Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
William Buchanan <william@williambuchanan.net> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: How to store marginal effect value after using margin command? |

Date |
Sat, 8 Jun 2013 17:20:52 -0700 |

If you're using the - margins - command, the - post - option is clearly documented in the help file. Additionally, the Statalist FAQ suggests looking through the documentation as a good first step prior to querying the list. If this isn't the answer that you were looking for it may be a good idea to be more explicit about your end goal. HTH, Billy Sent from my iPhone On Jun 8, 2013, at 16:54, Vũ Võ <hoangvu@ueh.edu.vn> wrote: > Dear Sergiy, > > Thank you for your message. Probably, you misunderstand my question > nor I am clear in raising a question. > > For example: > > sysuse auto, clear > > reg price price wgt mpg c.wgt#c.wgt c.mpg#c.mpg c.wgt#c.mpg > > > Source | SS df MS Number of obs = 74 > -------------+------------------------------ F( 5, 68) = 12.84 > Model | 308384833 5 61676966.6 Prob > F = 0.0000 > Residual | 326680563 68 4804125.93 R-squared = 0.4856 > -------------+------------------------------ Adj R-squared = 0.4478 > Total | 635065396 73 8699525.97 Root MSE = 2191.8 > > ------------------------------------------------------------------------------ > price | Coef. Std. Err. t P>|t| [95% Conf. Interval] > -------------+---------------------------------------------------------------- > weight | -31.88985 9.148215 -3.49 0.001 -50.14483 -13.63487 > mpg | -3549.495 1126.464 -3.15 0.002 -5797.318 -1301.672 > | > c.weight#| > c.weight | .0034574 .0008629 4.01 0.000 .0017355 .0051792 > | > c.mpg#c.mpg | 38.74472 12.62339 3.07 0.003 13.55514 63.93431 > | > c.weight#| > c.mpg | .5421927 .1971854 2.75 0.008 .1487154 .9356701 > | > _cons | 92690.55 25520.53 3.63 0.001 41765.12 143616 > ------------------------------------------------------------------------------ > > So, I would like to calculate the marginal effects of weight and mpg > on price by using command: > margins, dydx(weight mpg) > > and get -> > > Average marginal effects Number of obs = 74 > Model VCE : OLS > > Expression : Linear prediction, predict() > dy/dx w.r.t. : weight mpg > > ------------------------------------------------------------------------------ > | Delta-method > | dy/dx Std. Err. z P>|z| [95% Conf. Interval] > -------------+---------------------------------------------------------------- > weight | .5360966 .6516553 0.82 0.411 -.7411243 1.813318 > mpg | -262.0502 103.681 -2.53 0.011 -465.2612 -58.83919 > ------------------------------------------------------------------------------ > > > My question is how to obtain or store in to scalar or whatever in > stata values of 0.5360966 and -262.0502 in the above table? > > If i use mfx , after that using matrix list e(b) as you suggested, it > will give me coefficients of the regression. To some extent, it can > say that these are marginal effets, but not what I would like to > obtain. > > Any suggestion are highly appreciated. Thanks > > Vu > > On 9 June 2013 00:07, Sergiy Radyakin <serjradyakin@gmail.com> wrote: >> type either 'return list' or 'ereturn list' (depending on the command) >> to see which results are saved after these commands. From what you >> describe you are interested in matrices r(b) and e(b) >> >> sysuse auto, clear >> generate lp=log(price) >> regress lp weight length headroom mpg >> mfx >> matrix list e(b) >> >> Best, Sergiy >> >> On Sat, Jun 8, 2013 at 4:50 PM, Vũ Võ <hoangvu@ueh.edu.vn> wrote: >>> Hi everyone, >>> >>> I am writing a code in do file to calculate the marginal effect of x >>> on y (log-linear model) >>> >>> The function form as following: >>> >>> Ln(Y) = a0 + a1*X + a2*X^2 + e ----> Y = exp(a0 + a1*X + a2*X^2) >>> >>> So, dY/dX = (a1 + 2*a2*X)*exp(a0 + a1*X + a2*X^2) eq(1) >>> >>> If I run the regression by command line as: >>> >>> reg lnY x c.x#c.x >>> >>> after that using margins command: >>> >>> margins, dydx(x). >>> >>> I will obtain the marginal effect of x on Ln(Y): (a1 + 2*a2*X). >>> >>> How can I calculate the dY/dX as in eq(1) by using the do file, not >>> calculating manually? >>> >>> >>> 2. Second question is: >>> >>> If I use command margins, predict(p) and obtain the results as following: >>> >>> Marginal effects after hetprob >>> y = Pr(y) (predict, p) >>> = .54284206 >>> ------------------------------------------------------------------------------ >>> variable | dy/dx Std. Err. z p>|z| [ 95% C.I. ] X >>> ---------+-------------------------------------------------------------------- >>> x | .3704576 .03237 11.44 0.000 .307015 .4339 .020114 >>> xhet | -.0736092 .02423 -3.04 0.002 -.121095 -.026124 .502716 >>> off1 | (offset1) 1.00516 >>> off2 | (offset2) 1.09709 >>> ------------------------------------------------------------------------------ >>> >>> The question is how to store the marginal effects value, say in this >>> case is 0.3704576, >>> >>> in the scalar in stata? >>> >>> >>> Thank you so much. >>> >>> Vo Duc Hoang Vu >>> * >>> * For searches and help try: >>> * http://www.stata.com/help.cgi?search >>> * http://www.stata.com/support/faqs/resources/statalist-faq/ >>> * http://www.ats.ucla.edu/stat/stata/ >> >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/faqs/resources/statalist-faq/ >> * http://www.ats.ucla.edu/stat/stata/ > > > > -- > > Vo Duc Hoang Vu > Faculty of Development Economics > University of Economics HCMC > 1 A Hoang Dieu Street > Phu Nhuan Dist. Ho Chi Minh > Vietnam > Tel: +84 94 550 22 77 (VN); +31 624 63 29 45 (NL) > Fax: +84 8 38477948 (VN) > E-mail:hoangvu@ueh.edu.vn > http://www.voduchoangvu.net > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/statalist-faq/ > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: How to store marginal effect value after using margin command?***From:*Steve Samuels <sjsamuels@gmail.com>

**Re: st: How to store marginal effect value after using margin command?***From:*Steve Samuels <sjsamuels@gmail.com>

**References**:**st: How to store marginal effect value after using margin command?***From:*Vũ Võ <hoangvu@ueh.edu.vn>

**Re: st: How to store marginal effect value after using margin command?***From:*Sergiy Radyakin <serjradyakin@gmail.com>

**Re: st: How to store marginal effect value after using margin command?***From:*Vũ Võ <hoangvu@ueh.edu.vn>

- Prev by Date:
**Re: st: How to store marginal effect value after using margin command?** - Next by Date:
**Re: st: reading HTML source in Chinese but get a messy code** - Previous by thread:
**Re: st: How to store marginal effect value after using margin command?** - Next by thread:
**Re: st: How to store marginal effect value after using margin command?** - Index(es):