Blog
Policy & causal

Panel data: fixed, random, Hausman

Separate differences between units from change within them, with fixed and random effects and the Hausman test.

Skari team7 min

Regress patents on R&D spending using eight years of data on 50 manufacturers, and you get a result like this.

"One percentage point more R&D intensity means 2.7 more patents!"

But firms with strong technology to begin with both spend more on R&D and file more patents. Could those firm-specific differences have slipped into the R&D effect?

With panel data — the same units observed over several years — this problem can be solved. Today we cover fixed-effects and random-effects models, and the Hausman test that decides between them.

What panel data is

Panel data is data that observes the same units repeatedly over several points in time. Like firm × year or region × month, it has two axes: the unit (entity) and time.

  • Sample — 50 fictional manufacturers × 8 years (2017–2024, 400 rows)
  • Outcome (Y) — patent applications per year
  • Predictor (X) — R&D intensity (% of sales)
  • Control — log sales

Why plain regression (pooled OLS) is risky

Putting all 400 rows into one regression is called pooled OLS.

  • If firm-specific traits (technical capability, industry, research culture) affect both R&D and patents, the coefficient is inflated
  • Several years from the same firm resemble one another, so standard errors tend to come out too small

So you need a model that separates "differences between firms" from "change within a firm".

Fixed-effects model (FE)

The fixed-effects model subtracts each firm's own average from every variable and estimates the slope only from how each firm changed from year to year (the within estimator).

That way every firm trait that does not change over time is filtered out, measured or not. In effect it asks, "in the years a firm raised its R&D, how many more patents did it file?"

The catch is that the effect of a variable that never changes over time, such as industry, cannot be estimated with fixed effects.

Random-effects model (RE)

The random-effects model treats each firm's difference as a randomly scattered value and estimates using both within-firm change and between-firm differences.

Using more information makes it more efficient, and time-invariant variables can be included. But it rests on a strong assumption: firm-specific traits must be unrelated to the predictors.

Choosing with the Hausman test

The Hausman test checks whether the fixed-effects and random-effects coefficients differ markedly.

  • p < .05 — the coefficients differ → the random-effects assumption fails → fixed effects
  • p ≥ .05 — no marked difference → the more efficient random effects is fine

Other tests are worth running alongside.

ComparisonTest
Pooled OLS vs fixed effectspoolability F test
Pooled OLS vs random effectsBreusch-Pagan LM test
Fixed vs random effectsHausman test

And because errors from the same firm are tied together in panel data, it is standard to use standard errors clustered by firm.

Reading the results

ModelR&D intensity
Pooled OLS2.70
Fixed effects1.22 · 95% CI [1.00, 1.44] · within R² .285
Random effects1.34
Hausman testχ²(2) = 24.94, p < .001 → fixed effects

The poolability F test was also significant (p < .001), so firm effects were real. With the Hausman test rejecting the random-effects assumption as well, report the fixed-effects model.

Within the same firm, a one-point rise in R&D intensity brings about 1.2 more patents. More than half of the pooled OLS figure of 2.7 was really the difference made by firms that were technologically strong to begin with.

How to write it up

A Hausman test on eight years of panel data from 50 manufacturers (N = 400) rejected the random-effects assumption (χ²(2) = 24.94, p < .001), so an entity fixed-effects model was adopted. With standard errors clustered by firm, a one-percentage-point increase in R&D intensity raised annual patent applications within the same firm by 1.22 (b = 1.22, SE = 0.11, 95% CI [1.00, 1.44], t(49) = 11.19, p < .001). This is less than half of the pooled OLS estimate (2.70), suggesting that firm-specific traits inflated the pooled estimate.

Example sentence · the numbers are made up

In Skari

In Skari Statistics, load data stacked one row per firm per year, switch the analysis list to By field and open Economics · policy → Panel data, where the Fixed Effects Model, Random Effects Model and Hausman Test sit side by side. (Under By method, they are in Econometrics → Panel Data.)

In the Fixed Effects Model, the variables step asks for the entity / unit column, time column, dependent variable (Y) and predictors (X); at the settings step you choose entity, time or two-way (entity + time) fixed effects and the type of standard error. Standard errors are clustered by entity by default.

Choosing the fixed-effects structure and standard errors — opened on the public Grunfeld investment data (10 firms × 20 years)
Choosing the fixed-effects structure and standard errors — opened on the public Grunfeld investment data (10 firms × 20 years)

Try fixed effects on your panel data

Opens Statistics at By field → Economics · policy → Panel data

Open fixed effects

Run the analysis and the results come together as a report. The within coefficients with confidence intervals, the poolability F test and a comparison of pooled OLS and fixed-effects coefficients appear together, so you see at once how much the firm effects changed the result.

Top of the fixed-effects report — example result (Grunfeld data, investment explained by firm value and capital stock)
Top of the fixed-effects report — example result (Grunfeld data, investment explained by firm value and capital stock)
Pooled OLS and fixed-effects coefficients compared — same example
Pooled OLS and fixed-effects coefficients compared — same example

The Hausman Test menu estimates fixed and random effects with the same variables and summarises the recommended model along with the FE − RE difference for each coefficient.

Hausman test summary — example result (wage panel of 545 US men over 8 years)
Hausman test summary — example result (wage panel of 545 US men over 8 years)
FE − RE difference by coefficient — same example
FE − RE difference by coefficient — same example

The Random Effects Model report also includes a model-selection table with the Breusch-Pagan LM and Hausman tests, plus the variance components. Reports download as Word, PDF or Excel.

Wrapping up

The heart of panel analysis is separating differences between units from change within them. Start with pooled OLS, then go F test → LM test → Hausman test to choose between fixed and random effects, and you will be one step closer to "the real effect of R&D".

Want the theory behind it?The Academy's panel data chapter covers within-unit change, fixed and random effects and the Hausman test in depth →

Keep reading

Every feature free through Dec 31, 2026

Run the analyses from these posts on your own data