jeffgortmaker / pyblp

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

Question about Operator I(-prices) I(low / income) and parallel processing #166

Closed QWangPKU closed 6 days ago

QWangPKU commented 1 week ago

Hi Jeff,

Thanks for this amazing package!

  1. Could you explain what the operator "I()" mean. Specifically, in the case using micro moments with automobile data, what does "I(-prices)" represents, is it referring to the term "-alpha price" or "alphalog(y-p)" in the utility function? Also I still had a hard time understanding what "I(low / income)" and "I(log(fs) * fv)" stand for even after reading Petrin's paper.

  2. If I want to apply parallel processing to estimation (not post-estimation calculation), is the syntax the same as in the case of calculating elasticity like below?

    
    pyblp.options.verbose = True

problem = pyblp.Problem(formulation, product_data)

with pyblp.parallel(2):

results = problem.solve()


Thank you for your help in advance!
chrisconlon commented 6 days ago
  1. PyBLP uses (modified) Patsy formulas. You can read about how formulas work here: https://patsy.readthedocs.io/en/latest/formulas.html#:~:text=To%20make%20this%20more%20convenient,sum%20of%20x1%20and%20x2%20.

These work much like regression formulas in R

The short answer is that it constructs a new variable for the nonlinear part of the model by evaluating the I( ) function. As an example " I ( x1 * x2 ) " would construct an interaction term between x1 and x2.

" I (- prices ) " constructs a new variable (negative prices) that is used to evaluate the micro moments.

  1. I believe this will work in parallel (subject to the usual caveats re: Python). The main step that can be parallelized for estimation is inverting for the mean utilities market by market. Because NumPy matrix computations can already use multiple cores, too much parallelization may slow things down. You will need to experiment on your own problem/hardware.
QWangPKU commented 6 days ago

Thank you for the explanation! This is super helpful.