9  Correlated Random Effect

Published

April 15, 2025

9.1 Panel data

The standard panel-data setup is:

\[y_{it} = \alpha + X_{it} \beta + v_i + \epsilon_{it} \tag{9.1}\]

9.2 Fixed effect

The fixed-effect estimator runs OLS on demeaned data:

\[ (y_{it} - \bar y_i) = (X_{it} - \bar X_i) \beta + (\epsilon_{it} - \bar \epsilon_i) \tag{9.2}\] Both \(\alpha\) and \(v_i\) drop out after demeaning by unit.

9.3 Random effect

Random effects treat \(v_i + \epsilon_{it}\) as a composite error with two variance components: \(\hat \sigma^2_e\) (idiosyncratic) and \(\hat \sigma^2_u\) (individual). The GLS transformation is

\(z^*_{it} = z_{it} - \hat \theta_i \bar z_i\)

with \(\hat \theta_i = 1 - \sqrt{\hat \sigma^2_e / (T_i \hat \sigma^2_u + \hat \sigma^2_e)}\), where \(T_i\) is the number of observations for unit \(i\). Given estimated variance components, we run OLS on the transformed variables and iterate.

9.4 Correlated random effect

The correlated random-effect (CRE) model runs a random-effects regression of \(y_{it}\) on \(X_{it}\), \(\bar X_i\), time-invariant covariates \(w_i\), and a constant.

RE requires \(v_i\) and \(X_{it}\) to be uncorrelated — an assumption most economists reject. FE is consistent regardless, but it cannot estimate time-invariant covariates (race, gender, etc.). CRE includes time-invariant variables, and Mundlak and Wooldridge show that its coefficients on \(X_{it}\) are identical to the FE estimates. Its coefficients on \(w_i\) are another matter. Any part of the unit effect \(v_i\) that moves with \(w_i\) is indistinguishable from the coefficient on \(w_i\), so that coefficient is causal only under an extra restriction: that \(v_i\) is mean-independent of \(w_i\) once \(\bar X_i\) is controlled. Testing whether the coefficients on \(\bar X_i\) are jointly zero gives the Mundlak test for choosing between RE and CRE.

9.5 Example

Stata 18 added a cre option to xtreg. The following uses nlswork, 28,101 person-years from the National Longitudinal Survey of Young Women with complete data on the model’s variables. We regress log wage on tenure and age, which vary within a person, plus race, which does not — the covariate a fixed-effect model has to drop.

Code
webuse nlswork

xtreg ln_wage tenure age i.race, cre vce(cluster idcode)
(National Longitudinal Survey of Young Women, 14-24 years old in 1968)

note: 2.race omitted from xt_means because of collinearity.
note: 3.race omitted from xt_means because of collinearity.

Correlated random-effects regression            Number of obs     =     28,101
Group variable: idcode                          Number of groups  =      4,699

R-squared:                                      Obs per group:
     Within  = 0.1296                                         min =          1
     Between = 0.2346                                         avg =        6.0
     Overall = 0.1890                                         max =         15

                                                Wald chi2(4)      =    1685.18
corr(xit_vars*b, xt_means*γ) = 0.5474           Prob > chi2       =     0.0000

                             (Std. err. adjusted for 4,699 clusters in idcode)
------------------------------------------------------------------------------
             |               Robust
     ln_wage | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
xit_vars     |
      tenure |   .0211313   .0012113    17.44   0.000     .0187572    .0235055
         age |   .0121949   .0007414    16.45   0.000     .0107417     .013648
             |
        race |
      Black  |  -.1312068   .0117856   -11.13   0.000    -.1543061   -.1081075
      Other  |   .1059379   .0593177     1.79   0.074    -.0103225    .2221984
             |
       _cons |     1.2159   .0306965    39.61   0.000     1.155736    1.276064
-------------+----------------------------------------------------------------
xt_means     |
      tenure |   .0376991    .002281    16.53   0.000     .0332283    .0421698
         age |  -.0011984   .0013313    -0.90   0.368    -.0038077    .0014109
             |
        race |
      Black  |          0  (omitted)
      Other  |          0  (omitted)
-------------+----------------------------------------------------------------
     sigma_u |  .33334407
     sigma_e |  .29808194
         rho |  .55567161   (fraction of variance due to u_i)
------------------------------------------------------------------------------
Mundlak test (xt_means = 0): chi2(2) = 331.5144           Prob > chi2 = 0.0000

CRE gives tenure = .0211313 and age = .0121949, and estimates race as well: Black women earn 13.1% less (\(-.1312068\), SE .0118), while the “Other” category is marginal (\(.1059\), \(p = 0.074\)). The coefficients on the group means are .0376991 for mean tenure and \(-.0011984\) for mean age.

Stata prints the Mundlak test at the foot of the table: \(\chi^2(2) = 331.51\), \(p < 0.0001\). The group means are jointly far from zero, so plain random effects is rejected — \(v_i\) and the regressors are correlated, as the reported \(\text{corr} = 0.5474\) between the two blocks says directly.

To compare with a fixed effect model:

Code
webuse nlswork

xtreg ln_wage tenure age i.race, fe vce(cluster idcode)
(National Longitudinal Survey of Young Women, 14-24 years old in 1968)

note: 2.race omitted because of collinearity.
note: 3.race omitted because of collinearity.

Fixed-effects (within) regression               Number of obs     =     28,101
Group variable: idcode                          Number of groups  =      4,699

R-squared:                                      Obs per group:
     Within  = 0.1296                                         min =          1
     Between = 0.1916                                         avg =        6.0
     Overall = 0.1456                                         max =         15

                                                F(2, 4698)        =     766.79
corr(u_i, Xb) = 0.1302                          Prob > F          =     0.0000

                             (Std. err. adjusted for 4,699 clusters in idcode)
------------------------------------------------------------------------------
             |               Robust
     ln_wage | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
      tenure |   .0211313   .0012112    17.45   0.000     .0187568    .0235059
         age |   .0121949   .0007414    16.45   0.000     .0107414    .0136483
             |
        race |
      Black  |          0  (omitted)
      Other  |          0  (omitted)
             |
       _cons |   1.256467   .0194187    64.70   0.000     1.218397    1.294537
-------------+----------------------------------------------------------------
     sigma_u |  .39034493
     sigma_e |  .29808194
         rho |  .63165531   (fraction of variance due to u_i)
------------------------------------------------------------------------------

The coefficients on tenure and age are identical: .0211313 and .0121949 in both, with standard errors agreeing to the seventh decimal (.0012112 against .0012113). Race is reported as 0 (omitted) here, being collinear with the unit effects — the one thing FE cannot do and CRE can. This is the Mundlak result in practice: CRE gives you the fixed-effect estimates and the time-invariant coefficients from a single random-effects fit.

We can replicate this manually by including the group means in a RE model:

Code
webuse nlswork
* Restrict the mean calculation to the estimation sample (listwise-deleted
* on the model's variables), matching what xtreg's native cre option does
* internally. Both tenure and age have missing values in nlswork, so
* computing age_mean/tenure_mean over all rows for an idcode (rather than
* only rows with complete data on ln_wage, tenure, age, and race) would
* make the manual means diverge from cre's.
egen age_mean = mean(age) if !missing(ln_wage, tenure, age, race), by(idcode)
egen tenure_mean = mean(tenure) if !missing(ln_wage, tenure, age, race), by(idcode)
xtreg ln_wage tenure tenure_mean age age_mean i.race, vce(cluster idcode)
(National Longitudinal Survey of Young Women, 14-24 years old in 1968)

(433 missing values generated)

(433 missing values generated)


Random-effects GLS regression                   Number of obs     =     28,101
Group variable: idcode                          Number of groups  =      4,699

R-squared:                                      Obs per group:
     Within  = 0.1296                                         min =          1
     Between = 0.2346                                         avg =        6.0
     Overall = 0.1890                                         max =         15

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

                             (Std. err. adjusted for 4,699 clusters in idcode)
------------------------------------------------------------------------------
             |               Robust
     ln_wage | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
      tenure |   .0211313   .0012113    17.44   0.000     .0187572    .0235055
 tenure_mean |   .0376991    .002281    16.53   0.000     .0332283    .0421698
         age |   .0121949   .0007414    16.45   0.000     .0107417     .013648
    age_mean |  -.0011984   .0013313    -0.90   0.368    -.0038077    .0014109
             |
        race |
      Black  |  -.1312068   .0117856   -11.13   0.000    -.1543061   -.1081075
      Other  |   .1059379   .0593177     1.79   0.074    -.0103225    .2221984
             |
       _cons |     1.2159   .0306965    39.61   0.000     1.155736    1.276064
-------------+----------------------------------------------------------------
     sigma_u |  .33334407
     sigma_e |  .29808194
         rho |  .55567161   (fraction of variance due to u_i)
------------------------------------------------------------------------------

This is what Stata’s cre option does internally. Every number matches the first table: tenure .0211313, age .0121949, Black \(-.1312068\), Other .1059379, constant 1.2159, and the same variance components (\(\sigma_u\) .3333, \(\sigma_e\) .2981, \(\rho\) .5557). The cre option is a convenience, not a different estimator.

The one detail worth care is in the code above: the group means must be computed on the estimation sample. Both tenure and age have missing values in nlswork, so averaging over all of a woman’s rows rather than only her complete ones would give different means and break the equivalence.

9.6 Summary

Random effects is efficient but assumes the unit effect is uncorrelated with the regressors. Fixed effects drops that assumption but cannot estimate time-invariant covariates. The correlated random effects model adds the unit means of the time-varying regressors to a random-effects regression. That gives the fixed-effects slopes and estimates for time-invariant covariates in one fit. The joint test on the means is the Mundlak version of the Hausman test.

On the nlswork data, CRE and fixed effects give identical coefficients on tenure and age, .0211 and .0122. CRE also estimates the race gap, with Black women earning about 13% less. The Mundlak test strongly rejects plain random effects. Adding the means by hand reproduces Stata’s cre option exactly, provided the means are computed on the estimation sample.