The full academy launches January 2027. Join the waitlist for the $179 founding price.
Waldbauer Academy of Economics

Courses › Statistics and Econometrics

Second and third year · Module 14 of 15

Panel data and difference-in-differences

Fixed effects, before–after and treated–control comparisons, parallel trends, event studies and clustered standard errors.

By Maximus S. Waldbauer · About 3 hours, including the problem set and quiz.

When you can’t randomize, the next best thing is often to compare units with themselves. A café that raises its prices can be compared with its own sales before the change; a state that raises its minimum wage can be compared with its own past and with a similar state that didn’t. Panel data, the same units observed repeatedly, make this possible.

This module covers fixed effects regression, which removes every fixed difference between units; time fixed effects for shocks that hit everyone; the difference-in-differences design and its key assumption of parallel trends; event studies that check that assumption; and the clustered standard errors panel data require.

By the end of this module you will be able to

What this module covers

  1. Fixed effects: comparing each unit with itself
  2. Time fixed effects and two-way fixed effects
  3. Difference-in-differences
  4. Event studies and checking parallel trends
  5. Clustered standard errors
  6. Problem set with step-by-step solutions
  7. Module quiz

Lesson 14.1 Free lesson

Fixed effects: comparing each unit with itself

Panel data observe each unit i (a person, firm, café, city or province) in several periods t. Write the regression with a separate intercept for each unit:

Yit = β1Xit + αi + uit

The entity fixed effect αi captures everything about unit i that doesn’t change over time: a café’s location, a person’s innate ability, a province’s geography and history. Any such factor, measured or not, is absorbed. This is a powerful answer to omitted variable bias, as long as the omitted variables are fixed over time.

How it is estimated

Two equivalent methods:

Either way, β₁ is identified only from changes within units over time. That is the Frisch–Waugh idea of Module 8, with the unit dummies as the controls.

The full module has an interactive graph here that you can move yourself.

Worked example: Two cafés, two months

Café A sells 900 lattes at $4.00 in March and 840 at $4.10 in April. Café B (busier, in a better location) sells 1,800 at $5.00 and 1,750 at $5.10.

Across cafés, the higher-priced café sells far more: a pooled regression would find a large positive price slope.

Within each café, a 10-cent rise goes with 60 fewer lattes at A and 50 fewer at B. A fixed-effects regression uses only these within-café changes and finds a negative slope of about −550 lattes per dollar.

What fixed effects can’t do

Common mistake

Thinking fixed effects solve all omitted variable problems. They remove only time-invariant confounders. Ask what else changed for a unit at the same time as X did.

Key ideas

  • Entity fixed effects α_i absorb all time-invariant differences between units, measured or not.
  • Estimate by demeaning each unit’s data or by including unit dummies; the slope is the same.
  • β₁ is identified only from within-unit changes over time.
  • Fixed effects don’t handle time-varying confounders or estimate effects of fixed characteristics.

Practice questions: Panel data and difference-in-differences

Try these, then open each answer to check your work.

  1. 1.Entity fixed effects remove omitted variable bias from factors that:
    1. Are constant over time within each unit
    2. Vary over time but not across units
    3. Are measured with error
    4. Are caused by X
    Show answer

    Answer: A. They absorb all time-invariant differences between units.

  2. 2.The within (demeaning) transformation and including a dummy for every unit:
    1. Give the same slope estimates
    2. Give different slope estimates
    3. Only work with two periods
    4. Remove time effects
    Show answer

    Answer: A. Least squares dummy variables and demeaning are numerically identical for the slope.

  3. 3.Time fixed effects absorb:
    1. Differences between units that never change
    2. Measurement error
    3. Shocks common to all units in a given period
    4. Spillovers
    Show answer

    Answer: C. One dummy per period captures anything that hits everyone at once.

Problems with step-by-step solutions

  1. 4.A panel of 200 workers observed for 5 years. Name two factors the worker fixed effects absorb and one they don’t.
    Show step-by-step solution
    1. Absorbed: innate ability, family background (anything fixed over the five years), and also fixed education if it doesn’t change.
    2. Not absorbed: a health shock in year 3, a new manager, or a move to a different city (time-varying factors).
  2. 5.Café data (price, lattes sold): Café A: ($4.00, 900), ($4.20, 860); Café B: ($5.00, 1,800), ($5.20, 1,740). Compute the within-café slope for each café and their average.
    Show step-by-step solution
    1. Café A: (860 − 900)/(4.20 − 4.00) = −40/0.20 = −200 lattes per dollar.
    2. Café B: (1,740 − 1,800)/0.20 = −300.
    3. Average within slope: −250 lattes per dollar (with equal-sized price changes, fixed effects gives this average).

Get the full module

The complete module adds every lesson, interactive graphs, a full problem set with step-by-step solutions, and a quiz. The academy opens in January 2027: join the waitlist for the founding price (lifetime access for $179).

Join the waitlist Try a full module free

More practice: free practice questions for this course.