Panel Data Analysis: Fixed or Random Effects? (The Hausman Test)

Fixed or random effects in panel data analysis? The Hausman test decision rule, within and GLS estimators, key diagnostics and robust standard errors.

In graduate theses and empirical journal articles, panel data analysis combines cross-sectional and time-series information by following the same units (firms, countries, regions, hospitals) over time. Yet the question examiners and reviewers raise most often has not changed: fixed effects or random effects? This guide sets out the logic of both estimators, the null hypothesis and decision rule of the Hausman test, and the diagnostic battery that referees now treat as standard — with concrete thresholds throughout.

The structure of panel data and the pitfalls of pooled OLS

A panel observes N units over T periods, giving an N×T structure. The baseline model is written yit = β′xit + αi + εit, where αi captures unobserved, time-invariant heterogeneity — management quality, institutional design, geography. Pooled OLS simply ignores this term. If αi is correlated with the regressors, the coefficients are biased and inconsistent; even if it is not, observations belonging to the same unit are not independent, so classical standard errors are understated and t statistics artificially inflated. Panel estimators exist precisely to deal with these two problems.

Fixed effects: the logic of the within transformation

The fixed effects (FE) estimator subtracts each unit's own mean from every variable (yit − ȳi) and estimates the model on the within (demeaned) transformation. This algebraically eliminates αi altogether, so the coefficients remain consistent no matter how strongly the unit effects are correlated with the regressors. The price is twofold: time-invariant variables (gender, region, year of foundation) are wiped out by the demeaning, and regressors with little within-unit variation acquire large standard errors. FE learns only from variation within units; differences between units are absorbed into the identity of each unit.

Random effects: the GLS logic and the consistency condition

The random effects (RE) estimator treats αi as a random draw from a common distribution and estimates the model by generalised least squares (GLS) using quasi-demeaning, yit − θȳi. The parameter θ, computed from the variance components, lies between 0 and 1: at θ = 1 RE collapses to fixed effects, at θ = 0 to pooled OLS. Because RE exploits both within and between variation, it is more efficient than FE under its own assumptions and can estimate time-invariant covariates. But one condition is decisive: the unit effects must be uncorrelated with the regressors, Corr(αi, xit) = 0. If that condition fails, RE is inconsistent — and its efficiency advantage is worthless.

Fixed effects versus random effects at a glance
FeatureFixed effects (FE)Random effects (RE)
Core assumptionαi may be correlated with regressorsRequires Corr(αi, xit) = 0
Estimation methodWithin (demeaned) transformationGLS with quasi-demeaning (θ)
Time-invariant variablesDropped from the modelCan be estimated
When Corr(αi, x) ≠ 0ConsistentInconsistent
Efficiency under RE assumptionsLess efficientEfficient
Stata / R commandxtreg, fe / plm(model = "within")xtreg, re / plm(model = "random")

The Hausman test: null hypothesis and decision rule

The null hypothesis of the Hausman test is that the difference between the FE and RE coefficients is not systematic: under H₀ both estimators are consistent and RE is, in addition, efficient. The test statistic is H = (bFE − bRE)′[V(bFE) − V(bRE)]⁻¹(bFE − bRE), distributed as chi-squared with k degrees of freedom.

  1. If p < 0.05, reject H₀: the coefficient differences are systematic, RE is inconsistent → report fixed effects.
  2. If p ≥ 0.05, H₀ cannot be rejected: both estimators are consistent → the more efficient random effects may be preferred.
  3. The classical Hausman test assumes homoskedasticity; in the presence of heteroskedasticity or serial correlation, use the Mundlak approach (add the unit means of the regressors and test their joint significance) or a robust/bootstrap Hausman variant instead.
The Hausman test does not tell you which model is true; it tells you whether random effects is defensible.

Diagnostics and robust standard errors in panel data analysis

The FE/RE decision is only half the job; referees now expect three standard diagnostics before any validity discussion. In each of them, p < 0.05 signals that the problem is present:

  • Modified Wald test: tests groupwise heteroskedasticity after an FE model; H₀ = unit-level error variances are equal.
  • Wooldridge test: tests first-order serial correlation in panel data; H₀ = no AR(1) autocorrelation.
  • Pesaran CD test: tests cross-sectional dependence between units; H₀ = cross-sectional independence. In macro panels this is rejected almost routinely because of common shocks.

When a problem is detected, standard practice is not to abandon the model but to correct the standard errors. If heteroskedasticity and autocorrelation occur together, cluster-robust standard errors clustered at the unit level suffice; if cross-sectional dependence is also present and the time dimension is reasonable (roughly T ≥ 20), Driscoll-Kraay standard errors, robust to all three problems at once, are the preferred choice. In long macro panels the stationarity of the variables should also be checked — see our guide to unit root tests for the details.

72543618072Heteroskedasticity64Serial correlation51Cross-sectional dependence33All three at once8None
Share of applied panel studies in which each diagnostic signals a problem, % (illustrative)

Software: Stata, R and EViews

In Stata the workflow is clean: declare the panel with xtset; estimate xtreg y x, fe and xtreg y x, re; run hausman on the stored results; then xttest3 (modified Wald), xtserial (Wooldridge) and xtcsd, pesaran for the diagnostics, with xtscc supplying Driscoll-Kraay errors. In R, the plm package covers the same ground: compare plm(..., model = "within") with model = "random" via phtest, and obtain robust covariances with vcovHC and vcovSCC. In EViews, the effects type is chosen in the panel estimation options and the Hausman test is reported from the menu in one click. Whichever package you use, attaching the full script to your thesis appendix is a strong signal of reproducibility.

Frequently Asked Questions

What should I do if the Hausman test p-value is very close to 0.05?

With borderline results, do not lean on a single p-value; confirm the decision with the Mundlak approach. If the unit means are jointly significant, fixed effects is the safe choice, and the economic rationale should be reported alongside the test.

My time-invariant variable was dropped in the fixed effects model — what now?

If that coefficient is central to your research question, consider a Mundlak-type correlated random effects (CRE) specification or the Hausman-Taylor estimator. If the variable is merely a control, fixed effects already controls for it implicitly and nothing further is needed.

How many units and periods are enough for panel data analysis?

There is no mechanical minimum, but reliable estimation of the GLS variance components usually calls for at least 10-15 units and more than 5 periods. With small N and long T, panel time-series tools are more appropriate; with very short T, dynamic panel (GMM) methods may be required.

What does Celsus offer for panel data analysis?

Celsus handles model specification, FE/RE estimation with Hausman and Mundlak decision analyses, the full diagnostic battery, and final tables with cluster-robust or Driscoll-Kraay standard errors. Stata or R scripts are delivered in fully reproducible form, together with thesis- and journal-ready reporting.

← All posts