I'm running a count regression with x1 and x1^2 terms using the "poisson" command (I expect a nonlinear effect of x1), and want to compute marginal effects.
The "mfx" and "margeff" commands appear to not be well-suited for computing the marginal effects of such product or power terms (see http://www.unc.edu/%7Eenorton/NortonWangAi.pdf).
Ideally, I'd like to be able to graph the marginal effects and their statistical significance (perhaps in a similar manner as in the above paper).
Ironically, if graph the "mfx" marginal effects on y, I get the concave shape that I expect, but if I replace these with marginal effects calculated by my own derivitives I don't get similar results. I was wondering if I've made a mistake in the code below or if I'm way off base in my approach/understanding of the issues at hand. Also, I haven't even gotten around to attempting to calculate the significance of the marginal effects, so help with that would be great.
Thanks,
Jason Franken
CODE FOLLOWS:
*1st, I run the count regression y = e^(X'B), where X'B = b0 + b1x1 + b2(x1)^2 + b3x3 ... .
poisson y x1 x1squared x3 x4 x5 x6 x7
*Then "mfx" gives marginal effects at mean values of other explanatory variables.
mfx
*And "margeff" computes the average of the marginal effects for each observation in the sample.
margeff, dummies(x6) replace
*But the marginal effects for x1 and x1squared are incorrect (see http://www.unc.edu/%7Eenorton/NortonWangAi.pdf).
*The problem is that derivatives w.r.t x1 (dy/dx1 and d2y/dx1dx1) are incorrect.
*For other variables, like x3, we can show that STATA results are correct.
poisson y x1 x1squared x3 x4 x5 x6 x7
*REPRODUCE THE "mfx" RESULT
egen x1bar = mean(x1)
egen x1squaredbar = mean(x1squared)
egen x3bar = mean(x3)
egen x4bar = mean(x4)
egen x5bar = mean(x5)
egen x6bar = mean(x6)
egen x7bar = mean(x7)
gen eBXbar = exp(_b[_cons] + _b[x1]*x1bar + _b[x1squared]*x1squaredbar + _b[x3]*x3bar + _b[x4]*x4bar + _b[x5]*x5bar + _b[x6]*x6bar + _b[x7]*x7bar)
gen mf_x3MEAN = _b[x3]*eBXbar
list mf_x3MEAN
*REPRODUCE THE "margeff" RESULT
gen eBX = exp(_b[_cons] + _b[x1]*x1 + _b[x1squared]*x1squared + _b[x3]*x3 + _b[x4]*x4 + _b[x5]*x5 + _b[x6]*x6 + _b[x7]*x7)
gen mf_x3 = _b[x3]*eBX
sum mf_x3
*Now, I want to compute true marginal effects for x1 (and x1squared), so that I can graph its nonlinear effect.
*FOLLOWING SHOULD GIVE TRUE MARGINAL EFFECT FOR "x1" ...
*for the average of marginal effects for all observations (like "margeff"):
gen mf_x1 = (_b[x1]+(2*_b[x1squared]*x1))*eBX
sum mf_x1
*for the marginal effect at mean values of other explanatory variables (like "mfx"):
gen mf_rpMEAN = (_b[x1]+(2*_b[x1squared]*x1bar))*eBXbar
list mf_rpMEAN
*FOLLOWING SHOULD GIVE TRUE MARGINAL EFFECT FOR "x1squared".
*for the average of marginal effects for all observations (like "margeff"):
gen mf_x1squared = (2*_b[x1squared]*eBX) + (((_b[x1]+(2*_b[x1squared]*x1))^2)*eBX)
sum mf_x1squared
*for the marginal effect at mean values of other explanatory variables (like "mfx"):
gen mf_x1squaredMEAN = (2*_b[x1squared]*eBXbar) + (((_b[x1]+(2*_b[x1squared]*x1bar))^2)*eBXbar)
list mf_x1squaredMEAN
*Here's the graph computed using "mfx" marginal effects (Am I "out of line" treating the marginal effects like coefficients to predict a value of y at the mean?).
poisson y x1 x1squared x3 x4 x5 x6 x7
mfx
gen yMEAN = _b[_cons] + (1.297568*rpfactoramos1) + (-.1066019*rp2) + (.083736*x3bar) + (.0003309*x4bar) + (-.0615128*x5bar) + (-.0954496*x6bar) + (.2182201*x7bar)
graph twoway (scatter ymean x1, ms(O)) (line yMEAN x1, sort)
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/