Is it possible to save margins estimates as a new variable? In the example below, I would like to create a variable that contains the marginal effects of ycn across the whole range of age in order to then use this variable in a two-way graph (that way I will be able to combine several "margins plots" in one graph). You can of course create this variable manually, but that is so tiresome...
I found a similar post (https://www.statalist.org/forums/for...=1566557316931) but I do not manage to get the code provided in that post to work in my case.
Code:
. . use http://www.stata-press.com/data/r13/margex, clear
(Artificial data for margins)
. . reg outcome c.ycn c.age c.age#c.ycn
Source | SS df MS Number of obs = 3000
-------------+------------------------------ F( 3, 2996) = 182.34
Model | 65.2517193 3 21.7505731 Prob > F = 0.0000
Residual | 357.387947 2996 .119288367 R-squared = 0.1544
-------------+------------------------------ Adj R-squared = 0.1535
Total | 422.639667 2999 .140926865 Root MSE = .34538
------------------------------------------------------------------------------
outcome | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
ycn | -.0018226 .0010404 -1.75 0.080 -.0038625 .0002173
age | .008331 .0019362 4.30 0.000 .0045346 .0121275
|
c.age#c.ycn | .0000576 .0000252 2.29 0.022 8.18e-06 .0001071
|
_cons | -.1989264 .0783917 -2.54 0.011 -.3526334 -.0452194
------------------------------------------------------------------------------
. margins, dydx (ycn) at (age=(20(1)60))
Kind regards,
David
0 Response to Saving margins estimates as a new variable
Post a Comment