The Hausman test is the standard way to choose between fixed and random effects in panel data. In Stata it takes one line, yet its output is easy to misread. Building on our fixed vs random effects guide, this deep-dive states the null hypothesis precisely, works through a numeric example, gives the exact Stata sequence and explains what to do when the statistic is negative or your errors are clustered.
What the Hausman test compares
Hausman (1978) proposed comparing two estimators of the same parameters: one consistent whether or not a suspect assumption holds, and one efficient only if it holds. In panel data the suspect assumption is that the unit effects αi are uncorrelated with the regressors. The fixed effects (within) estimator removes αi, so it is consistent under both hypotheses. The random effects (GLS) estimator is consistent and efficient under the null but inconsistent under the alternative. If the assumption holds, the two coefficient vectors differ only by sampling error; if it fails, RE drifts away from FE and the gap becomes systematic. The same principle drives the Durbin–Wu–Hausman endogeneity test (OLS versus instrumental variables).
Hausman test null hypothesis and the chi-square statistic
- H₀: Cov(αi, xit) = 0. Both estimators are consistent and the difference bFE − bRE is not systematic; RE is preferred for its efficiency.
- H₁: Cov(αi, xit) ≠ 0. FE stays consistent, RE does not; FE is preferred.
The statistic is H = (bFE − bRE)′[VFE − VRE]⁻¹(bFE − bRE). Under H₀ the efficient estimator is uncorrelated with the difference, so the variance of the difference reduces to VFE − VRE, and H follows a chi-square distribution with degrees of freedom equal to the number of coefficients compared. Time-invariant regressors (dropped by FE) and, by default, the constant are excluded, so the df usually equals the number of time-varying regressors; year dummies in both models are compared too. Strictly, the df is the rank of VFE − VRE, and Stata prints a note when it differs from the number of coefficients.
Hausman test interpretation: a worked example
Suppose a thesis models return on assets (ROA) for 120 firms over 8 years with three time-varying regressors. The numbers are illustrative; Stata's hausman output looks like this:
| Regressor | b (FE) | B (RE) | b − B | √diag(V_b − V_B) |
|---|---|---|---|---|
| Leverage | −0.084 | −0.048 | −0.036 | 0.009 |
| Firm size | 0.006 | 0.016 | −0.010 | 0.005 |
| Sales growth | 0.031 | 0.027 | 0.004 | 0.004 |
| Joint test | — | — | χ²(3) = 19.84 | p = 0.0002 |
First, compare the statistic with the chi-square critical value for 3 df: 7.81 at 5% and 11.34 at 1%. As 19.84 exceeds both, Stata prints Prob > chi2 = 0.0002. Second, reject H₀: the differences are systematic, RE is inconsistent and the fixed effects model should be reported. Third, locate the gap. Dividing each difference by its standard error is a rough guide: leverage (−0.036 / 0.009 = −4.0) and firm size (−2.0) differ clearly, sales growth (1.0) does not. Here RE understates the leverage effect by more than 40%.
Two cautions. A p-value of 0.05 or above means no evidence against RE, not proof that its assumption holds: with little within-unit variation, FE is imprecise and the test has low power. And in very large panels even trivial differences become significant, so judge the size of b − B as well.
Hausman test in Stata: step by step
- xtset firm year — declare the panel.
- xtreg roa leverage size growth, fe — fixed effects with default standard errors.
- estimates store fe
- xtreg roa leverage size growth, re — random effects, same sample and regressors.
- estimates store re
- hausman fe re — consistent estimator first, efficient one second.
- hausman fe re, sigmamore — if Stata warns that V_b − V_B is not positive definite.
Order matters: hausman re fe reverses the variance difference and can yield a negative or meaningless statistic. sigmamore bases both covariance matrices on the disturbance variance from the efficient (RE) model, sigmaless on the one from the consistent (FE) model; the Stata manual recommends them for FE–RE comparisons because a common variance estimate makes a non-positive-definite difference much less likely. Keep default standard errors here: the classic test assumes RE is fully efficient, which fails once you need robust or clustered errors.
In EViews, estimate the equation with the cross-section effect set to Random (Panel Options tab), then choose View → Fixed/Random Effects Testing → Correlated Random Effects – Hausman Test. The output gives the chi-square statistic, df and p-value, plus a coefficient-by-coefficient comparison.
Negative chi-square, clustered errors and robust alternatives
- Negative χ² or a 'not positive definite' warning: in finite samples VFE − VRE need not be positive definite. Check command order, sample and regressor list, then try sigmamore. A negative value is not evidence for RE.
- Heteroskedasticity or serial correlation: RE is then no longer fully efficient, the variance formula breaks down and the classic test is invalid — the usual case when your final model uses clustered errors.
- Mundlak (correlated random effects) test: following Mundlak (1978), add the unit means of the time-varying regressors to the RE model and test them jointly with cluster-robust errors. Rejection points to FE.
- xtoverid: a community-contributed command (ssc install xtoverid) run after xtreg ..., re vce(cluster firm); its Sargan–Hansen statistic tests the extra orthogonality conditions of RE, and rejection points to FE. It may not accept factor-variable notation such as i.year, so create dummies manually if needed.
In Stata the Mundlak version is: bysort firm: egen m_lev = mean(leverage), likewise m_size and m_growth (on the estimation sample); xtreg roa leverage size growth m_lev m_size m_growth, re vce(cluster firm); test m_lev m_size m_growth. A Wald χ²(3) with p below 0.05 favours FE. In a balanced panel the coefficients on the original regressors equal the FE estimates, and time-invariant variables can stay in the model.
Decision table and how to report the Hausman test
| Test (Stata) | Null hypothesis | If p < 0.05 | If p ≥ 0.05 |
|---|---|---|---|
| F test that all u_i = 0 (xtreg, fe) | No unit effects | Unit effects present; pooled OLS rejected | Pooled OLS not rejected |
| Breusch–Pagan LM (xttest0 after xtreg, re) | Var(αi) = 0 | RE preferred to pooled OLS | Pooled OLS not rejected |
| Classic Hausman (hausman fe re) | Differences not systematic | Fixed effects | Random effects |
| Mundlak test or xtoverid (clustered SEs) | RE orthogonality conditions hold | Fixed effects | Random effects |
Report the statistic, df, p-value, the variant used (classic, sigmamore or robust Mundlak) and the standard-error type of the final model. An APA 7 sentence: “A Hausman test indicated systematic differences between the fixed- and random-effects coefficients, χ²(3) = 19.84, p < .001; fixed-effects estimates are therefore reported with firm-clustered standard errors.” Write Stata's 0.0002 as p < .001, never p = .000; see our APA 7 reporting checklist. For the whole FE/RE decision and final tables, our econometric analysis service delivers reproducible Stata do-files.
A Hausman test is only as trustworthy as its assumptions: check them before you trust the p-value.
Frequently Asked Questions
What is the null hypothesis of the Hausman test?
That the difference between the fixed- and random-effects coefficients is not systematic, which holds when the unit effects are uncorrelated with the regressors. Rejecting it favours fixed effects.
How do I interpret the Hausman test p-value in Stata?
Read the Prob > chi2 line. Below 0.05, reject the null and use fixed effects; at 0.05 or above, there is no evidence against random effects, which can be kept for its efficiency.
Why is my Hausman test chi-square negative?
The estimated variance difference is not positive definite, often because the command order is reversed or the models use different samples. Try hausman fe re, sigmamore; if that fails, use the Mundlak test or xtoverid with clustered errors.
Can Celsus run the Hausman test and panel models for my thesis?
Yes. Celsus runs the full panel workflow in Stata or EViews, from F, Breusch–Pagan and Hausman tests to robust Mundlak checks and final tables with clustered or Driscoll-Kraay errors. You receive reproducible do-files and APA-ready reporting text.