use https://www.stata-press.com/data/r16/margex, clear(Artificial data for margins)
use https://www.stata-press.com/data/r16/margex, clear(Artificial data for margins)
dtable y i.sex i.groupRunning C:\Users\agrogan\Desktop\GitHub\Stata\indicator-variables\profile.do ..
> .
------------------------
Summary
------------------------
N 3,000
y 69.734 (21.540)
sex
male 1,498 (49.9%)
female 1,502 (50.1%)
group
1 1,199 (40.0%)
2 1,118 (37.3%)
3 683 (22.8%)
------------------------
regress y i.sex i.group
est store M1 // store estimatesRunning C:\Users\agrogan\Desktop\GitHub\Stata\indicator-variables\profile.do ..
> .
Source | SS df MS Number of obs = 3,000
-------------+---------------------------------- F(3, 2996) = 152.06
Model | 183866.077 3 61288.6923 Prob > F = 0.0000
Residual | 1207566.93 2,996 403.059723 R-squared = 0.1321
-------------+---------------------------------- Adj R-squared = 0.1313
Total | 1391433.01 2,999 463.965657 Root MSE = 20.076
------------------------------------------------------------------------------
y | Coefficient Std. err. t P>|t| [95% conf. interval]
-------------+----------------------------------------------------------------
sex |
female | 18.32202 .8930951 20.52 0.000 16.57088 20.07316
|
group |
2 | 8.037615 .913769 8.80 0.000 6.245937 9.829293
3 | 18.63922 1.159503 16.08 0.000 16.36572 20.91272
|
_cons | 53.32146 .9345465 57.06 0.000 51.48904 55.15388
------------------------------------------------------------------------------
regress y i.sex ibn.group, noconstant
est store M2 // store estimatesRunning C:\Users\agrogan\Desktop\GitHub\Stata\indicator-variables\profile.do ..
> .
Source | SS df MS Number of obs = 3,000
-------------+---------------------------------- F(4, 2996) = 9162.52
Model | 14772177 4 3693044.26 Prob > F = 0.0000
Residual | 1207566.93 2,996 403.059723 R-squared = 0.9244
-------------+---------------------------------- Adj R-squared = 0.9243
Total | 15979744 3,000 5326.58132 Root MSE = 20.076
------------------------------------------------------------------------------
y | Coefficient Std. err. t P>|t| [95% conf. interval]
-------------+----------------------------------------------------------------
sex |
female | 18.32202 .8930951 20.52 0.000 16.57088 20.07316
|
group |
1 | 53.32146 .9345465 57.06 0.000 51.48904 55.15388
2 | 61.35908 .7006367 87.58 0.000 59.9853 62.73285
3 | 71.96068 .7730326 93.09 0.000 70.44495 73.47641
------------------------------------------------------------------------------
est table M1 M2, starRunning C:\Users\agrogan\Desktop\GitHub\Stata\indicator-variables\profile.do ..
> .
----------------------------------------------
Variable | M1 M2
-------------+--------------------------------
sex |
female | 18.322021*** 18.322021***
|
group |
1 | (base) 53.321461***
2 | 8.0376149*** 61.359076***
3 | 18.639222*** 71.960683***
|
_cons | 53.321461***
----------------------------------------------
Legend: * p<0.05; ** p<0.01; *** p<0.001
marginsmargins
margins sex#groupRunning C:\Users\agrogan\Desktop\GitHub\Stata\indicator-variables\profile.do ..
> .
Adjusted predictions Number of obs = 3,000
Model VCE: OLS
Expression: Linear prediction, predict()
------------------------------------------------------------------------------
| Delta-method
| Margin std. err. t P>|t| [95% conf. interval]
-------------+----------------------------------------------------------------
sex#group |
male#1 | 53.32146 .9345465 57.06 0.000 51.48904 55.15388
male#2 | 61.35908 .7006367 87.58 0.000 59.9853 62.73285
male#3 | 71.96068 .7730326 93.09 0.000 70.44495 73.47641
female#1 | 71.64348 .6015065 119.11 0.000 70.46407 72.82289
female#2 | 79.6811 .8022261 99.32 0.000 78.10813 81.25407
female#3 | 90.2827 1.114023 81.04 0.000 88.09838 92.46703
------------------------------------------------------------------------------
noconstant Option Does Not Work With Two Indicator Variables
regress y ibn.sex ibn.group, noconstantRunning C:\Users\agrogan\Desktop\GitHub\Stata\indicator-variables\profile.do ..
> .
note: 3.group omitted because of collinearity.
Source | SS df MS Number of obs = 3,000
-------------+---------------------------------- F(4, 2996) = 9162.52
Model | 14772177 4 3693044.26 Prob > F = 0.0000
Residual | 1207566.93 2,996 403.059723 R-squared = 0.9244
-------------+---------------------------------- Adj R-squared = 0.9243
Total | 15979744 3,000 5326.58132 Root MSE = 20.076
------------------------------------------------------------------------------
y | Coefficient Std. err. t P>|t| [95% conf. interval]
-------------+----------------------------------------------------------------
sex |
male | 71.96068 .7730326 93.09 0.000 70.44495 73.47641
female | 90.2827 1.114023 81.04 0.000 88.09838 92.46703
|
group |
1 | -18.63922 1.159503 -16.08 0.000 -20.91272 -16.36572
2 | -10.60161 1.01299 -10.47 0.000 -12.58783 -8.615381
3 | 0 (omitted)
------------------------------------------------------------------------------
margins
margins sex#groupRunning C:\Users\agrogan\Desktop\GitHub\Stata\indicator-variables\profile.do ..
> .
Adjusted predictions Number of obs = 3,000
Model VCE: OLS
Expression: Linear prediction, predict()
------------------------------------------------------------------------------
| Delta-method
| Margin std. err. t P>|t| [95% conf. interval]
-------------+----------------------------------------------------------------
sex#group |
male#1 | 53.32146 .9345465 57.06 0.000 51.48904 55.15388
male#2 | 61.35908 .7006367 87.58 0.000 59.9853 62.73285
male#3 | 71.96068 .7730326 93.09 0.000 70.44495 73.47641
female#1 | 71.64348 .6015065 119.11 0.000 70.46407 72.82289
female#2 | 79.6811 .8022261 99.32 0.000 78.10813 81.25407
female#3 | 90.2827 1.114023 81.04 0.000 88.09838 92.46703
------------------------------------------------------------------------------