How to run a regression which report all factor variables?

寵の児 提交于 2020-01-06 06:55:53

问题


I want to run a regression that calculates the estimated values for all levels of a factor variable. By default, Stata omits one dummy as a base level.

When I use the allbaselevels option, it just shows a zero value for a base level:

regress adjusted_volume i.rounded_time, allbaselevels

SAS shows all the estimated values of categorical variables when the constant has been removed.

How can i do the same thing in Stata?


回答1:


The option allbaselevels is one of several display options, which can be useful when reporting results from estimation commands such as regress. But specifying it as an option does not make any difference in the calculations.

As the Stata manual points out:

"...The allbaselevels option is much like baselevels, except allbaselevels lists base levels in interactions as well as in main effects. Specifying allbaselevels will make the output easier to understand..."

What you are actually looking for is the ibn. factor-variable operator:

. sysuse auto, clear
(1978 Automobile Data)

. regress mpg ibn.rep78
note: 5.rep78 omitted because of collinearity

  Source |       SS           df       MS          Number of obs   =        69
-------------+----------------------------------   F(4, 64)        =      4.91
   Model |  549.415777         4  137.353944       Prob > F        =    0.0016
Residual |  1790.78712        64  27.9810488       R-squared       =    0.2348
-------------+----------------------------------   Adj R-squared   =    0.1869
   Total |   2340.2029        68  34.4147485       Root MSE        =    5.2897

------------------------------------------------------------------------------
     mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
   rep78 |
      1  |  -6.363636   4.066234    -1.56   0.123    -14.48687    1.759599
      2  |  -8.238636   2.457918    -3.35   0.001    -13.14889    -3.32838
      3  |  -7.930303    1.86452    -4.25   0.000    -11.65511   -4.205497
      4  |   -5.69697    2.02441    -2.81   0.006    -9.741193   -1.652747
      5  |          0  (omitted)
         |
   _cons |   27.36364   1.594908    17.16   0.000     24.17744    30.54983
------------------------------------------------------------------------------

Of course, you also need to specify the noconstant option:

. regress mpg ibn.rep78, noconstant

  Source |       SS           df       MS          Number of obs   =        69
-------------+----------------------------------   F(5, 64)        =    227.47
   Model |  31824.2129         5  6364.84258       Prob > F        =    0.0000
Residual |  1790.78712        64  27.9810488       R-squared       =    0.9467
-------------+----------------------------------   Adj R-squared   =    0.9426
   Total |       33615        69  487.173913       Root MSE        =    5.2897

------------------------------------------------------------------------------
     mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
   rep78 |
      1  |         21   3.740391     5.61   0.000     13.52771    28.47229
      2  |     19.125   1.870195    10.23   0.000     15.38886    22.86114
      3  |   19.43333   .9657648    20.12   0.000       17.504    21.36267
      4  |   21.66667   1.246797    17.38   0.000      19.1759    24.15743
      5  |   27.36364   1.594908    17.16   0.000     24.17744    30.54983
------------------------------------------------------------------------------


来源:https://stackoverflow.com/questions/50044814/how-to-run-a-regression-which-report-all-factor-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!