After I executed regress syntax, I want to run the margins line. But I got this error - factor 'xxx' not found in list of covariates.
Tom
Tom
. sysuse auto, clear (1978 Automobile Data) . describe make price storage display value variable name type format label variable label ----------------------------------------------------------------- make str18 %-18s Make and Model price int %8.0gc Price
reg y x margins x
reg y i.x margins x
. use 20171114.dta . regress averagedailydoseduringtheinitial bsa gendercode agey af hypertension nonaaornonanona n > on11ornon1non1 chf ttestindication ttesttargetinr Source | SS df MS Number of obs = 175 -------------+---------------------------------- F(10, 164) = 10.05 Model | 43.1617679 10 4.31617679 Prob > F = 0.0000 Residual | 70.4175304 164 .429375185 R-squared = 0.3800 -------------+---------------------------------- Adj R-squared = 0.3422 Total | 113.579298 174 .652754588 Root MSE = .65527 --------------------------------------------------------------------------------- averagedailyd~l | Coef. Std. Err. t P>|t| [95% Conf. Interval] ----------------+---------------------------------------------------------------- bsa | 1.188892 .3362718 3.54 0.001 .5249113 1.852872 gendercode | .1272196 .1238465 1.03 0.306 -.1173195 .3717588 agey | -.0155522 .0047775 -3.26 0.001 -.0249855 -.006119 af | .127866 .1221302 1.05 0.297 -.1132843 .3690162 hypertension | .3461978 .1281871 2.70 0.008 .093088 .5993076 nonaaornonanona | .8642623 .1477174 5.85 0.000 .5725892 1.155935 non11ornon1non1 | -.4617247 .1669169 -2.77 0.006 -.7913078 -.1321415 chf | -.1948752 .1412051 -1.38 0.169 -.4736895 .0839391 ttestindication | -.269428 .170816 -1.58 0.117 -.60671 .067854 ttesttargetinr | -.0804833 .1887749 -0.43 0.670 -.4532259 .2922593 _cons | 1.517105 .6921503 2.19 0.030 .1504305 2.88378 --------------------------------------------------------------------------------- . margins gendercode factor 'gendercode' not found in list of covariates r(322);
. regress averagedailydoseduringtheinitial bsa i.gendercode agey i.af i.hypertension i.nonaaorno > nanona i.non11ornon1non1 i.chf i.ttestindication i.ttesttargetinr Source | SS df MS Number of obs = 175 -------------+---------------------------------- F(10, 164) = 10.05 Model | 43.1617679 10 4.31617679 Prob > F = 0.0000 Residual | 70.4175304 164 .429375185 R-squared = 0.3800 -------------+---------------------------------- Adj R-squared = 0.3422 Total | 113.579298 174 .652754588 Root MSE = .65527 ----------------------------------------------------------------------------------- averagedailydos~l | Coef. Std. Err. t P>|t| [95% Conf. Interval] ------------------+---------------------------------------------------------------- bsa | 1.188892 .3362718 3.54 0.001 .5249113 1.852872 1.gendercode | .1272196 .1238465 1.03 0.306 -.1173195 .3717588 agey | -.0155522 .0047775 -3.26 0.001 -.0249855 -.006119 1.af | .127866 .1221302 1.05 0.297 -.1132843 .3690162 1.hypertension | .3461978 .1281871 2.70 0.008 .093088 .5993076 1.nonaaornonanona | .8642623 .1477174 5.85 0.000 .5725892 1.155935 1.non11ornon1non1 | -.4617247 .1669169 -2.77 0.006 -.7913078 -.1321415 1.chf | -.1948752 .1412051 -1.38 0.169 -.4736895 .0839391 1.ttestindication | -.269428 .170816 -1.58 0.117 -.60671 .067854 1.ttesttargetinr | -.0804833 .1887749 -0.43 0.670 -.4532259 .2922593 _cons | 1.517105 .6921503 2.19 0.030 .1504305 2.88378 ----------------------------------------------------------------------------------- . margins i.gendercode i.af i.hypertension i.nonaaornonanona i.non11ornon1non1 i.chf i.ttestindi > cation i.ttesttargetinr Predictive margins Number of obs = 175 Model VCE : OLS Expression : Linear prediction, predict() --------------------------------------------------------------------------------- | Delta-method | Margin Std. Err. t P>|t| [95% Conf. Interval] ----------------+---------------------------------------------------------------- gendercode | 0 | 2.608814 .0852265 30.61 0.000 2.440531 2.777097 1 | 2.736034 .073641 37.15 0.000 2.590627 2.881441 | af | 0 | 2.639871 .0626649 42.13 0.000 2.516137 2.763605 1 | 2.767737 .0972987 28.45 0.000 2.575617 2.959856 | hypertension | 0 | 2.593013 .059096 43.88 0.000 2.476326 2.7097 1 | 2.939211 .1079877 27.22 0.000 2.725985 3.152436 | nonaaornonanona | 0 | 2.56153 .0535161 47.86 0.000 2.45586 2.667199 1 | 3.425792 .1367456 25.05 0.000 3.155783 3.695801 | non11ornon1non1 | 0 | 2.727549 .0524245 52.03 0.000 2.624035 2.831063 1 | 2.265824 .157728 14.37 0.000 1.954385 2.577264 | chf | 0 | 2.712351 .0547825 49.51 0.000 2.604181 2.820521 1 | 2.517476 .1277955 19.70 0.000 2.265139 2.769812 | ttestindication | 0 | 2.860189 .1244822 22.98 0.000 2.614395 3.105983 1 | 2.590761 .0752239 34.44 0.000 2.442229 2.739293 | ttesttargetinr | 0 | 2.695694 .0616338 43.74 0.000 2.573996 2.817392 1 | 2.615211 .1599611 16.35 0.000 2.299362 2.931059 ---------------------------------------------------------------------------------
Comment