Fixed Effects vs Random Effects in Stata (Hausman Test Explained)

Fixed Effects vs Random Effects in Stata (Hausman Test Explained)

If you are running panel data in Stata and stuck between xtreg, fe and xtreg, re, you are not the only one. This is the fixed effects vs random effects decision. Almost every thesis student, PhD scholar, and working analyst hits this same wall at some point.

In this article I will explain it in simple terms and give you the actual commands. I will also share my honest opinion on the academic research around this topic. I will point out where I think it goes too deep into theory and forgets the practical side.

I am Siddharth Gupta. I have spent more than 10 years in analytics consulting, working with R, Python, SPSS, Stata, and Power BI. My work spans finance, BFSI, marketing, and econometrics projects.

I have handled panel data Stata work for real clients many times, not just in textbook examples. This article also covers Hausman test interpretation the way I actually apply it, not just the theory.

What Fixed Effects and Random Effects Actually Mean

Panel data means you are tracking the same units, such as people, firms, states, or countries, across multiple time periods. The problem is that each unit has its own hidden characteristics that do not change with time but still affect your outcome.

A firm’s management style. A state’s political culture. A student’s natural ability.

You have two ways to handle this hidden characteristic. That choice is the fixed effects vs random effects decision.

Fixed Effects: Controlling for What You Cannot Observe

A fixed effects model assumes that each unit’s hidden characteristic is correlated with your independent variables. Instead of trying to measure that hidden part, the model simply removes it by looking only at how things change within each unit over time.

A fixed effects model in panel data estimates the relationship between variables by controlling for all time invariant characteristics of each unit. It uses only the within unit variation over time.

In Stata, this is the xtreg fixed effects command, written as xtreg y x1 x2, fe. For example, say you are studying how R&D spending affects profit for 200 firms over 10 years. Fixed effects will control for everything unique to each firm. Things like brand strength or founding year, that do not change year on year, get absorbed automatically.

Random Effects: Assuming No Correlation With Your Regressors

A random effects model assumes the unit specific characteristic is not correlated with your independent variables. It treats that hidden part as random noise, which allows the model to use both within unit and between unit variation.

This matters because random effects is more efficient. It uses more information present in your data. The catch is, if this assumption is wrong, your estimates become biased. The xtreg random effects command is xtreg y x1 x2, re.

Still confused about which software to start with? Check this out: R vs Stata for beginners, what to choose for data analysis.

Fixed Effects vs Random Effects at a Glance

PointFixed EffectsRandom Effects
Key assumptionUnit effect IS correlated with regressorsUnit effect is NOT correlated with regressors
Stata commandxtreg y x1 x2, fextreg y x1 x2, re
Uses which variationWithin unit onlyWithin unit and between unit
EfficiencyLess efficientMore efficient, if assumption holds
Risk if wrongLoses some efficiencyCoefficients become biased
Confirm withHausman test rejects nullHausman test fails to reject null

The Hausman Test: What It Is Really Testing

You do not just guess between fixed and random effects. You test it properly, and running the Hausman test in Stata is the standard way to do this. The Hausman test, from Jerry Hausman’s 1978 paper, compares the coefficients from both models. It checks if they differ in any way.

Amini, Delgado, Henderson and Parmeter wrote a review tracing how this test has been used and extended over four decades. It is good for background reading. It is written for other academics, not for someone with real client data and a deadline. Read it to understand history, not to learn execution.

The Null and Alternative Hypothesis in Plain English

  • Null hypothesis (H0): The random effects estimator is consistent and efficient. The unit specific effect is not correlated with your regressors. Use random effects.
  • Alternative hypothesis (H1): The random effects estimator is not consistent. There IS correlation. Use fixed effects.

You are not testing which model is “better” in some general sense. You are testing whether the extra efficiency you get from random effects is coming at the cost of biased results.

Why This Decision Matters for Your Thesis or Paper

Choosing the wrong model does not just cost you marks. It can flip your entire conclusion. If your true model needs fixed effects but you ran random effects instead, your coefficients are biased. Any conclusion built on top of them becomes unreliable.

University examiners ask students to justify this choice in the viva. A common thesis topic here is state-level panels, for example MSME finance data or state GDP series across states. These panels are very often unbalanced, since state-level reporting years do not always match. That makes this decision even more important to get right and defend properly.

How to Run the Hausman Test in Stata (Step by Step)

Here is the exact sequence for the Hausman test Stata workflow. No guessing, no shortcuts.

  1. Run the fixed effects model: xtreg y x1 x2, fe
  2. Store the fixed effects estimates: estimates store fe
  3. Run the random effects model: xtreg y x1 x2, re
  4. Store the random effects estimates: estimates store re
  5. Run the Hausman test: hausman fe re
  6. Read the chi square statistic and p value from the output
  7. Decide based on the p value threshold, usually 0.05

That’s it. Same seven steps every time, whether your panel is balanced or unbalanced.

Interpreting Your Result

This is the part where most students freeze up looking at the output table. It is simpler than it looks, if you know what to check.

p Less Than 0.05: Go With Fixed Effects

A significant Hausman test, meaning p value below 0.05, tells you to reject the null. The random effects assumption does not hold, your unit specific effects are correlated with your regressors. Use fixed effects, and mention the Hausman chi square and p value in your methodology section as justification.

p More Than 0.05: Random Effects Is Fine, and More Efficient

A non-significant result means you fail to reject the null. There is no statistical evidence that unit effects are correlated with your regressors. Random effects is not just acceptable here, it is actually the better choice because it uses more of your data’s variation.

When the Hausman Test Is Not Enough (My Honest Opinion)

This is where most tutorials online stop, and where the real problems begin. I have run this test many times on actual client and thesis data, and it does not always behave the way the textbook promises.

The Negative Chi Square Problem

Sometimes Stata gives you a negative chi square value for the Hausman test. This is not a Stata bug. It happens because the test assumes the variance difference between fixed and random effects should be positive.

That assumption does not always hold in your particular sample. Small samples, near singular covariance matrices, or unbalanced panels with a lot of gaps commonly cause this.

When this happens, students often panic or keep rerunning the command hoping for a different number. That is not a fix. The honest options are to use xtoverid after random effects for a more solid overidentification check. Or move to a Mundlak style correlated random effects approach instead of depending on the classic Hausman test alone.

Another common error you will see in Stata is a message saying the model does not meet the asymptotic assumptions of the test. This is Stata’s polite way of telling you the same thing.

Your covariance matrix difference is not behaving. Do not ignore this message and force the test through. Switch to xtoverid or the Mundlak approach instead.

Why Robust or Clustered Standard Errors Complicate the Test

The default Stata Hausman test assumes errors are homoskedastic and not serially correlated. Real panel data almost never behaves this nicely. You usually have heteroskedasticity and serial correlation within units.

Clustering means you allow errors to be correlated within each unit over time, instead of assuming every observation is independent. In Stata, you add this with vce(cluster id) in your xtreg command, where id is your panel identifier. This is standard practice for most panel data work now, not an optional extra.

Bole and Rebec studied this and showed that the standard asymptotic Hausman test can seriously misstate its own size and power. This is especially true at stricter significance levels. Their bootstrap version corrects a large part of this error.

My take: this is one of the few papers that admits the plain Hausman test people run by default is less trustworthy than textbooks suggest. The weak point is that their bootstrap correction is heavy on simulation detail. It is useful for a journal, not something a thesis student can build in an afternoon before submission.

Baltagi’s chapter makes an important point. He says rejecting the null under the standard test only signals model misspecification in general, it is not automatically a certificate for fixed effects.

My take: I agree with this fully, and I think it is the single most underused piece of advice in student theses. Most students see a rejected test and jump straight to fixed effects without asking why.

Where the chapter falls short is that it stays theoretical about “what to check next,” like endogeneity or misspecified dynamics. It does not give Stata level, hands-on guidance. Good for direction, not enough on its own for execution.

Practically speaking, if you suspect heteroskedasticity or serial correlation, do not run the plain hausman command and call it done. Use the robust variant, add clustering with vce(cluster id), or cross check with xtoverid, which handles this situation more cleanly.

Alternatives: Mundlak’s Correlated Random Effects Approach

If your Hausman test result is unstable, negative, or does not match your theory, the correlated random effects Mundlak approach is a practical middle path. It adds the time averages of your time varying regressors into a random effects model. This directly tests whether unit effects correlate with regressors, without the small sample fragility of the classic Hausman statistic.

Papke and Wooldridge propose something related but slightly different. It is a regression based test for whether fixed effects should be controlled at a more aggregate group level or at the disaggregated unit level. It stays simple to apply even with unbalanced panels, while being robust to heteroskedasticity and cluster correlation.

My take: this is the most practically useful paper of the six I am covering here. It is written by people who clearly know what happens on the ground when a researcher has messy, unbalanced data. The test they propose can actually be coded in Stata without needing a statistics PhD.

The one thing to watch is that this test answers a slightly different question, school level versus district level in their example. So do not assume it replaces the classic Hausman test. It complements it.

This is exactly the kind of decision that benefits from a second opinion before you write it into a thesis chapter. Get 1-on-1 help choosing the right model.

Common Mistakes Students Make

  • Running the Hausman test once and reporting the p value without checking if errors are heteroskedastic or clustered
  • Treating a non-significant Hausman result as proof that there is no unit effect at all, when it only proves there is no correlation with regressors
  • Ignoring a negative chi square instead of investigating why it happened
  • Not reporting the Hausman test statistic and decision rule properly in the methodology section
  • Forcing the plain Hausman test through even when Stata warns the asymptotic assumptions are not met
  • Assuming the quasi-demeaned computation and the untransformed FGLS computation of the test always give the same answer, when they can diverge

Two Specialist Papers Worth Knowing About

Mutl and Pfaffermayr show that the standard Hausman comparison needs adjustment when units are spatially linked. The test statistic’s behaviour changes once spatial autocorrelation enters the picture.

My take: solid and technically sound, but written for spatial econometrics specialists. Unless your thesis is specifically about spatial data, such as agriculture, regional economics, or real estate panels, you do not need to apply this. Know that the problem exists. Move on if it does not apply to you.

Le Gallo and Sénégas show that the quasi-demeaned and untransformed FGLS computations of the Hausman test can diverge quite a lot in finite samples. This depends on the within-between structure of your regressors.

My take: genuinely useful and underrated. Most software, Stata included, uses the quasi-demeaned version by default without warning you this could be unreliable in small samples. The gap in this paper is that it flags the problem but gives no simple rule of thumb for when the divergence becomes serious. That judgment call is still on you.

Why I Recommend Getting a Second Pair of Eyes on This

The Hausman test looks like a simple, one-command decision. It is not. Whether your panel is balanced, how your errors behave, and what your theory predicts, all of this changes what the right answer looks like. Getting this wrong is best discovered before your viva, not during it.

This is exactly the kind of judgment call I help people with through Statssy. Not just running the command, but making sure your choice holds up under questioning. Get 1-on-1 help choosing the right model.

Sources referenced and reviewed:

Baltagi (2024),

Papke and Wooldridge (2024),

Bole and Rebec (2013),

Amini, Delgado,

Henderson and Parmeter (2012),

Le Gallo and Sénégas (2023),

Mutl and Pfaffermayr (2011).

Perfect for students, researchers, and professionals looking to build real statistical skills.

Frequently Asked Questions

It tests whether the unit specific effects in your panel data are correlated with your independent variables. This tells you whether fixed effects or random effects gives you consistent results.

Run xtreg y x, fe then estimates store fe. Run xtreg y x, re then estimates store re. Then run hausman fe re and read the chi square and p value.

It means you fail to reject the null hypothesis. There is no strong evidence that your unit effects correlate with your regressors, so random effects is the more efficient and valid choice.

Yes, this happens when the test's underlying variance assumptions break down in your sample, often with small or unbalanced panels. Use xtoverid or a Mundlak correlated random effects approach instead of forcing the standard test to work.

The standard Hausman test assumes no heteroskedasticity or serial correlation. With robust or clustered errors, use the robust version of the test, add vce(cluster id) to your model, or cross check with xtoverid.

It means the same problem as a negative chi square, your covariance matrix difference is not behaving as the test expects. Do not force it through. Switch to xtoverid or a Mundlak correlated random effects model.

No. It is a specification test, not an automatic model selector. A rejection signals misspecification in general. You should still check your theory, your panel structure, and your standard error assumptions before finalising your model choice.