Skip to main content

FEM and REM for panel data

When data tracks multiple units (countries, firms, provinces) over multiple periods, the two most common estimators are FEM (Fixed Effects Model) and REM (Random Effects Model). Both control for unobserved unit-specific characteristics, but they differ in their assumption about the correlation between those characteristics and the explanatory variables.

In EcoLab, FEM/REM belong to the Panel Data group and generate reproducible code for Stata, R and Python. See Estimation & Modeling.


Core difference

  • FEM assumes the unobserved unit-specific effect (αi\alpha_i) may be correlated with the regressors. FEM removes αi\alpha_i through the within transformation (subtracting unit means), so it is consistent even under such correlation — but it cannot estimate time-invariant variables.
  • REM assumes αi\alpha_i is uncorrelated with the regressors and treats it as a random component. REM is more efficient (smaller standard errors) when the assumption holds, and it can estimate time-invariant variables — but it is biased if the assumption is violated.

Which model should you use?

SituationRecommended
You suspect αi\alpha_i correlates with regressors (endogeneity from unit characteristics)FEM
You care about coefficients of time-invariant variables (gender, fixed geography)REM
The sample is a random draw from a large population; αi\alpha_i treated as randomREM
UncertainRun both and use the Hausman test

Model specification

Yit=βXit+αi+uitY_{it} = \beta \, X_{it} + \alpha_i + u_{it}
  • YitY_{it}: dependent variable of unit ii at period tt.
  • XitX_{it}: vector of regressors.
  • αi\alpha_i: unobserved unit-specific characteristic of unit ii.
  • FEM treats αi\alpha_i as a fixed parameter; REM treats αi\alpha_i as a random variable with E[αiXit]=0E[\alpha_i \mid X_{it}] = 0.

The Hausman test

The Hausman test compares the FEM and REM estimates:

  • Null hypothesis H0: REM is consistent (no correlation between αi\alpha_i and XX) → choose REM (more efficient).
  • Reject H0 (small p-value) → REM is biased → choose FEM.

Besides Hausman, also check: heteroskedasticity (Modified Wald), autocorrelation (Wooldridge), and cross-sectional dependence with long panels. When these issues are present, use clustered robust standard errors.


Running in EcoLab

  1. In the Data Collection module, obtain panel data (make sure it has an entity column and a time column).
  2. In the Modeling module, click Add modelPanel Data group → choose Fixed Effects or Random Effects.
  3. Declare the Entity and Time variables, select YY and the XX variables.
  4. Choose the standard-error structure: Robust or Clustered by unit if you suspect issues.
  5. Run both FEM and REM, open the Diagnostics tab to view the Hausman test and decide on the final model.

Input / output example

Input (illustrative): a panel of 63 provinces × 10 years with pci (competitiveness index), fdi (FDI capital), labor (labor force).

Output (format, illustrative figures — not real results):

FEMREM
fdi0.31***0.29***
labor0.12*0.18**
Hausman p-value0.004 → choose FEM

Interpretation: Hausman rejects H0 ⇒ prefer FEM; the partly time-invariant labor variable is less stable under FEM.


Replication code

* ---- FEM / REM with Hausman test ----
use "panel_data.dta", clear
xtset id time

* Fixed Effects (within estimator) with robust SE
xtreg y x1 x2, fe vce(robust)
estimates store fe

* Random Effects
xtreg y x1 x2, re
estimates store re

* Hausman test: FE vs RE
hausman fe re

Limitations and notes

  • FEM cannot estimate time-invariant variables.
  • REM is biased if the no-correlation assumption is violated — always check Hausman.
  • "Time-wide" panels (large T) require attention to cross-sectional dependence and stationarity; consider panel time-series methods.
  • With a lagged dependent variable on the right-hand side or dynamic endogeneity, consider GMM (Arellano–Bond).

Video tutorial

Video Tutorial: Running FEM and REM in EcoLab

See also