In Stata 11, the margins command can be used to calculate least square means.
Title | Use of adjust | |
Author | Weihua Guan, StataCorp |
Currently there is no convenient command in Stata to calculate the least square means, but one may use the adjust command to compute them manually. LSMEANS are just the predicted linear combination xb while holding the other covariates at values 1/n, where n is the number of categories in the corresponding discrete covariates. For continuous covariates, one just holds their values at their means when making the prediction.
Following is an example using the auto dataset:
. sysuse auto, clear (1978 Automobile Data) . anova mpg foreign rep78 Number of obs = 69 R-squared = 0.2825 Root MSE = 5.16246 Adj R-squared = 0.2256 Source | Partial SS df MS F Prob > F -----------+---------------------------------------------------- Model | 661.189524 5 132.237905 4.96 0.0007 | foreign | 111.773747 1 111.773747 4.19 0.0447 rep78 | 179.189006 4 44.7972516 1.68 0.1655 | Residual | 1679.01337 63 26.6510059 -----------+---------------------------------------------------- Total | 2340.2029 68 34.4147485 . xi: regress mpg i.foreign i.rep78 i.foreign _Iforeign_0-1 (naturally coded; _Iforeign_0 omitted) i.rep78 _Irep78_1-5 (naturally coded; _Irep78_1 omitted) Source | SS df MS Number of obs = 69 -------------+------------------------------ F( 5, 63) = 4.96 Model | 661.189524 5 132.237905 Prob > F = 0.0007 Residual | 1679.01337 63 26.6510059 R-squared = 0.2825 -------------+------------------------------ Adj R-squared = 0.2256 Total | 2340.2029 68 34.4147485 Root MSE = 5.1625 ------------------------------------------------------------------------------ mpg | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Iforeign_1 | 3.556584 1.736681 2.05 0.045 .0861047 7.027064 _Irep78_2 | -1.875 4.081284 -0.46 0.648 -10.0308 6.280795 _Irep78_3 | -1.922325 3.774126 -0.51 0.612 -9.464315 5.619665 _Irep78_4 | -1.111626 3.944633 -0.28 0.779 -8.994345 6.771094 _Irep78_5 | 3.453704 4.215132 0.82 0.416 -4.969565 11.87697 _cons | 21 3.650411 5.75 0.000 13.70524 28.29476 ------------------------------------------------------------------------------ . adjust _Irep78_2=.2 _Irep78_3=.2 _Irep78_4=.2 _Irep78_5=.2, by(foreign) se ------------------------------------------------------------------------------- Dependent variable: mpg Command: regress Variable left as is: _Iforeign_1 Covariates set to value: _Irep78_2 = .2, _Irep78_3 = .2, _Irep78_4 = .2, _Irep78_5 = .2 ------------------------------------------------------------------------------- ---------------------------------- Car type | xb stdp ----------+---------------------- Domestic | 20.709 (1.04909) Foreign | 24.2655 (1.55104) ---------------------------------- Key: xb = Linear Prediction stdp = Standard Error
There are five outcomes in the variable rep78. The values of the dummy variables _Irep* are held as 1/5 = 0.2.
Given that adjust is just another form of predict, we could also use predict to reproduce the results.