Skip to content
Panel Dataadvanced

Fixed Effects (the Within Estimator)

A panel model is yit=xitβ+ai+uity_{it} = x_{it}'\beta + a_i + u_{it}, where aia_i is a fixed, unobserved trait of entity ii (a firm, a person, a country). Fixed effects applies the within transformation: it subtracts each variable's entity mean over time, (yityˉi)=(xitxˉi)β+(uituˉi)(y_{it}-\bar{y}_i) = (x_{it}-\bar{x}_i)'\beta + (u_{it}-\bar{u}_i), which wipes out the time-invariant aia_i entirely. So FE stays consistent even when Cov(ai,xit)0\text{Cov}(a_i, x_{it}) \neq 0, the exact case that breaks pooled OLS, as long as strict exogeneity of uitu_{it} holds. The cost: because demeaning removes anything constant over time, FE cannot estimate the coefficient on any time-invariant regressor (gender, industry, a firm's founding decade). In Stata: `xtset id year` then `xtreg y x, fe`.

Watch the lesson

Modelling· 5:25· ECON3006

Fixed Effects, giving every firm its own line

Open full lesson page →

Why it matters

Picture one fitted line drawn through three different firms. A pooled fit ignores who each firm is and lets persistent firm traits leak into the slope. Fixed effects instead gives each entity its own intercept, so identification comes only from how a firm moves relative to its own average over time, not from comparing one firm to another. That within-firm focus is exactly what neutralises stable confounders such as management quality or culture. But it cuts both ways. Anything that never changes for a firm has no within variation left to explain yy, so its effect simply cannot be recovered. Add time effects λt\lambda_t for shocks common to all entities in a year, giving two-way FE.

Formulas

Within (demeaned) equation
(yityˉi)=(xitxˉi)β+(uituˉi)(y_{it}-\bar{y}_i) = (x_{it}-\bar{x}_i)'\beta + (u_{it}-\bar{u}_i)
Subtracting the entity mean yˉi=1Ttyit\bar{y}_i = \tfrac{1}{T}\sum_t y_{it} cancels aia_i because aia_i is constant over tt. OLS on these demeaned data is the within estimator. With T=2T=2 it is identical to first differencing the data.
Two-way fixed effects
yit=xitβ+ai+λt+uity_{it} = x_{it}'\beta + a_i + \lambda_t + u_{it}
Adding λt\lambda_t absorbs shocks common to every entity in period tt (a recession, a tax change). In Stata: `xtreg y x i.year, fe vce(cluster id)`.

Worked examples

Scenario

Estimate how leverage and firm size relate to return on assets, controlling for all stable firm differences.

Solution

Declare the panel with `xtset id year`, then run `xtreg roa lev size, fe vce(cluster id)`. The slopes on `lev` and `size` are now identified purely from within-firm changes over time, so any time-invariant trait (industry, headquarters country, founder) is differenced away rather than biasing the estimates. The `vce(cluster id)` option makes the standard errors robust to serial correlation within each firm.

NoteCompare against `reg roa lev size` (pooled OLS): if the coefficients move a lot, fixed firm traits were correlated with the regressors.
Scenario

Try to include a time-invariant industry dummy in the fixed effects model.

Solution

Running `xtreg roa lev size i.industry, fe` makes Stata silently omit the industry dummies and report them as dropped, because `industry` never changes within a firm and so has zero within variation. The within transformation has already removed everything constant over time, industry included. To learn the effect of a stable trait you must use a different estimator such as random effects (`xtreg ..., re`) or report group means separately.

NoteThis is a feature, not a bug: the same demeaning that controls for unobserved fixed traits also blocks estimation of observed fixed traits.

Common mistakes

  • Believing fixed effects can estimate the coefficient on a time-invariant regressor. It cannot. The within transformation removes everything constant over time, so gender, industry, or founding year are swept out along with aia_i and reported as omitted.
  • Thinking fixed effects fixes every kind of endogeneity. It only removes bias from the time-invariant aia_i. Strict exogeneity of uitu_{it} is still required, so simultaneity, measurement error, or a time-varying omitted variable will still bias the estimates.
  • Assuming pooled OLS and fixed effects should give similar slopes. They diverge precisely when Cov(ai,xit)0\text{Cov}(a_i, x_{it}) \neq 0, which is the usual reason to prefer FE. A large gap is informative, not a red flag.
  • Forgetting to cluster standard errors. Default `xtreg, fe` errors assume no serial correlation, which is rarely true in panels. Use `vce(cluster id)` so inference is valid when a firm's shocks persist across years.

Revision bullets

  • FE applies the within transformation: demean each variable by its entity mean to cancel aia_i.
  • Consistent even when Cov(ai,xit)0\text{Cov}(a_i, x_{it}) \neq 0, as long as uitu_{it} is strictly exogenous.
  • It cannot estimate coefficients on time-invariant regressors, they have no within variation.
  • Two-way FE adds λt\lambda_t for common time shocks via `xtreg y x i.year, fe`.
  • With T=2T=2, fixed effects and first differencing give identical estimates.
  • Always pair with clustered SEs: `xtset id year` then `xtreg y x, fe vce(cluster id)`.

Quick check

Why is the fixed effects (within) estimator consistent when the unobserved effect aia_i is correlated with the regressors?

You run `xtreg wage educ tenure i.gender, fe` on worker-year panel data. What happens to the `gender` coefficient?

Connected topics

Sources

  1. Wooldridge (2019), §14.1
    Wooldridge, Jeffrey M. Introductory Econometrics: A Modern Approach. 7th ed. Cengage, 2019.
    Develops the unobserved effects model, the within transformation, and why fixed effects allows arbitrary correlation between aia_i and the regressors under strict exogeneity.
  2. Wooldridge (2019), §14.2
    Wooldridge, Jeffrey M. Introductory Econometrics: A Modern Approach. 7th ed. Cengage, 2019.
    Covers the inability of fixed effects to identify time-invariant regressors, the dummy variable regression equivalence, and two-way fixed effects with time dummies.
How to cite this page
Dr. Phil's Quant Lab. (2026). Fixed Effects (the Within Estimator). Derivatives Atlas. https://phucnguyenvan.com/concept/efm-fixed-effects
Next concept
Pooled OLS on Panel Data
Share this page
Built by Dr. Phuc V. Nguyen ·Follow on LinkedInWork with PhilEmail