Home › Blog › Fixed vs Random Effects in Stata: How to Run and Interpret the Hausman Test
Data Analysis

Fixed vs Random Effects in Stata: How to Run and Interpret the Hausman Test

Panel data in your thesis? Here is how to set it up in Stata, estimate fixed and random effects models, run the Hausman test and explain your choice to examiners.

15 November 2026 · By Karatasi ·3 min read

If your thesis follows the same units, such as households, firms, counties or countries, over several time periods, you have panel data. The first modelling decision examiners will ask about is whether you used fixed effects (FE) or random effects (RE), and why. This guide shows you how to make and defend that choice in Stata.

Why panel data needs special models

Each unit has characteristics you can't observe that stay roughly constant over time: management quality, culture, geography. If these unobserved traits are correlated with your explanatory variables, ordinary pooled OLS gives biased estimates. Panel models deal with them in two different ways.

The Hausman test checks whether that key RE assumption holds.

Step 1: Declare your panel

* id = unit identifier, year = time variable
xtset id year
xtdescribe        // check how balanced the panel is
xtsum yield credit rainfall   // within vs between variation

If xtset complains about repeated time values within a panel, you have duplicate unit-year rows. Find them with duplicates report id year before going further.

Step 2: Estimate both models and store them

xtreg yield credit rainfall fert_use, fe
estimates store fe

xtreg yield credit rainfall fert_use, re
estimates store re

Step 3: Run the Hausman test

hausman fe re

The order matters: put the consistent model (FE) first and the efficient model (RE) second.

Step 4: Interpret the result

The null hypothesis is that the differences between FE and RE coefficients are not systematic, which means RE is consistent and preferred.

You might report: "The Hausman test rejected the null hypothesis that the random effects estimator is consistent (χ²(3) = 18.42, p < 0.001); the fixed effects model is therefore preferred."

Common problems and how to handle them

"V_b-V_B is not positive definite"

This warning is common in finite samples. Try hausman fe re, sigmamore, which bases both covariance matrices on the same error variance estimate and usually resolves it.

Robust or clustered standard errors

The classic Hausman test is not valid with robust or clustered standard errors. Most panel data needs those because of heteroskedasticity and serial correlation. The usual alternatives are:

Whichever model you choose, report the final estimates with clustered standard errors: xtreg yield credit rainfall fert_use, fe vce(cluster id).

Beyond FE and RE

Running panel models for your thesis? We help Masters and PhD students set up panel data, choose and test the right estimator, and interpret the output, with commented do-files you can re-run and defend.

Get help with Stata panel analysis →

StataPanel dataEconometricsHausman testFixed effects

Want support with your analysis?

Thesis data analysis and defense prep in R, Stata, SPSS, EViews, Excel and Power BI, with code and explanations you can defend.

Get a free quote →