jeffgortmaker / pyblp

BLP Demand Estimation with Python
https://pyblp.readthedocs.io
MIT License
228 stars 82 forks source link

Computing counterfactual shares #147

Closed ny1526 closed 10 months ago

ny1526 commented 10 months ago

Hello,

I am trying to compute counterfactual market shares by inputting new prices into a model saved in results. However, when I run results.compute_shares(prices = newprices), I get the following error:

AttributeError: 'ProblemResults' object has no attribute '_sigma'. Did you mean: 'sigma'?

This is a new issue for me -- I previously ran this code several months ago and did not receive this error. (I generated the model in results several months ago and stored/re-loaded it now.) Do you know what could be causing this?

Thank you for your help!

jeffgortmaker commented 10 months ago

Probably because you updated the package and something changed under the hood! This is a common issue with pickling to store data in Python -- it often isn't compatible across versions. You have two options I can think of:

  1. Re-create the results with the newer version of pyblp.
  2. Uninstall pyblp, re-install the version you used to create those results (probably whatever was current back then), load the data under that older version, save something that's more robust to version changes (like the results of ProblemResults.to_dict()), update pyblp, and load those results. With these, you won't be able to call ProblemResults.compute_shares directly -- you'll have to create a new Problem, "solve" it with something like Problem.solve(sigma=results['sigma'], ..., delta=results['delta'], ..., optimization=pyblp.Optimization('return'), iteration=pyblp.Iteration('return'), ...), to get your results.

Hope that helps.

ny1526 commented 10 months ago

Ah, that makes sense. I'll try that -- thank you for the detailed explanation.