Back to the on-screen lesson ·

Panel data and fixed effects

Compare each unit with itself: first differences and within transformations remove every time-constant confounder, but not what changes over time.

Paper packet. Every task here also exists on screen, where it is checked automatically; answers written on paper are not assessed by Nydus. When you are back at a device, enter your answers there.

1. What you will learn

By the end of this lesson you will be able to compute first differences and within values, estimate a first-difference slope, and say what fixed effects do and do not remove.

2. What you already have

From the omitted-variable lesson you know that anything left out of a regression that moves with the regressor biases its slope. From the experiments lesson you know that randomization removes that bias for every omitted variable at once.

Panel data — the same states, firms or people observed in several periods — offer a partial version of the same protection without an experiment. By comparing each unit with itself, a regression removes everything about the unit that does not change over time. This lesson shows how, and what it leaves behind.

3. Terms to use precisely

TermWhat it means
Panel dataObservations on the same units in two or more periods.
Unobserved effect$a_i$: a unit's characteristics that are constant over time, measured or not.
First differenceA unit's value in one period minus its value in the previous period.
Within transformationSubtracting each unit's own time average from its observations.
Fixed effects estimatorOLS on within-transformed data, or equivalently with a dummy for each unit.
Time fixed effectsDummies for each period, removing shocks common to all units in that period.
Idiosyncratic error$u_{it}$: the part of the error that varies across both units and time.

4. Compare each unit with itself

Write the panel model as

$$y_{it} = \beta x_{it} + a_i + u_{it},$$

where $a_i$ collects everything about unit $i$ that does not change over time — a state's geography and culture, a worker's ability, a firm's management style. If $a_i$ is correlated with $x_{it}$, OLS on the pooled data is biased, just as with any omitted variable.

First differencing removes $a_i$ by subtracting last period's equation from this period's:

$$\Delta y_{it} = \beta \Delta x_{it} + \Delta u_{it}.$$

The unobserved effect cancels because it is the same in both periods. The within or fixed effects estimator does the same with more periods: subtract each unit's own time average from every variable, then run OLS. Both use only variation within units over time, and both remove every time-constant confounder, measured or not.

Adding time fixed effects — a dummy for each year — also removes shocks common to all units in a year, such as a national recession.

Another way: action

Picture two lines per state: its beer tax and its traffic deaths over twenty years. Fixed effects ignore the heights of the lines — which states are high on average — and ask only whether each state's deaths fell when its own tax rose.

Another way: steps

  1. Write the model with an unobserved effect $a_i$.
  2. Difference or demean every variable within each unit.
  3. Regress the transformed $y$ on the transformed $x$.
  4. Add time effects for shocks common to all units.
  5. Ask what changes over time with $x$ that could still bias the slope.

5. Why the unobserved effect cancels

The unobserved effect $a_i$ has no time subscript: it is the same number in every period for a given unit. Subtracting any two periods, or subtracting the unit's average, removes it exactly. So whatever it contains — measured or not, correlated with $x$ or not — cannot bias the slope.

That is a remarkable guarantee, and its strength is also its limit. It covers only what is truly constant. A state's attitudes toward drinking may drift over twenty years; a worker's ability may be revealed gradually to employers. The more the supposedly fixed traits change, the less the fixed effects protect. A useful habit is to ask, for each trait the fixed effects are credited with removing, whether it could plausibly have changed during the years in the sample. Geography could not; a state's political leanings, its age structure or its enforcement budget might well have. The traits that could change are exactly the ones a careful study goes on to measure and control for, or to test by showing the results hold in shorter windows where change is less likely. That kind of reasoning turns a fixed-effects table from a black box into an argument a reader can check.

6. What fixed effects cost

Differencing removes the time-constant confounders, but it also removes the time-constant part of the regressor. Only the changes in $x$ within units remain, and they are usually a small share of its total variation. Standard errors rise, sometimes a lot.

Measurement error, from the earlier lesson, also becomes worse: the true changes in $x$ are small, while each period's reporting error is as large as ever, so differenced data are noisier and the slope is more attenuated.

And fixed effects cannot estimate the effect of anything that never changes within a unit. A worker's gender or a state's latitude is absorbed into $a_i$ along with everything else constant, so its coefficient cannot be recovered. Panel standard errors should also be clustered by unit, because each unit's errors are correlated across its own periods.

7. Pooled, first-difference and fixed-effects estimates

With exactly two periods, first differences and fixed effects give the same slope. With more periods they differ slightly, depending on how the errors are correlated over time; fixed effects is the more common default.

The pooled estimate, which ignores the panel structure, compares different units as well as the same unit at different times. When the pooled and fixed-effects estimates differ sharply, the difference is informative: it tells you that time-constant traits were correlated with the regressor. The beer-tax data below show a striking example, where the sign of the effect reverses. Whenever you see a panel study, look for both estimates side by side. If the authors report only the fixed-effects number, ask what the pooled one was and why they preferred the other; the gap between them is the size of the confounding they removed, and it tells you how much work the design is doing. A small gap suggests the fixed traits did not matter much; a large gap, or a change of sign, says the pooled comparison was badly misleading.

8. What fixed effects do not fix

Fixed effects handle $a_i$; they do nothing about $u_{it}$. If something that changes over time moves with the regressor and affects the outcome, the slope is still biased. A state that raises its beer tax in the same year it passes a tough drunk-driving law will show a fall in deaths that the fixed-effects regression credits partly to the tax.

Reverse causation is also untouched: if states raise alcohol taxes after a spike in traffic deaths, the within-state change in tax responds to the outcome. And feedback from past outcomes to current regressors — last year's sales shaping this year's advertising — creates its own bias. Controlling for time-varying confounders, adding time effects, and combining fixed effects with the designs of the next two lessons are the usual responses.

9. Fixed effects as dummy variables

There is a second way to see the fixed-effects estimator, which connects it to the dummy-variable lesson. Include a dummy for every unit — every state, firm or person — and run OLS. Each dummy gives its unit its own intercept, which soaks up that unit's $a_i$. The slope on $x$ is then estimated only from how $x$ and $y$ move together within units, and it is numerically identical to the slope from demeaning.

With fifty states that means fifty dummies, and with a million workers a million, which is why software demeans instead. But the dummy view makes two points clear. First, fixed effects are just controls — a very large set of them, chosen to absorb every constant difference between units. Second, the degrees of freedom used up are real: each unit's intercept costs one, so the error variance is estimated with $n T - n - k$ degrees of freedom rather than $n T - k - 1$.

Time fixed effects work the same way with a dummy for each period. Two-way fixed effects, with both sets, compare each unit's change with the average change of all units in the same period. The next lesson shows that with two groups and two periods this is exactly a difference-in-differences comparison.

10. Working a first-difference estimate, step by step

Three states change their beer tax by $2$, $-1$ and $1$ dollars per case; their traffic death rates change by $-4.5$, $1.5$ and $-1.5$.

  1. Products. $2(-4.5) + (-1)(1.5) + 1(-1.5) = -9 - 1.5 - 1.5 = -12$.
  2. Squares. $4 + 1 + 1 = 6$.
  3. Slope. $-12/6 = -2$ deaths per 10,000 per dollar.
  4. Interpret. Within states, higher beer taxes go with fewer deaths.
  5. Check the threats. Were drunk-driving laws or economic conditions changing at the same times as the taxes?

11. How to check a panel answer

Three checks.

  1. Is every difference within the same unit? Differencing across units does not remove $a_i$.
  2. Do the demeaned values sum to zero within each unit? They must.
  3. Does the slope's sign make sense relative to the pooled one? A reversal means time-constant confounding was strong, which is worth reporting.

Then list the time-varying factors that moved with the regressor, and say whether the design can rule them out.

12. In the world: beer taxes and traffic deaths

A classic dataset covers the 48 contiguous US states from 1982 to 1988, recording each state's real beer tax and its traffic fatality rate. A pooled regression of deaths per 10,000 people on the beer tax gives a positive slope of about $0.36$: states with higher beer taxes have more traffic deaths.

That makes no sense as a causal effect, and fixed effects explain why. States differ in many fixed ways — rural road networks, long driving distances, attitudes toward drinking — and some of the states with the deadliest roads also happen to tax beer more heavily. With state fixed effects the slope becomes about $-0.66$: within a state, a one-dollar rise in the real beer tax goes with about $0.66$ fewer deaths per 10,000 people, a large effect relative to the average rate of about $2$.

Adding year fixed effects barely changes the estimate. But the design cannot rule out time-varying confounders: states that raised beer taxes may also have tightened drunk-driving laws or raised the drinking age in the same years. Studies that add those laws as controls find a smaller, less precise effect, which is exactly the caution this lesson recommends. The fixed effects fixed one problem, not all of them.

13. Fixed effects are not a cure-all

The most common mistake is to think fixed effects make a slope causal. They remove only what is constant within units; anything that changes over time along with the regressor still biases it.

A second mistake is expecting fixed effects to estimate the effect of a characteristic that never changes, such as a person's gender. It is absorbed with everything else constant.

A third is ignoring the loss of precision. Within variation is often small, so standard errors grow, and measurement error bites harder.

14. A within value

  1. List the firm's values.

    $38, \ 45, \ 52$

    Three years of sales.

  2. Average the three years.

    $(38 + 45 + 52) \div 3 = 45$

    The firm's own mean.

  3. Subtract from year one.

    $38 - 45 = -7$

    Below its own average.

  4. Subtract from year three.

    $52 - 45 = 7$

    Above its own average.

  5. Check the sum.

    $-7 + 0 + 7 = 0$

    Deviations cancel.

15. A two-period first difference

  1. Write the model in both years.

    $y_{i2} = \beta x_{i2} + a_i + u_{i2}$

    And the same for year 1.

  2. Subtract year 1 from year 2.

    $\Delta y_i = \beta \Delta x_i + \Delta u_i$

    The fixed effect cancels.

  3. Read one county's changes.

    $\Delta x = 3, \ \Delta y = -6$

    Wage up, employment down.

  4. Compute its ratio.

    $-6 \div 3 = -2$

    One county's implied slope.

  5. Combine many counties.

    $\sum \Delta x \Delta y \div \sum \Delta x^2$

    The FD regression.

  6. State the assumption.

    $\Delta u \perp \Delta x$

    Nothing time-varying moves with $x$.

16. A slope that reverses sign

  1. Run the pooled regression.

    $\hat\beta_{pooled} > 0$

    Higher tax, more deaths?

  2. Suspect a fixed trait.

    $a_i = \text{rural roads, driving culture}$

    Differs by state.

  3. Link it to the tax.

    $\text{rural states tax beer more}$

    Correlated with $x$.

  4. Link it to deaths.

    $\text{rural roads are deadlier}$

    Affects $y$.

  5. Remove it with fixed effects.

    $y_{it} - \bar y_i \text{ on } x_{it} - \bar x_i$

    Within states.

  6. Read the new slope.

    $\hat\beta_{FE} < 0$

    Higher tax, fewer deaths.

  7. Draw the lesson.

    $\text{fixed confounders flipped the sign}$

    Pooled data compared the wrong states.

17. Your turn: changes in x are 3, 2 and −1; changes in y are 4, 3.5 and −2.

  1. Multiply the paired changes.

    $12 + 7 + 2 = 21$

    Sum of products.

  2. Square the x changes.

    $9 + 4 + 1 = 14$

    Sum of squares.

  3. Your turn: work this step out. Its working is at the end of the packet.

    Divide the sums.

18. Guided practice

A firm's sales over three years are $27$, $32$ and $37$. What is its within (demeaned) value for the third year?

Answer: within value

19. Guided practice

Complete the worked solution: a city's police force rises from $4$ to $5$ hundred officers while its crime index moves from $17$ to $15$. Find the change in police, the change in crime, and their ratio.

  1. Difference the police force.

    $5 - 4 =$ a

    Change within the city.

  2. Difference the crime index.

    $15 - 17 =$ b

    Crime fell.

  3. Divide crime's change by police's.

    $\Delta crime \div \Delta police =$ c

    A within-city slope, free of fixed city traits.

20. Guided practice

A county's minimum wage goes from $32$ to $39$ (tens of cents), and its teen employment rate goes from $30$ to $26$ percent. Fill in the first differences of the wage and of employment.

Change in wage: dx. Change in employment: dy.

21. Practice

A worker's weekly hours over three years are $30$, $36$ and $39$. Fill in the within (demeaned) value for each year.

within value
year 1
year 2
year 3

22. Practice

A state-year panel regresses traffic deaths on the beer tax with state fixed effects. Match each omitted factor to whether the fixed effects handle it.

removed by state fixed effectsnot removed; can still bias the slope
long-standing attitudes toward drinking in the state
a tougher drunk-driving law passed the same year as a tax rise
how rural the state's road network is
a recession that cuts both driving and tax revenue

23. Practice

Three states change their beer tax between two years by $3, 2, -1$ dollars per case, and their traffic death rates change by $4, 3.5, -2$ deaths per 10,000 people, in the same order. Regressing the change in deaths on the change in tax without an intercept, what is the first-difference slope?

Answer: deaths per 10,000 per dollar

24. Somewhere new

A public-health agency studies three counties' cigarette taxes (dollars per pack) and adult smoking rates (percent) between two surveys. The tax changes are $3, -1, 2$ and the smoking-rate changes are $-3.5, 0.5, -1.5$, in the same county order. What is the first-difference slope through the origin?

Answer: points per dollar

25. Lesson test

Lesson test: one question per skill, one attempt each, no hints. Your answers are checked when you submit.

26. Test question

A worker's weekly hours over three years are $26$, $33$ and $31$. Fill in the within (demeaned) value for each year.

within value
year 1
year 2
year 3

27. What you can do now

You can use panel data. Explain to someone how the beer-tax slope can change sign when state fixed effects are added.

Working for the steps left to you

17. Your turn: changes in x are 3, 2 and −1; changes in y are 4, 3.5 and −2., step 3

$21 \div 14 = 1.5$

First-difference slope.