Skip to content
We use only essential cookies to keep you signed in and remember your preferences. See our Cookie Policy.
TestStop
MocksPracticeResourcesIndiaBlogPricing
Sign in
Resources › Econometrics › 13. Panel data
Econometrics · Lesson 13 of 18

Panel data: fixed and random effects

Follow the same individuals (people, firms, countries) over several periods and you can do something a single cross-section never can: compare each individual with itself. That strips out everything about the individual that does not change, including the things nobody measured. This lesson covers the kinds of data, why pooling the observations can mislead, the fixed-effects estimators (within, first-difference, dummy variables), random effects, and the Hausman test that chooses between them, with a lab where the truth is known and real data on twelve economies.

← Econometrics moduleLesson 13 of 18 · about 50 minutes
1Multiple regression2Matrix form and Gauss-Markov3t and F tests4R² and adjusted R²5Dummies and interactions6Functional forms7Misspecification8Multicollinearity9Heteroscedasticity10Autocorrelation11Instrumental variables12Simultaneous equations13Panel data14Logit and probit15Unit roots16ARMA, VAR and cointegration17Test Atlas18Hard problems
A question to hold on to
Consider a simple pooled regression model yit = β₀ + β₁xit + vit, where vit = μi + εit and Cov(xit, μi) ≠ 0. Here μi captures the unknown individual-specific effects and εit is the idiosyncratic error, uncorrelated with both xit and μi. If the parameters of this model are estimated by OLS, the estimated slope coefficient will be: (A) biased; (B) inconsistent; (C) unbiased but consistent; (D) unbiased but efficient.
GATE Economics (XH-C1) 2024Solved at the end ↓
New here?What is the Ashanagar survey?The invented household survey behind this page's examples: 600 households, generated from a model whose true coefficients we publish.

The Ashanagar survey is invented. The statistics modules used one district of 60 households. Econometrics needs more households and more variables, so this is a new, larger survey of 600 households in the same imaginary district: income, spending, household size, whether the household is in the town or a village, the head’s schooling and earnings.

Because we wrote the data-generating process, we know the true answers, and every lab can show whether a regression recovers them. Household spending, in thousands of rupees a month, was generated as 1 + 0.45 × income + 0.9 × household size + 1.5 × town + an error with standard deviation 2.5. A real survey never tells you its true coefficients. This one does, so you can see how close an estimate comes.

It also holds a variable, the head’s ability, that a real survey could not observe. It is kept so that the lessons on omitted variables can show what happens when it is left out. Every figure here is illustrative, not official statistics.

Households
600
Share in the town
41%
Mean monthly income
₹15.4 thousand
Mean monthly spending
₹12.6 thousand
Mean schooling of the head
8.2 years

How the module uses it →

In this guide
Lesson · about 50 minutes
  1. Kinds of data
  2. Why pooled OLS can fail
  3. Fixed effects: within, first differences, LSDV
  4. Random effects and the Hausman test
  5. Real data: twelve economies
  6. The opening question, solved
  7. The lesson on one screen
  8. Check yourself
  9. Past papers, by level
01
Vocabulary

Kinds of data

KindWhat it isExample
Cross-sectionMany individuals at one point in timeA household survey in one year, the 186 economies in 2019
Time seriesOne individual over many periodsIndia’s GDP, 1960 to 2025
Pooled cross-sectionsSeveral cross-sections, each a fresh sample of different individualsA household survey repeated every year with new households
Panel (longitudinal)The same individuals followed over time12 economies, each observed in each of 20 years

Data collected at a point in time are cross-sectional (CUET asks it directly), and one state over many years is a time series. A panel is balanced if every individual is observed in every period, unbalanced otherwise. With N individuals and T periods the sample has n = NT observations. A short panel has many individuals and few periods (typical of surveys), a long panel few individuals and many periods (typical of country data).

02
Interactive

Why pooled OLS can fail

The simplest approach stacks all the observations and runs OLS, ignoring that they come in groups. That is the pooled regression, yit = β₀ + β₁xit + vit. But every observation of individual i shares an individual effect μi: something about that person, firm or country that persists, such as ability, management quality or institutions. It sits in the error: vit = μi + εit. If μi is related to x, we have an omitted variable that is correlated with the regressor, and the bias of lesson 7 returns:

Pooled OLS with an individual effect
plimbpooled​=β+Var(xit​)Cov(xit​,μi​)​
If Cov(x, μ) = 0 the pooled estimator is fine (but its standard errors need adjusting for the repeated individuals). If not, it is biased and inconsistent, whether T is large or N is.

In the lab each individual in colour has its own level (μ), and individuals with a high level also have a high x. Looking across individuals, the pattern is steep; looking within one individual, the slope is the true 1. The dashed pooled line is much steeper than any individual’s own line. Press “draw new samples” and raise c to see the pooled and between estimators drift away from 1 while the within and first-difference estimators stay put.

True model: yit = 1 × xit + μi + eit, with an individual effect μi and xit = c μi + noise. The slope we want is 1. The plot shows 8 individuals, each in its own colour.

EstimatorAverage slopeSpread
Pooled OLS1.4650.109
Between1.953n/a
Fixed effects (within)0.9970.093
First differences0.9990.111
Random effects1.2970.118
Pooled OLS converges to1.488
Hausman test rejects random effects100%
−1−0.50.511.522.533.5−2246xy

Horizontal: x. Vertical: y. Each colour is one individual; its short line has the within slope (0.86), and the dashed black line is the pooled OLS fit (1.41).

What it shows

Individuals with a high effect also have a high x, so the pooled line is steeper than each individual's own: it converges to 1.49, not 1 (average 1.47), and the between estimator, which uses only differences across individuals, is worse (1.95). The within and first-difference estimators remove μ by comparing each individual with itself, and are centred on the truth (1 and 1). Random effects assumes μ is unrelated to x, so it is biased too (1.3). The Hausman test, which compares fixed and random effects, rejects random effects in 100% of samples.

03
The remedy

Fixed effects: within, first differences, LSDV

If μi is constant over time, differences within an individual cannot contain it. Three equivalent ways to use that:

  • The within (fixed-effects) estimator. Subtract each individual’s average from each variable and run OLS on the demeaned data. μi disappears.
  • First differences. Subtract the previous period: Δyit = βΔxit + Δεit. μi disappears. With T = 2 it is identical to the within estimator; with T > 2 they differ (in efficiency, and in how they treat serial correlation in ε).
  • Least squares with dummy variables (LSDV). Add a dummy for each individual (N − 1 of them, with a constant). The slope is identical to the within estimator’s, and the dummies’ coefficients estimate the individual effects.
Derive it

Why subtracting each individual's mean removes the individual effect

We want to show
In yit = βxit + μi + εit, regressing yit − ȳi on xit − x̄i gives an estimate of β that does not depend on whether μi is related to x, because μi drops out.
  1. 1
    Average the equation over time for individual i.
    yˉ​i​=βxˉi​+μi​+εˉi​

    μi is the same in every period, so it equals its own average.

  2. 2
    Subtract it from the original.
    yit​−yˉ​i​=β(xit​−xˉi​)+(εit​−εˉi​)

    The individual effect is gone, whatever its relation to x. The new error εit − ε̄i is unrelated to the demeaned x if x is strictly exogenous with respect to ε, so OLS on the demeaned data is consistent.

  3. 3
    The price: degrees of freedom and time-invariant variables.

    The N means were estimated, so the residual degrees of freedom are n − N − k, not n − k. And any variable that does not change over time (sex, country of birth) has x − x̄i = 0, so its coefficient cannot be estimated: the within estimator is silent about it.

  4. 4
    It is the same as a dummy for every individual.

    Regress y on x and on N − 1 individual dummies (least squares with dummy variables, LSDV) and the slope on x is identical to the within estimator’s. For 12 economies over 20 years of World Bank data (life expectancy on ln GDP per head), the within slope is 8.129 and the LSDV slope is 8.129. The pooled slope, which ignores the economy effects, is 6.3678. The within regression has 227 degrees of freedom: 240 − 12 − 1.

Step 1 of 4
So
Fixed effects asks “when this economy’s GDP rose, what happened to its life expectancy?”, using only variation inside each economy. Pooled OLS also uses the differences between economies, which are mixed up with everything else that distinguishes them.

What fixed effects costs: degrees of freedom (n − N − k), and the ability to estimate the effect of any variable that does not change within an individual: sex, birthplace, a country’s geography. Those are absorbed by the individual effect. The within estimator answers “what happens when x changes for the same individual?” and is silent on differences between individuals.

Watch out for

The mistakes examiners are fishing for

  • Saying fixed effects makes OLS unbiased in every case. It removes anything constant over time. A shock that varies over time and is correlated with x (a policy changing in response to the outcome) still biases it.
  • Counting degrees of freedom as n − k. With N individual means estimated, they are n − N − k.
04
The alternative

Random effects and the Hausman test

The random-effects (RE) model treats μi as a random draw, assumed uncorrelated with x. The composite error vit = μi + εit is then correlated within an individual (the same μi in each period), so OLS is unbiased but inefficient, and GLS fixes that. GLS is computed as OLS on quasi-demeaned data: subtract a fraction θ of the individual mean,

Random-effects quasi-demeaning
yit​−θyˉ​i​=β(xit​−θxˉi​)+error,θ=1−σε2​+Tσμ2​σε2​​​
θ = 0 gives pooled OLS and θ = 1 gives the within estimator. θ rises with T and with the share of variance that is individual-specific.

RE is more efficient than FE when its assumption holds, because it also uses the variation between individuals, and it can estimate the effect of time-invariant variables. But if μi is correlated with x, RE is biased (the lab shows it), while FE is not. Which to use? The Hausman test compares the two:

  • H₀: μi is uncorrelated with x. Both FE and RE are consistent, and RE is efficient.
  • H₁: μi is correlated with x. Only FE is consistent.
  • Statistic: H = (bFE − bRE)′ [Var(bFE) − Var(bRE)]⁻¹ (bFE − bRE), chi-square with k degrees of freedom (the number of slope coefficients compared). A significant H rejects RE: use fixed effects.

A model written yit = β₀ + β₁xit + εi + uit with a person-specific error εi and an idiosyncratic error uit is the random-effects form (the individual term is a part of the error, not a set of coefficients).

Pause and predict
The Hausman test rejects its null. Which estimator should be used?
05
Real data

Real data: twelve economies

World Bank, World Development Indicators: life expectancy and GDP per head for 12 economies (India, China, the United States, Japan, Korea, Brazil, Nigeria, Germany, Indonesia, Bangladesh, Ethiopia and the United Kingdom), 2000 to 2019: a balanced panel of 240 observations. Regress life expectancy on the log of GDP per head:

EstimatorSlope on ln GDPStandard error
Pooled OLS6.3680.306
Between (economy averages)6.2951.491
Fixed effects (within)8.1290.294
First differences3.0970.597
Random effects8.060.289

The estimated individual effects range from −21.6 (Nigeria) to 1 (China) years: economies differ a great deal in life expectancy at the same income, which is what pooling ignores. The within estimate is 8.13, the pooled 6.37. The Hausman test comparing fixed and random effects gives H = 1.45 with 1 degree of freedom (p = 0.23), so it does not reject random effects here; the two estimates (8.13 and 8.06) are close, and the random-effects weight θ = 0.96 is near 1, so RE here behaves almost like FE.

The first-difference slope (3.1) is well below the within slope. They answer slightly different questions: the within estimator uses all the variation over twenty years, including long slow trends in both GDP and life expectancy, whereas first differences use only year-to-year changes, which are small and noisy; one standard reason for such a gap is that differencing amplifies measurement error. These are real data, and no estimator here proves that GDP causes longer lives: fixed effects removes what is constant about an economy, not what changes with GDP and also lengthens life.

In economics

A pitfall specific to this example: the economies are not a random sample of the world (they are twelve of the largest or best known), so the random-effects assumption that the effects are draws from one population is hard to defend, and a fixed-effects reading is more natural. With only twelve individuals the Hausman test may have little power, so failing to reject is weak evidence.

What to say in an exam

With an individual effect correlated with a regressor, pooled OLS is biased and inconsistent. Fixed effects (within, first differences or LSDV) removes it by comparing each individual with itself, at the price of time-invariant regressors and degrees of freedom. Random effects is more efficient but needs the effect to be uncorrelated with the regressors. The Hausman test chooses: rejection means use fixed effects.

06
Solving the opening question

The opening question, solved

GATE Economics (XH-C1) 2024 · hard
yit = β₀ + β₁xit + μi + εit with Cov(x, μ) ≠ 0 is estimated by pooled OLS. The slope is?
  1. 1
    Locate μ.
    In the pooled regression the individual effect is part of the error: vit = μi + εit.
  2. 2
    Is the error correlated with x?
    Cov(x, v) = Cov(x, μ) + Cov(x, ε) = Cov(x, μ) + 0 ≠ 0. The regressor is endogenous.
  3. 3
    Conclude.
    OLS converges to β₁ + Cov(x, μ) ÷ Var(x), not β₁: it is biased and inconsistent. It is not unbiased (C and D are false), and it makes no sense to call it efficient.
Answer
(A) and (B): biased and inconsistent. The exam’s official answer marks both.
07
Revise

The lesson on one screen

The lesson on one screen
Kinds of data
Cross-section (one time), time series (one individual), pooled cross-sections (new individuals each time), panel (same individuals over time). Balanced: every individual in every period.
Pooled OLS
Fine if the individual effect is unrelated to x. Otherwise β + Cov(x, μ) ÷ Var(x): biased and inconsistent.
Within (FE)
Subtract individual means. Removes μ. Degrees of freedom n − N − k. Cannot estimate time-invariant variables.
First differences
Δy on Δx. Removes μ. Same as within when T = 2.
LSDV
A dummy per individual. Slope identical to within.
Random effects
μ random and uncorrelated with x. GLS by quasi-demeaning with θ. More efficient than FE if the assumption holds, biased if not.
Hausman test
Compares FE and RE. H₀: effect uncorrelated with x. Reject: use FE. Chi-square with k df.
Remember
FE removes what is constant over time, not time-varying omitted variables.
08
Practice

Check yourself

0 of 13 correct so far

Compute

The within transformation
An individual’s values of x over three periods are 3, 5 and 7. Find the demeaned value of x in the third period.
Degrees of freedom of fixed effects
A balanced panel has N = 50 individuals, T = 10 periods and k = 3 regressors. Find the residual degrees of freedom of the within estimator.
LSDV dummies
An LSDV regression with a constant has 12 individuals. How many individual dummies does it include?
The random-effects weight
σ²ε = 1, σ²μ = 0.5 and T = 4. Find θ for the quasi-demeaning.
First differences with two periods
For one individual, y rises by 6 and x by 2 from period 1 to period 2 (the first-difference regression has no constant here). Find the implied slope.
What pooled OLS converges to
β = 1, Var(x) = 2 and Cov(x, μ) = 0.8. To what does the pooled OLS slope converge?
The Hausman statistic with one coefficient
bFE = 0.8, bRE = 0.5, and Var(bFE) − Var(bRE) = 0.04. Find the Hausman statistic. (The 5% chi-square critical value for 1 df is 3.84.)
The size of a panel
A balanced panel follows 30 individuals for 5 periods. How many observations does it have?

Quick questions

1Data on the same households followed over ten years are
2The within estimator cannot estimate the effect of
3Random effects is preferred to fixed effects when
4The least squares dummy variable estimator of the slope equals
5A significant Hausman statistic implies
09
Real questions

Past papers, by level

Foundation

Definitions and one-step calculations: a t statistic, an R², which assumption is which. Most CUET and JNU questions sit here.

1 questionPractise →

Standard

Restricted against unrestricted regressions, reading output, and statement questions, up to GATE and IIT JAM level.

1 questionPractise →
All 2 past-paper questions for this lesson, easiest first: practise the full set →

✦These are questions from the TestStop bank. A free account answers 10 a day, each with its worked solution; All-Access opens every set with no daily limit.

This lesson’s set is short: few papers ask about panels, and two further questions (on the form of a random-effects model, and on panel data for states) are waiting for a person to sign off their keys. The instrumental-variables alternative to fixed effects is in lesson 11.

← Lesson 12Simultaneous equations and identificationLesson 14 →The linear probability model, logit and probit

Read next

All resources →
EconometricsEconometrics 14: the linear probability model, logit and probitWhy a line fails for a 0/1 outcome, the logit and probit as S-curves, odds and log-odds, maximum likelihood and the likelihood-ratio test, pseudo and count R squared, and marginal effects, with a lab on a household survey with a known truth.Complete guide · 50 minEconometricsEconometrics 11: endogeneity, instrumental variables and two-stage least squaresWhy a regressor correlated with the error breaks OLS, what makes an instrument valid, the IV and Wald estimators derived, two-stage least squares, weak instruments and the Hausman and Sargan tests, with a lab that shows OLS, IV and a weak instrument against a known truth.Complete guide · 55 minEconometricsEconometrics 5: dummy variables, the dummy trap and interaction termsA dummy shifts the intercept and an interaction shifts the slope, a regression on a dummy returns the group averages, m categories and the dummy-variable trap as perfect collinearity, changing the base group, recoding 0 and 1 as minus one and plus one, and a kinked line, with two labs.Complete guide · 55 min