Panel data analysis: pooled OLS, fixed and random effects

Panel data, the same firms, banks or countries observed over several years, is the most common data structure in economics and finance dissertations. Here's how to choose the right panel model, test it and report it.

5 min readReviewed 2026-11-25Stata · EViews · R
M

Made for: Master's dissertation student

Your data is ready. The model isn't cooperating.

Sound familiar?

  • The Hausman test says one thing and your supervisor says another
  • Stata or EViews throws errors you can't decode at 1 a.m.
  • You're not sure your results are even the right ones to report
  • The deadline is fixed, and your supervisor has 20 other students

We diagnose your model, run it with you, and explain every number so you can defend it.

What is panel data?

Panel (longitudinal) data follows the same units (i = firms, banks, countries) over several periods (t = years, quarters). A dataset of 120 listed firms over 2014–2023 is a panel with N = 120 and T = 10.

Panels let you control for unobserved heterogeneity: characteristics of each unit that don't change over time and that you can't measure, such as management culture, geography or institutions. Ignoring them is the most common reason a cross-sectional regression gives biased results.

A panel is balanced if every unit is observed in every period and unbalanced otherwise. Most estimators handle both.

The three basic models

Model Assumption about the unit effect αᵢ When it fits
Pooled OLS No unit effects at all (αᵢ = α for everyone) Rarely; mostly as a baseline
Fixed effects (FE) αᵢ may be correlated with the regressors Default for firms and countries; effects of time-varying variables only
Random effects (RE) αᵢ is uncorrelated with the regressors When units are a random sample and that assumption is credible; can estimate time-invariant variables

The general model is: yᵢₜ = α + β′xᵢₜ + αᵢ + εᵢₜ.

Fixed effects removes αᵢ by demeaning each variable within its unit (the "within" transformation). The cost is that you can't estimate variables that never change for a unit, such as a country's legal origin or a firm's industry.

Random effects treats αᵢ as part of the error term and uses a GLS weighting. It is more efficient than FE, but inconsistent if αᵢ is correlated with your regressors.

Step by step

  1. Declare the panel and check its structure.
  2. Describe the data: summary statistics, within and between variation (xtsum in Stata). A variable with almost no within variation will be poorly estimated by FE.
  3. Estimate pooled OLS as a baseline.
  4. Test for unit effects. An F-test that all αᵢ = 0 (reported after FE), and the Breusch-Pagan LM test for random effects (xttest0). If both are insignificant, pooled OLS is acceptable.
  5. Estimate FE and RE, then choose between them with the Hausman test (FE vs RE).
  6. Test the error structure: heteroskedasticity (modified Wald test, xttest3), serial correlation (Wooldridge test, xtserial) and, for long or macro panels, cross-sectional dependence (Pesaran CD test, xtcsd).
  7. Use robust inference. If any of these tests reject, report cluster-robust standard errors (clustered by unit), or Driscoll-Kraay standard errors when there is cross-sectional dependence.
  8. Add time effects (year dummies) if common shocks such as a crisis or COVID affect all units. Test their joint significance with testparm.
  9. Run robustness checks: alternative proxies, subsamples, lagged regressors or a dynamic model (GMM (Arellano-Bond, system GMM)).
* Stata
xtset firm_id year
xtsum roa leverage size growth
reg roa leverage size growth, vce(cluster firm_id)      // pooled OLS
xtreg roa leverage size growth i.year, fe vce(cluster firm_id)
estimates store FE
xtreg roa leverage size growth i.year, re
estimates store RE
xttest0                                                 // Breusch-Pagan LM
hausman FE RE                                           // see the Hausman guide
# R (plm)
library(plm)
p  <- pdata.frame(df, index = c("firm_id", "year"))
fe <- plm(roa ~ leverage + size + growth, data = p, model = "within", effect = "twoways")
re <- plm(roa ~ leverage + size + growth, data = p, model = "random")
phtest(fe, re)                                          # Hausman
lmtest::coeftest(fe, vcov = vcovHC(fe, cluster = "group"))

In EViews, create a panel workfile (dated panel with a cross-section identifier), then in the equation window choose Panel Options and set the cross-section to Fixed or Random. The Hausman test is under View → Fixed/Random Effects Testing → Correlated Random Effects – Hausman Test (after estimating random effects).

How to interpret the results

  • β under fixed effects is a within effect: when a firm's leverage rises by one unit above its own average, its ROA changes by β, holding other variables constant.
  • R² in FE output: report the within R², which is the relevant one for FE.
  • rho (Stata) is the share of error variance due to unit effects. A high rho (e.g. 0.70) confirms that unit heterogeneity matters.
  • Coefficients that change sign between pooled OLS and FE usually mean that unit effects were biasing the pooled estimate. That's an argument for FE, worth one sentence in your discussion.

How to report it

Example: Table 4 reports fixed-effects estimates with year dummies and standard errors clustered at the firm level. The Hausman test rejects the random-effects specification (χ²(6) = 24.31, p < .001). Leverage is negatively associated with ROA (β = −0.084, SE = 0.021, p < .001), consistent with H1.

Include in your table: coefficients, standard errors (in brackets), significance stars, the number of observations and units, within R², whether year effects are included, the type of standard errors, and the Hausman statistic.

Common mistakes

  • Running OLS on panel data without clustering standard errors by unit.
  • Choosing RE because "Hausman says so" without checking that the Hausman assumptions hold (they fail under heteroskedasticity; see Hausman test (FE vs RE)).
  • Adding time-invariant variables to a FE model and wondering why Stata drops them.
  • Including a lagged dependent variable in FE with short T (Nickell bias). Use GMM instead.
  • Ignoring non-stationarity in long macro panels (T > 20–25). Check panel Unit root tests (ADF, KPSS).

Frequently asked questions

How many years do I need for panel data?

Technically two. Practically, FE needs enough within-unit variation in your key variables. With short panels (T ≤ 5), focus on variables that actually change over time, and be careful with dynamic models.

Can I use panel data with only 10 countries?

Yes, but inference is fragile with few clusters. With fewer than about 30–40 clusters, cluster-robust standard errors can be unreliable. Consider wild cluster bootstrap or Driscoll-Kraay errors, and discuss the limitation.

Should I use two-way fixed effects?

Adding year effects (two-way FE) is usually wise when common shocks affect all units. Test their joint significance. If your key variable is a policy adopted at different times by different units, read Difference-in-differences first: staggered two-way FE has known problems.

What's the difference between FE and first differences?

Both remove αᵢ. With T = 2 they are identical. With T > 2, FE is more efficient if errors are serially uncorrelated; first differences is better if errors follow a random walk.