Search

Search papers and lessons

Panel Data

Level 2 · 12 min read

Panel data follows the same units, such as people, firms or countries, across several time periods, so each unit can be compared with its own past.

On this page

  • Colour = topic mix
  • Discrete math
  • Probability
  • Calculus
  • Linear algebra
  • Classical models
  • Losses & regularization
  • Sign in to see your progress

TL;DR

Panel data records the same units, such as workers, firms or countries, over several time periods. Each unit appears many times, once per period. That lets you compare a unit with itself at different dates, which removes everything about the unit that stays the same over time, including traits you never measured.

Where you'll see it: in studies of how a worker's wage changes after more schooling, in tracking how a firm's investment responds to its own tax changes, and in cross-country studies that follow the same countries across decades.

Intuition

A photo or a film

Think of three ways to record a group of people.

  • A cross-section is one photo: many people, one moment.
  • A time series is one long film of one person: one unit, many moments.
  • A panel is many films filmed side by side: many units, many moments.

The panel is the most informative of the three, because it gives you two kinds of comparison at once. You can compare different units at the same time, as a cross-section does, and you can compare the same unit at different times, as a time series does.

A small panel looks like a table with one row per unit and time combination.

UnitYearHours trainedWage
Worker 120201020
Worker 120211223
Worker 220202030
Worker 220212233

Why the second dimension matters

Suppose you have only a single snapshot from 2020. Worker 2 trains more and earns more. Is the extra training the cause, or does Worker 2 simply have more natural ability, which both raises training and raises pay? A snapshot cannot tell these apart, because ability is not in the data.

A panel can. Look at how Worker 2 changes from 2020 to 2021: training rose by 2 hours and pay rose by 3. Ability is the same in both years, so it cannot explain that change. The panel uses each unit as its own control. Anything fixed about the unit drops out of the comparison.

This is the core idea of panel data: a fixed trait of a unit cannot fake an effect when you only look at how that unit changes.

The math

Setting it up

Let yity_{it} be the outcome for unit ii at time tt, and let xitx_{it} be the variable we want the effect of. There are NN units, indexed by i=1,…,Ni = 1, \dots, N, and TT periods, indexed by t=1,…,Tt = 1, \dots, T. A panel with every unit observed in every period is called balanced. It has NTNT observations in total.

Suppose the outcome follows

yit=βxit+αi+εit.y_{it} = \beta x_{it} + \alpha_i + \varepsilon_{it}.

Here β\beta is the effect we want. The term αi\alpha_i is a fixed trait of unit ii that does not change over time, such as ability, culture or location. It may be unobserved. The term εit\varepsilon_{it} is everything else that changes from period to period.

Definition

Definition: Panel data

A panel dataset is a collection of observations {(yit,xit)}\{(y_{it}, x_{it})\} indexed by a unit ii and a time tt. It is balanced when every unit is observed in every period, and unbalanced otherwise.

Why a single regression can go wrong

If you ignore αi\alpha_i and run an ordinary regression of yity_{it} on xitx_{it}, the estimate of β\beta is biased whenever αi\alpha_i is correlated with xitx_{it}. The fixed trait then gets credited to xx. This is the omitted variable bias problem, a form of confounding, in a panel setting. The regression run on all NTNT rows is called pooled linear regression.

Removing the fixed trait

Average the model over time for each unit (a plain mean of that unit's own rows). Let yˉi\bar{y}_i, xˉi\bar{x}_i and εˉi\bar{\varepsilon}_i be the unit means. Then

yˉi=βxˉi+αi+εˉi.\bar{y}_i = \beta \bar{x}_i + \alpha_i + \bar{\varepsilon}_i.

Subtract this from the original equation for each period. The term αi\alpha_i appears in both, so it cancels:

yit−yˉi=β (xit−xˉi)+(εit−εˉi).y_{it} - \bar{y}_i = \beta\,(x_{it} - \bar{x}_i) + (\varepsilon_{it} - \bar{\varepsilon}_i).

The result uses only deviations from each unit's own average. The estimator that does this, pooled over all units, is

β^=∑i∑t(xit−xˉi)(yit−yˉi)∑i∑t(xit−xˉi)2.\hat{\beta} = \frac{\sum_{i}\sum_{t} (x_{it} - \bar{x}_i)(y_{it} - \bar{y}_i)}{\sum_{i}\sum_{t} (x_{it} - \bar{x}_i)^2}.

This is the within estimator. Its full treatment, with the dummy-variable form and its assumptions, is in the fixed effects model.

The estimator only uses variation within units over time. If xitx_{it} never changes for a unit, its deviation is zero and the unit contributes nothing to the sums. This matters a great deal in practice, as the examples show.

Worked examples

Example
1. Two units, two periods, by hand

Take two units observed in two periods. The true model is yit=2xit+αiy_{it} = 2x_{it} + \alpha_i, with no noise, so the true effect is β=2\beta = 2. Unit A has αA=0\alpha_A = 0 and unit B has αB=4\alpha_B = 4.

Unitttxxyy
A112
A224
B128
B2310
  1. Check the data. For A, 2⋅1+0=22 \cdot 1 + 0 = 2 and 2⋅2+0=42 \cdot 2 + 0 = 4. For B, 2⋅2+4=82 \cdot 2 + 4 = 8 and 2⋅3+4=102 \cdot 3 + 4 = 10.
  2. Pooled regression. Ignore the units and fit one line to all four points. The mean of xx is 22 and the mean of yy is 66. The cross-product sum is ∑(x−2)(y−6)=(−1)(−4)+0+0+(1)(4)=8\sum (x-2)(y-6) = (-1)(-4) + 0 + 0 + (1)(4) = 8. The sum of squares of xx is 1+0+0+1=21 + 0 + 0 + 1 = 2. The pooled slope is 8/2=48/2 = 4.
  3. Interpret step 2. The pooled slope is 44, twice the true value. Unit B has both higher xx and a higher fixed trait, so the trait is credited to xx.
  4. Within deviations. For A, the mean of xx is 1.51.5 and the mean of yy is 33, so the deviations are xx: −0.5,0.5-0.5, 0.5 and yy: −1,1-1, 1. For B, the means are 2.52.5 and 99, so the deviations are xx: −0.5,0.5-0.5, 0.5 and yy: −1,1-1, 1.
  5. Within slope. The cross-products are 0.5+0.50.5 + 0.5 for A and 0.5+0.50.5 + 0.5 for B, a total of 22. The squared xx deviations are 0.25+0.250.25 + 0.25 for A and the same for B, a total of 11. The within slope is 2/1=22/1 = 2.
  6. Interpret step 5. The within estimator recovers the true β=2\beta = 2. The fixed traits αA\alpha_A and αB\alpha_B were removed by the demeaning.
Example
2. Three workers, two years, with fixed ability

A standard textbook setting. Wage yy depends on training hours xx, with β=1.5\beta = 1.5, and each worker has a fixed ability term αi\alpha_i. The values below are constructed so the model holds exactly.

Workerαi\alpha_iYear 1: xx, yyYear 2: xx, yy
1510, 2012, 23
2020, 3022, 33
3−10-1030, 3528, 32
  1. Within deviations for worker 1. Mean x=11x = 11, mean y=21.5y = 21.5. Deviations: xx: −1,1-1, 1; yy: −1.5,1.5-1.5, 1.5.
  2. Worker 2. Mean x=21x = 21, mean y=31.5y = 31.5. Deviations: xx: −1,1-1, 1; yy: −1.5,1.5-1.5, 1.5.
  3. Worker 3. Mean x=29x = 29, mean y=33.5y = 33.5. Deviations: xx: 1,−11, -1; yy: 1.5,−1.51.5, -1.5.
  4. Cross-products. Each worker contributes 1.5+1.5=31.5 + 1.5 = 3, for a total of 99.
  5. Squared xx deviations. Each worker contributes 1+1=21 + 1 = 2, for a total of 66.
  6. Within slope =9/6=1.5= 9 / 6 = 1.5. This matches the true β\beta.
  7. Compare with pooled regression. Pooling all six rows gives a slope of 691/994≈0.70691/994 \approx 0.70. Worker 3 has high training and low ability, which pulls the pooled slope toward zero. The within estimator is not fooled by that.

The example is exact because there is no noise. With real data the within estimate would differ from the truth by sampling error, but the bias from the fixed traits would be gone.

Example
3. Realistic: when a regressor does not change over time

Illustrative numbers, not from a real dataset. A survey follows N=1,000N = 1{,}000 adults for T=10T = 10 years, giving NT=10,000NT = 10{,}000 rows. The outcome is annual income and the regressor is years of formal education.

  1. Count the rows that can help. Within estimation uses only changes over time. Suppose most adults finish their education before the survey starts, so their education value is the same in every year. For those people xit−xˉi=0x_{it} - \bar{x}_i = 0 in every period.
  2. Suppose 900 of the 1,000 adults have constant education. Then only 100 adults contribute to the denominator ∑(xit−xˉi)2\sum (x_{it} - \bar{x}_i)^2. The effect of education is estimated from a small slice of the sample.
  3. Interpret step 2. The estimate is still valid, but its standard error is much larger than the 10,000 rows suggest. The panel has many observations and little within variation.
  4. Consequence. Panels are very good at estimating effects of variables that change within units, such as a training programme or a tax change. They are weak for variables that barely move, such as schooling after a certain age. For those, a researcher needs another design or a different estimator.

Tradeoffs and failure modes

Panel data solves one problem and creates others. Use it when a unit trait is likely to be correlated with the variable of interest and you have repeated observations. Be careful in the situations below.

SituationProblemBetter choice
Unit trait is correlated with xxPooled regression is biasedFixed effects, which use within variation
xx never changes for a unitThat unit gives no information to fixed effectsChoose a variable that varies, or a different design
Shocks hit all units in the same periodA common trend can look like an effectAdd time fixed effects (a separate intercept for each period)
Errors are correlated within a unit over timeStandard errors (the measure of how much an estimate would vary from sample to sample) that assume independence are too smallCluster standard errors by unit, which lets errors be related within a unit
Units drop out of the survey (attrition)Remaining units may differ systematicallyCheck who leaves, and reweight if needed
Unit trait is uncorrelated with xxFixed effects throw away useful between-unit variationRandom effects, which treat αi\alpha_i as random noise drawn per unit
Last period's outcome used as a regressor, short TTDemeaning makes the regressor correlated with the error, biasing its coefficientSpecialised dynamic panel estimators

The key tradeoff is between the power of within variation and the information you lose by throwing away between-unit comparisons. Fixed effects give up all between-unit information. Random effects use it, but they assume the unit traits are uncorrelated with xx, and that assumption is often false.

History

Panel analysis grew out of economic surveys that followed the same households over time. The Panel Study of Income Dynamics, a long-running survey of US families that began in 1968, is one of the best-known early examples. Economists started using fixed effects regressions for panel data in the 1960s, and Yair Mundlak's 1978 paper on pooling time series and cross-section data helped make the random and fixed effects choice a standard part of applied work. The method spread to other fields, including sociology, public health and political science, where repeated measures on the same people or places are common.

Recap

A panel has many units observed over many periods. Each unit can be compared with itself, so any trait that stays fixed for the unit drops out of the comparison. Subtracting each unit's own average is the simplest way to do this, and it gives the within estimator. The price is that only changes within units inform the estimate. The next step is the fixed effects model, which turns this idea into a full regression, and omitted variable bias explains why the fixed traits matter in the first place.

Check yourself

QuestionRecall: what does the term αi\alpha_i represent in the panel model yit=βxit+αi+εity_{it} = \beta x_{it} + \alpha_i + \varepsilon_{it}?Show answer

It is a fixed trait of unit ii that does not change over time, such as ability, culture or location. It may be unobserved. It does not carry a time index because it is constant for that unit.

QuestionComputation: a unit has training hours x=(4,6,8)x = (4, 6, 8) over three periods. What is the within deviation of xx in the middle period?Show answer

The unit mean is (4+6+8)/3=6(4 + 6 + 8)/3 = 6. The middle deviation is 6−6=06 - 6 = 0. The first deviation is 4−6=−24 - 6 = -2 and the last is 8−6=28 - 6 = 2. Deviations always sum to zero within a unit.

QuestionWhy: why can a pooled regression give the wrong slope even when the data are exact?Show answer

Pooling ignores that units differ in a fixed trait. If a unit with high xx also has a high fixed trait, the regression attributes part of the trait's effect to xx. This is omitted variable bias, and it does not disappear with more data from the same units. Example 1 in this lesson shows a pooled slope of 4 when the true value is 2.

QuestionApplied: a researcher studies the effect of a city's minimum wage on teenage employment, using data on 50 cities over 20 years. A city's minimum wage changes only twice in 20 years. Which concern from this lesson applies, and what should the researcher check?Show answer

Most cities have little within-city variation in the policy, so those cities contribute little to the within estimator, and the estimate rests on the few changes. The researcher should check how many changes occur and where they occur, and should consider shocks that hit all cities in the same year, which call for time fixed effects. Clustering standard errors by city is also needed, because outcomes within a city are correlated over time.

Sources

Panel Data — explained simply | ungoon.me