7391 4

# [其他] 在Stata中估计Fixed and Random Effects [推广有奖]

• 0关注
• 1粉丝

14%

-

0

85410 个

29.1307

2 点

4 点

1 点

9949 点

239

0

531 小时

2004-10-23

2022-12-22

luyunhang 发表于 2005-4-19 23:21:00 |显示全部楼层
+2 论坛币
k人 参与回答

### 感谢您参与论坛问题回答

+2 论坛币

Fixed and Random Effects

IX. Fixed Effects.

A. Unmodeled Heterogeneity.  We hope that our independent variables have explained much of what is different about an observation, a unit, or a year, but there is probably some unmodeled heterogeneity.  Since we haven’t modeled it, it goes into ei,t.  The real problem comes when some units (or, less commonly, time periods) share some unmodeled heterogeneity.  We’d love to be able to explain everything that makes Luxembourg different, but usually we can’t, so we need to violate the prohibition on using proper names as independent variables and do something to remove this shared and thus systematic heterogeneity from the error term.

B. The Fixed Effects Model in Concept.  One way to do this is to estimate a “fixed effects” model that gives Luxembourg and every other unit in our study its own intercept.  The most intuitive way to do this would be by including a dummy variable for N-1 units.  We still assume that the betas pool across units, so in essence we have N parallel regression lines.  Observations across time in each unit vary around a baseline level specific that unit.  Note that any substantive explanatory variables that do not vary across time in each unit will be perfectly collinear with the fixed effects, and so we cannot include them in the model (or estimate their effects).

yi,t = αi  + xi,tβ + ei,t

C. Sketch of a Test for Fixed Effects.  The null hypothesis is that our simple, restrictive model was appropriate, that all of the units share the same intercept.  The alternative is that they vary across units, so the way to test this is by running both models and then comparing their sum of squares in a joint F-test.

D. Estimating the Fixed Effects Model.  We could just include dummy variables for all but one of the units.  If we have panel data, though, this sacrifices a lot of degrees of freedom.  And with so many units and very few time periods, these intercepts may be picking up on a lot of random error and thus be quite inconsistent.  We’re not going to learn much of substance from these “incidental” or “nuisance” parameters.  So this frees us to estimate the effect of our substantive coefficients in a slightly different way that preserves the substantive story of fixed effects without costing us so many degrees of freedom.  We convert our xs and y for each observation into a deviation from the mean in that unit.  This “sweeps out the unit effects” because when you mean deviate variables, you no longer need to include an intercept term.  So the model regresses yi,t – mean(yi) on xi,t – mean(xi).  This is often called this “within” estimator because it looks at how changes in the explanatory variables cause y to vary around a mean within the unit.  Stata has a canned procedure that (I believe) transforms your variables in this way and then corrects the standard errors to reflect the fact that N of your observations bring no new information (since they are determined by the mean and the other observations for each unit).

xtreg DiscretionarySpending salary totalday staffper init ideo leg_dd gov_dem docs_g senc_g medi_g noreast, fe

Fixed-effects (within) regression               Number of obs      =       616

Group variable (i): alpha                       Number of groups   =        44

R-sq:  within  = 0.0126                         Obs per group: min =        14

between = 0.0232                                        avg =      14.0

overall = 0.0053                                        max =        14

F(3,569)           =      2.42

corr(u_i, Xb)  = -0.3025                        Prob > F           =    0.0648

------------------------------------------------------------------------------

Discretion~g |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]

-------------+----------------------------------------------------------------

salary |  -2.94e-06   5.26e+07    -0.00   1.000    -1.03e+08    1.03e+08

totalday |  (dropped)

staffper |  (dropped)

init |  (dropped)

ideol |  (dropped)

leg_dd |  -.1616329   .0701156    -2.31   0.022      -.29935   -.0239159

gov_dem |  -.0682768   .0426327    -1.60   0.110    -.1520135    .0154599

docs_g |  (dropped)

senc_g |  (dropped)

medi_g |  (dropped)

noreast |  (dropped)

_cons |   4.374255   1.33e+12     0.00   1.000    -2.62e+12    2.62e+12

-------------+----------------------------------------------------------------

sigma_u |  .51059043

sigma_e |  .42354445

rho |  .59238137   (fraction of variance due to u_i)

------------------------------------------------------------------------------

F test that all u_i=0:     F(43, 569) =     7.86             Prob > F = 0.0000

X. Random Effects

A. The Random Effects Model in Concept.  Instead of thinking of each unit as having its own systematic baseline, we think of each intercept as the result of a random deviation from some mean intercept.  The intercept is a draw from some distribution for each unit, and it is independent of the error for a particular observation.  Instead of trying to estimate N parameters as in fixed effects, we just need to estimate parameters describing the distribution from which each unit’s intercept is drawn.  If we have a large N (panel data), we will be able to do this, and random effects will be more efficient than fixed effects.  It has N more degrees of freedom, and it also uses information from the “between” estimator (which averages observations over a unit and regresses average y on average x to look at differences across units).  Another nice property is that you can still have explanatory variables that don’t change over time for a unit.  If we have a big T (TS-CS data), then the difference between fixed effects and random effects goes away.

yi,t = μ + αi  + xi,tβ + ei,t

B. Sketch of a Test for Random Effects.  A small assumption is that Cov(αi , ei) = 0.  A huge assumption is that Cov(αi , xi) = 0, which means that the things that make a unit’s intercept different are unrelated to the country’s xs.  In concept, a test regresses the errors on the xs.

C. Estimating the Random Effects Model.

xtreg DiscretionarySpending salary totalday staffper init ideo leg_dd gov_dem docs_g senc_g medi_g noreast, re

Random-effects GLS regression                   Number of obs      =       616

Group variable (i): alpha                       Number of groups   =        44

R-sq:  within  = 0.0125                         Obs per group: min =        14

between = 0.5560                                        avg =      14.0

overall = 0.3272                                        max =        14

Random effects u_i ~ Gaussian                   Wald chi2(11)      =     53.09

corr(u_i, X)       = 0 (assumed)                Prob > chi2        =    0.0000

------------------------------------------------------------------------------

Discretion~g |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]

-------------+----------------------------------------------------------------

salary |   8.34e-06   5.39e-06     1.55   0.122    -2.23e-06    .0000189

totalday |   .0000968   .0008137     0.12   0.905    -.0014979    .0016916

staffper |  -.0223183   .0209193    -1.07   0.286    -.0633193    .0186828

init |  -.2080793   .1182186    -1.76   0.078    -.4397836    .0236249

ideol |   .6509317   .8078395     0.81   0.420    -.9324047    2.234268

leg_dd |  -.1153163    .064981    -1.77   0.076    -.2426768    .0120442

gov_dem |  -.0570731    .042057    -1.36   0.175    -.1395033    .0253572

docs_g |   .0700836   .0764945     0.92   0.360    -.0798429    .2200101

senc_g |    .056224   .1389907     0.40   0.686    -.2161928    .3286409

medi_g |   .1813995   .0828276     2.19   0.029     .0190605    .3437385

noreast |   .4777465    .126015     3.79   0.000     .2307616    .7247314

_cons |    3.74571   .2060277    18.18   0.000     3.341903    4.149517

-------------+----------------------------------------------------------------

sigma_u |  .32985269

sigma_e |  .42354445

rho |  .37753489   (fraction of variance due to u_i)

------------------------------------------------------------------------------

### 扫码加我 拉你入群

brwei2007 发表于 2009-8-2 12:41:02 |显示全部楼层
 在stata中help xtreg即可看到帮助的信息和有关例子
tmdxyz 发表于 2009-8-5 06:16:01 |显示全部楼层
 谢谢楼主。
olDBear0769 发表于 2009-8-7 20:52:09 |显示全部楼层
 不如我自己看帮助文档
wocaishiliuking   发表于 2010-12-2 17:56:01 |显示全部楼层
 支持一下。很不错
 您需要登录后才可以回帖 登录 | 我要注册 回帖后跳转到最后一页