ECON 410 · Econometrics II: Causal Methods and Time Series
Panel Data and Fixed Effects
Following the same units over time lets you cancel out every unchanging difference between them.
Key takeaways
- Panel data follows the same people, firms or places over several periods.
- A fixed effect gives each unit its own baseline, which absorbs every trait that never changes for that unit.
- The fixed-effects slope uses only changes within a unit over time.
- A pooled regression can show the wrong sign when baselines differ across units.
- Fixed effects cannot fix hidden traits that change over time, and they cannot estimate effects of things that never change.
Three food trucks park in three different parts of a city. The downtown truck sells a lot and spends little on advertising, since the lunch crowd finds it anyway. The truck in a quiet suburb sells little and spends a lot, desperate for customers. If you line up the trucks and compare advertising with sales, you will find that ads and sales move in opposite directions. Should the suburban owner cut her ad budget?
Of course not. The comparison across trucks is picking up what kind of place each truck sits in, not what advertising does. The fix is to watch each truck against itself. If the downtown truck spends a bit more this month than last, what happens to its own sales? This idea, comparing a unit with its own past, is the heart of panel data. It handles a whole class of hidden traits at once, with no instrument and no experiment.
What panel data is
Most data sets you have met are snapshots. A cross-section measures many units at one moment: 1,000 households this year. A time series measures one unit over many moments: one country's inflation for 50 years. Panel data, also called longitudinal data, does both. It measures many units over many periods, such as 500 stores for each of 10 years.
The advantage is that the same unit appears more than once. That lets you ask about changes inside a unit, and that is exactly what a hidden trait cannot easily contaminate if the trait does not change. A truck's neighborhood, a store's founder, a country's geography and a person's native talent stay put across years.
The three trucks, with numbers
Suppose we observe each truck in three years. Advertising spend is in hundreds of dollars a month and sales are in hundreds of dollars a month. All figures are invented.
| Truck | Year | Advertising | Sales |
|---|---|---|---|
| Downtown | 1 | 1 | 20 |
| Downtown | 2 | 2 | 22 |
| Downtown | 3 | 3 | 24 |
| Midtown | 1 | 4 | 14 |
| Midtown | 2 | 5 | 16 |
| Midtown | 3 | 6 | 18 |
| Suburb | 1 | 7 | 8 |
| Suburb | 2 | 8 | 10 |
| Suburb | 3 | 9 | 12 |
Inside each truck, an extra $100 of advertising goes with $200 of extra sales. That is the true within-truck pattern. But across trucks, the high spenders sell the least.
Pooled regression. Treat all nine rows as one bag and fit a single line. The mean of advertising is 5 and the mean of sales is 16. The deviations multiply and add up like this.
Advertising deviations: −4, −3, −2, −1, 0, 1, 2, 3, 4
Sales deviations: 4, 6, 8, −2, 0, 2, −8, −6, −4
Products: −16, −18, −16, 2, 0, 2, −16, −18, −16 → sum = −96
Squares of advertising deviations: sum = 60
Slope = −96 ÷ 60 = −1.6 The pooled slope is −1.6. It says each extra $100 of advertising lowers sales by $160. That is nonsense for any one truck.
Each truck's line slopes up with slope 2. The pooled line slopes down because baselines differ across trucks.
The fixed-effects fix
A fixed effect is a separate intercept, a personal baseline, for each unit. The model says sales equal the truck's own baseline plus a slope times advertising plus noise. In symbols, the sales of truck i in year t are baseline_i + β × advertising_it + noise. The baseline captures everything that is stable for that truck: its location, its owner's skill, its menu.
There are two equivalent ways to get the estimate.
- Add a dummy variable for each truck. This is called the least squares dummy variable approach. It works but gets clumsy with 10,000 units.
- Demean within each unit. Subtract each truck's own average from its advertising and its sales, then run a regression on the leftovers. This is called the within transformation, and it makes the baselines vanish.
Let's demean. The downtown truck has average advertising 2 and average sales 22. Subtracting gives deviations of −1, 0, +1 for advertising and −2, 0, +2 for sales. The midtown truck averages 5 and 16, and the suburb truck averages 8 and 10. Their deviations are the same pattern, −1, 0, +1 and −2, 0, +2.
Within-truck products per truck: (−1)(−2) + 0 + (1)(2) = 4
Total across three trucks: 12
Within squares per truck: 1 + 0 + 1 = 2
Total across three trucks: 6
Fixed-effects slope = 12 ÷ 6 = 2 The fixed-effects slope is 2: each extra $100 of advertising goes with $200 of extra sales. The sign flipped from −1.6 to +2, and now it matches what happens inside every single truck. The baselines can be recovered too. Downtown's is 22 − 2 × 2 = 18, midtown's is 16 − 2 × 5 = 6 and the suburb's is 10 − 2 × 8 = −6.
Subtracting each unit's own average removes anything about the unit that never changes.
What fixed effects remove, and what they do not
The within transformation wipes out any trait that is constant over time for a unit, whether you measured it or not. That is a big gift, and it closes much of the gap that matching leaves open for unmeasured traits that stay fixed. But it has limits worth learning early.
- Time-varying hidden traits remain. Suppose the downtown truck's owner hires a famous chef in year 2, raising sales and, because she feels rich, ad spending too. Fixed effects cannot see this. Only traits that stay put are removed.
- You cannot estimate effects of things that do not change. If you wanted the effect of a truck's neighborhood, it is swallowed by the baseline. Anything constant within a unit disappears from the answer.
- You need variation inside units. If advertising barely changes within a truck, the estimate rests on tiny wiggles and is noisy.
- Measurement error hurts more. Real changes are small compared with random mistakes in the data, so noise has more weight after demeaning.
Another useful add-on is year fixed effects, a separate intercept for each time period. These absorb shocks that hit all trucks at once, such as a citywide festival or a recession. Using both unit and year fixed effects is called a two-way fixed-effects model. It is the building block for the next lesson, difference-in-differences.
Random effects, briefly
You will sometimes meet a cousin of fixed effects called a random-effects model. It also gives each unit its own baseline, but it treats those baselines as random draws that are unrelated to the other variables in the model. If that is true, the method uses the data more efficiently. If it is false, the answer is biased, just like the pooled regression.
In our food-truck table the baselines clearly track advertising: the trucks with high baselines spend little. So random effects would go wrong here, while fixed effects get it right. Economists often run a test, named for the economist Jerry Hausman, that compares the two sets of estimates. A big gap says the baselines are tangled up with the other variables, and fixed effects are the safer choice. For causal questions, most researchers start with fixed effects because they ask for fewer assumptions about where baselines come from.
Pick the method by what you believe about the hidden baselines.
A common mistake: believing fixed effects prove cause
Fixed effects are a powerful tool for one kind of problem, not a magic wand. A paper that says "we control for fixed effects" may still suffer from time-varying confounders, reverse causation (low sales this year might cause higher ad spending next year) or measurement noise. Look at what could change over time at the same moment as the treatment.
A second mistake is to ignore that the same unit is observed repeatedly. The errors in one truck's three years are usually related, so the standard errors need to allow for that. Researchers handle this by clustering standard errors by unit. Software does it with a setting, but you should check it was done. Without it, confidence intervals look too narrow.
A third, subtler mistake is to read the baseline as meaningless noise. The fixed effects themselves often carry information. In education research, school effects show which schools have lasting advantages that scores alone hide. In finance, firm effects capture traits like management quality.
Words to know
Panel data observations on the same units, such as people or firms, over several time periods.
Cross-section data on many units at a single point in time.
Fixed effect a separate baseline for each unit that absorbs every trait of that unit that never changes.
Within transformation subtracting each unit's own average from its values, so only changes inside the unit remain.
Pooled regression a regression that ignores which unit each row belongs to.
Time-varying confounder a hidden trait that changes over time and affects both the cause and the outcome.
Clustered standard errors standard errors that allow the repeated rows from one unit to be related.
Check yourself
- What does panel data have that a cross-section lacks, and why does that help?
- In the food-truck table, why does the pooled regression give a negative slope when every truck's slope is positive?
- A shop has advertising of 3, 5, 7 over three years and sales of 30, 36, 42. What are the within-shop deviations and the slope?
- Why can't a fixed-effects model estimate the effect of a truck's neighborhood on sales?
- Give an example of a hidden trait that fixed effects would not remove.
- Why should standard errors be clustered by unit?
Show the answers
- It follows the same units over time, so you can compare a unit with itself and cancel traits that never change.
- The trucks with the highest advertising have the lowest baselines, so across trucks the pattern is dominated by baselines, not by advertising's effect.
- Averages are 5 and 36, so advertising deviations are −2, 0, +2 and sales deviations are −6, 0, +6; slope = (12 + 12) ÷ (4 + 4) = 24 ÷ 8 = 3.
- The neighborhood never changes within a truck, so subtracting each truck's average removes it completely.
- For example, a new chef hired the same year the truck raises its ads; it changes over time and affects both advertising and sales.
- Rows from the same unit are related, so treating them as independent makes the standard errors too small and the intervals too narrow.