jeffgortmaker / pyblp

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

Demand Jacobian, markup term and first order conditions #142

Closed luke120395 closed 1 year ago

luke120395 commented 1 year ago

First of all, thanks a lot for this amazing package!

I might have come across an error in the computation of the markup term \eta. Specifically, I think that not the demand Jacobian \frac{\partial s}{\partial p}, but rather its transpose (where each (j,k) entry is given by \frac{\partial s_k}{\partial p_j}) should be used to construct the \Delta matrix in order to correctly reflect the firms' first order conditions.

As long as prices enter the indirect utility function linearly, this should not be a problem, since the demand Jacobian is symmetric in that case. If prices enter in logs, however, this is not true anymore.

Thanks for having a look!

jeffgortmaker commented 1 year ago

Thanks for finding this! I verified the issue with a unit test in which prices enter nonlinearly, and just pushed a fix.

I'm hoping this took a while for someone to find because nonlinear prices with a supply side is an uncommon setup. My sense is this can make solving for equilibrium prices tricky (e.g. negative prices in logs).

I updated a couple places in the dev documentation where there should be a transpose, but please let me know if there are any other places you noticed that need a fix too.

luke120395 commented 1 year ago

Hi Jeff,

thanks for the quick response and fix! Looks good to me now.