I am trying to work with counterfactuals using margins and I'm having a hard time including gen into the margins command. As an example I'll use the union data to show what I mean.
Code:
. sysuse nlsw88, clear
(NLSW, 1988 extract)
.
. keep if !missing(wage, age, race, married, tenure)
(15 observations deleted)
. summ wage ttl_exp tenure
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
wage | 2,231 7.792448 5.764505 1.004952 40.74659
ttl_exp | 2,231 12.55485 4.606011 .1153846 28.88461
tenure | 2,231 5.97785 5.510331 0 25.91667
.
. reg wage age i.race i.married
Source | SS df MS Number of obs = 2,231
-------------+---------------------------------- F(4, 2226) = 8.38
Model | 1099.58655 4 274.896637 Prob > F = 0.0000
Residual | 73002.2411 2,226 32.7952566 R-squared = 0.0148
-------------+---------------------------------- Adj R-squared = 0.0131
Total | 74101.8276 2,230 33.2295191 Root MSE = 5.7267
------------------------------------------------------------------------------
wage | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
age | -.0846017 .0397183 -2.13 0.033 -.1624905 -.0067128
|
race |
black | -1.450203 .2843798 -5.10 0.000 -2.007881 -.8925259
other | .4406781 1.132043 0.39 0.697 -1.779292 2.660649
|
married |
married | -.7871973 .2588382 -3.04 0.002 -1.294787 -.2796078
_cons | 11.98058 1.582136 7.57 0.000 8.877966 15.0832
------------------------------------------------------------------------------I have a simple model here predicting wages with a few basic controls, most importantly age. That's my measure of interest for now.
I want to see some predictions for age so I turn to margins with the at() option.
Code:
. margins, at(age=(15(5)65)) vsquish
Predictive margins Number of obs = 2,231
Model VCE : OLS
Expression : Linear prediction, predict()
1._at : age = 15
2._at : age = 20
3._at : age = 25
4._at : age = 30
5._at : age = 35
6._at : age = 40
7._at : age = 45
8._at : age = 50
9._at : age = 55
10._at : age = 60
11._at : age = 65
------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_at |
1 | 9.835705 .9668889 10.17 0.000 7.939607 11.7318
2 | 9.412697 .7702675 12.22 0.000 7.902179 10.92321
3 | 8.989688 .5750017 15.63 0.000 7.862093 10.11728
4 | 8.56668 .3831699 22.36 0.000 7.815272 9.318088
5 | 8.143672 .2046674 39.79 0.000 7.742313 8.545031
6 | 7.720663 .1258394 61.35 0.000 7.473888 7.967438
7 | 7.297655 .2620298 27.85 0.000 6.783806 7.811503
8 | 6.874647 .447617 15.36 0.000 5.996856 7.752437
9 | 6.451638 .6410457 10.06 0.000 5.194528 7.708748
10 | 6.02863 .8368964 7.20 0.000 4.387451 7.669809
11 | 5.605621 1.033793 5.42 0.000 3.578321 7.632922
------------------------------------------------------------------------------
.Here's where I want to expand things. I know that I can include a counterfactual using values that are not in the original model. So for example, I can compare the predictions for age, against another prediction for age where the values of tenure are minused out (I know this is not logical, it's just an example). It looks like this.
Code:
. margins, at(age = gen(age)) ///
> at(age = gen(age-tenure)) vsquish
Predictive margins Number of obs = 2,231
Model VCE : OLS
Expression : Linear prediction, predict()
1._at : age = age
2._at : age = age-tenure
------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_at |
1 | 7.792448 .1212427 64.27 0.000 7.554687 8.030208
2 | 8.298184 .266595 31.13 0.000 7.775383 8.820985
------------------------------------------------------------------------------
.I have tried code like the example below and have had no luck.
Code:
margins, at(age = gen(age)) /// at(age=(15(5)65) = gen(age-tenure))
Any help would be appreciated.
0 Response to Bringing gen() into Margins, at()
Post a Comment