I am analyzing panel data.

First, I have to decide whether to use a random or fixed effect estimator. The Hausman test suggests to use the fixed effect estimator (also named within group estimator). Thus, this is what I am using. However, this method eliminates the individual fixed effects, that is, the Ui's, which is what I am more interested about. Hence, I proceed with a second step.

Second, I run a between-group estimator where I regress the predicted individual effects, that is the Ui's predicted from the first step, against a list of time invariant fixed effects I am interested in

My questions are three:

  1. I was taught this two-step method in a graduate summer course, and no book I have read mentions it, do you know what is its name?
  2. Is it meaningful to cluster the standard errors on individuals in the first step? (i.e. within-group estimator)
  3. Is it meaningful to use a variable both as a covariate and as cluster for the standard error in the same model?
  • $\begingroup$ I am interested in the individual fixed effects. However, the Hausman test suggests I should use the within-group estimator, which eliminates the individual fixed effects. The solution I would like to adopt is this two steps method. The two-step method is illustrated in ftp.iza.org/dp7583.pdf page9-10 $\endgroup$
    – Fuca26
    Commented May 27, 2014 at 13:38
  • $\begingroup$ If you are interested in using fixed effects to remove omitted variables bias from non-time-varying characteristics, then you should NOT use random effects. You can recover the values of the estimated ID-wise intercepts by simply running a regression with the ID as a factor variable. If you're using R, you could also run it as a non-penalized random effect in a GAM model: library(mgcv); m = gam(y~s(ID,bs="re",sp=0)+x-1); plot(m) to get a plot of the estimated fixed effects. $\endgroup$ Commented May 27, 2014 at 21:46

3 Answers 3


You can and should use a well-specified random effects model. Always.

The Hausman test is said to suggest fixed effects models, but can and should be viewed "as a standard Wald test for the omission of the variables $\widetilde{\mathbf{X}}$" (Baltagi 2008, §4.3), where $\widetilde{\mathbf{X}}$ is a matrix of deviations from group means. If you do not omit $\widetilde{\mathbf{X}}$, a random effects model gives you the same population (fixed) effects as a fixed effects model, and the individual effects.

Mundlak (1978) argues that there is a unique estimator for the model $$\mathbf{y}=\mathbf{X}\boldsymbol{\beta}+\mathbf{Z}\boldsymbol{\alpha}+\mathbf{u}\qquad\qquad \mathbf{Z}=\mathbf{I}_{N}\otimes\mathbf{e}_T$$ where $\mathbf{I}_{N}$ is an identity matrix, $\otimes$ denotes Kronecker product, $\mathbf{e}_T$ is a vector of ones, so $\mathbf{Z}$ is the matrix of individual dummies, and $\boldsymbol{\alpha}=(\alpha_1,\dots,\alpha_N)$.

If $\alpha_i=\overline{\mathbf{X}}_{i*}\boldsymbol{\pi}+w_{i}$, $\boldsymbol{\pi}\ne\mathbf{0}$, averaging over $t$ for a given $i$, the model can be written as $$\mathbf{y}=\mathbf{X}\boldsymbol{\beta}+\mathbf{P}(\mathbf{X}\boldsymbol{\pi}+\mathbf{w})+\mathbf{u}\qquad\qquad \mathbf{P}=\mathbf{I}_N\otimes\bar{\mathbf{J}}_T$$ where $\mathbf{P}$ is a matrix which averages the observations across time for each individual (Baltagi 2008, §2.1). Under the fixed effects model, the within estimator is $$\hat{\boldsymbol{\beta}}_{w}=(\mathbf{X'QX})^{-1}\mathbf{X'Qy}\tag{1}$$ where $\mathbf{Q}=\mathbf{I}-\mathbf{P}$ is a matrix which obtains the deviations from individual means. Mundlak argues that under the random effects model, to get the same estimates the estimator should be $$\begin{bmatrix} \hat{\boldsymbol{\beta}} \\ \hat{\boldsymbol{\pi}}\end{bmatrix}= \left(\begin{bmatrix}\mathbf{X}' \\ \mathbf{X'P}\end{bmatrix}\boldsymbol{\Sigma}^{-1}\begin{bmatrix}\mathbf{X}&\mathbf{XP} \end{bmatrix}\right)^{-1}\begin{bmatrix}\mathbf{X}' \\ \mathbf{X'P} \end{bmatrix}\boldsymbol{\Sigma}^{-1}\mathbf{y}\tag{2}$$ where $\boldsymbol{\Sigma}^{-1}$ is the variance of the error term, while the "usual" estimator (the so-called "Balestra-Nerlove estimator") is $$\hat{\boldsymbol{\beta}}=(\mathbf{X}'\boldsymbol{\Sigma}^{-1}\mathbf{X})^{-1}\mathbf{X}'\boldsymbol{\Sigma}^{-1}\mathbf{y}$$ which is biased. According to Mundlak, since $(1)$ and $(2)$ obtain the same estimates for $\boldsymbol{\beta}$, $(2)$ is the within estimator, i.e. $(1)$ is the unique estimator and does not depend on the knowledge of the variance components.

However, the models $$\begin{align} \mathbf{y}&=\mathbf{X}\boldsymbol{\beta}+\mathbf{P}(\mathbf{X}\boldsymbol{\pi}+\mathbf{w})+\mathbf{u}\tag{FE} \\ \mathbf{y}&=\mathbf{X}\boldsymbol{\beta}+\mathbf{P}\mathbf{X}\boldsymbol{\pi}+(\mathbf{Pw}+\mathbf{u})\tag{RE} \end{align}$$ are formally equivalent (Hsiao 2003, §4.3), so a random effects model obtains the same estimates ... as long as you do not omit $\widetilde{\mathbf{X}}$! Let's try.

Data generation (R code):

N <- 25                 # individuals
T <- 5                  # time
In <- diag(N)           # identity matrix of order N
Int <- diag(N*T)        # identity matrix of order N*T
Jt <- matrix(1, T, T)   # matrix of ones of order T
Jtm <- Jt / T           
P <- kronecker(In, Jtm) # averages the obs across time for each individual
s2a <- 0.3              # sigma^2_\alpha
s2u <- 0.6              # sigma^2_u
w <- rep(rnorm(N, 0, sqrt(s2a)), each = T)
u <- rnorm(N*T, 0, sqrt(s2u))
b <- c(1.5, -2)
p <- c(-0.7, 0.8)
X <- cbind(runif(N*T, 2, 5), runif(N*T, 4, 8))
XPX <- cbind(X, P %*% X) # [ X PX ]
y <- XPX %*% c(b,p) + (P %*% w + u) # y = Xb + PXp + Pw + u
ds <- data.frame(id=rep(1:N, each=T), wave=rep(1:T, N), y, split(X, col(X)))

Under a fixed effects model we get:

> fe.1 <- plm(y ~ X1 + X2, data=ds, model="within")
> summary(fe.1)$coefficients
    Estimate Std. Error   t-value     Pr(>|t|)
X1  1.435987 0.07825464  18.35019 1.806239e-33
X2 -1.916447 0.06339342 -30.23100 1.757634e-51

while under a random effects model...

> re.1 <- plm(y ~ X1 + X2, data=ds, model="random")
> summary(re.1)$coefficients
             Estimate Std. Error    t-value     Pr(>|t|)
(Intercept)  1.830633 0.51687109   3.541759 5.638216e-04
X1           1.405060 0.07927271  17.724390 1.505521e-35
X2          -1.874784 0.06372731 -29.418846 3.076414e-57


But what if we do not omit $\widetilde{\mathbf{X}}=\mathbf{QX}$?

> Q <- diag(N*T) - P
> X1.mean <- P %*% ds$X1
    > X1.dev  <- Q %*% ds$X1
> X2.mean <- P %*% ds$X2
    > X2.dev  <- Q %*% ds$X2
> re.2 <- plm(y ~ X1.mean + X1.dev + X2.mean + X2.dev, data=ds, model="random")
> summary(re.2)$coefficients
               Estimate Std. Error      t-value     Pr(>|t|)
(Intercept) -0.04123108 2.30907450  -0.01785611 9.857833e-01
X1.mean      0.81279279 0.38146339   2.13072292 3.515287e-02
X1.dev       1.43598746 0.07824535  18.35236883 1.239171e-36
X2.mean     -1.23071499 0.26379329  -4.66545216 8.072196e-06
X2.dev      -1.91644653 0.06338590 -30.23458903 5.809240e-58

The estimates for X1.dev and X2.dev are equal to the within estimates for X1 and X2 (no room for Hausman tests!), and you get much more. You get what you need.

However this is just the tip of the iceberg. I recommend that you read at least Bafumi and Gelman (2006), Snijders and Berkhof (2008), Bell and Jones (2014).


Baltagi, Badi H. (2008), Econometric Analysis of Panel Data, John Wiley & Sons

Bafumi, Joseph and Andrew Gelman (2006), Fitting Multilevel Models When Predictors and Group Effects Correlate, http://www.stat.columbia.edu/~gelman/research/unpublished/Bafumi_Gelman_Midwest06.pdf

Bell, Andrew and Kelvyn Jones (2014), "Explaining Fixed Effects: Random Effects modelling of Time-Series Cross-Sectional and Panel Data", Political Science Research and Methods, http://dx.doi.org/10.7910/DVN/23415

Hsiao, Cheng (2003), Analysis of Panel Data, Cambridge University Press

Mundlak, Yair (1978), "On the Pooling of Time Series and Cross Section Data", Econometrica, 43(1), 44-56

Sniiders, Tom A. B. and Johannes Berkhof (2008), "Diagnostic Checks for Multilevel Models", in: Jan de Leeuw and Erik Meijer (eds), Handbook of Multilevel Analysis, Springer, Chap. 3

  • $\begingroup$ This is a nice answer, and a very simple rendition of the Bell and Jones paper (which I'm glad to see it is finally being published). Part of my hesitation to suggest this approach though is that estimating the model with group mean deviations is really a different model. (Much literature in sociology examined the issue in relation to estimating "frog-pond" effects). See The Effect of Different Forms of Centering in Hierarchical Linear Models (Kreft et al., 1995). $\endgroup$
    – Andy W
    Commented May 27, 2014 at 18:23
  • $\begingroup$ The fixed (lower level) effects are the same, but the higher contextual effects (e.g. X2.mean) ones are not between the fixed effects and random effects models (which is what the OP is interested in here). Typically the fixed effects model is only motivated by identification of the lower order effects, so again I don't see the real motivation of this if what you are interested in is the higher level effects (unless you have some substantive theory to expect the lower order effects to be of the "frog-pond" type). $\endgroup$
    – Andy W
    Commented May 27, 2014 at 18:27
  • $\begingroup$ @AndyW, in brief (what else?), I know Kreft et al. 1995, but I also like Raudenbush about adaptive centering and Bartels about cluster confounding. As to group means, including them in the model may offer interesting substantive results (Bafumi and Gelman), i.e. it's a different and richer model. Finally, a random effects model is always subject to objection: did you run the Hausman test? ;-) $\endgroup$
    – Sergio
    Commented May 27, 2014 at 19:08
  • $\begingroup$ That's a neat answer, and one that I hadn't seen before. I get that the X.dev terms are the marginal effects. But what is the interpretation of the X.mean? I guess the benefit of this model is that it facilitates prediction? $\endgroup$ Commented May 27, 2014 at 21:55
  • $\begingroup$ @ACD the X.dev terms are deviations from X.mean, the individual means. As to the interpretation of the X.mean, Bafumi and Gelman (2006) is a good starting point, Bartels (2008) an interesting in-depth analysis. $\endgroup$
    – Sergio
    Commented May 27, 2014 at 22:24

In addition to Andy W's answer, the procedure that was suggested to you is similar to the Fixed Effects Vector Decomposition (FEVD) proposed by Plümber and Troeger (2007). It's not quite the same but very alike to their three-step method which goes as follows:

  1. estimate the unit fixed effects
  2. decompose the fixed effects into the time-invariant factors and an error term
  3. estimate 1. again by pooled OLS including the time-invariant variables and the error from 2.

This procedure was heavily criticized by Greene (2011) and Breusch et al. (2011) so I would be careful with such types of estimation strategies. The point about the lower/higher level effects mentioned by Andy W is one of the set of critique points in these two papers.

If it helps you, I have written another post in a related question on how to keep time-invariant variables in fixed effects regressions. I hope you will find this useful.

  • $\begingroup$ Thank you Andy for your answer too, I will read the references! I did not know of the drawback you are mentioning! $\endgroup$
    – Fuca26
    Commented May 27, 2014 at 16:28

For 2, assuming that "individuals" are the cluster, no you shouldn't cluster the standard errors on the first step, and the same logic then extends to your question 3. For 1, this is sometimes called the between effects estimator in economics. See a Stata FAQ on it, and Snijders and Bosker's Multilevel modeling book has a pretty brief section explaining it as well.

That being said, I personally see no reason for it in favor of random effects modeling. Like Andrew Gelman says, "If you get to the point of asking, just do it." All the Hausman test tells you is if the between estimators are equal to the within estimators, which is not a terribly interesting question in and of itself. Most study designs should dictate the use of fixed effects or random effects, and here it appears you are really interested in the random effects.

  • $\begingroup$ Thank you very much for your answer Andy! Your responses to questions 2 and 3 are terribly important! Just one thing about the response to question 1. Yes, between effect estimator is the name of the model used in the second step, but I was wondering whether the method "step 1 followed by step 2" has a proper name. Thanks again!! $\endgroup$
    – Fuca26
    Commented May 27, 2014 at 14:03
  • $\begingroup$ I'm not quite sure what names you are looking for @Luca besides "between-effects" and "within-effects". I haven't seen any examples of this in practice, as random effects modelling is a much more direct way to examine the higher level effects. (Fixed effects make the lower level effects unbiased, not the higher ones, so it is unclear what is the motivation for the between effects estimator in practice.) $\endgroup$
    – Andy W
    Commented May 27, 2014 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.