5.1 Difference-in-differences
Difference-in-differences: what breaks when parallel trends fails
Difference-in-differences compares the change in an outcome for a group that gets a policy with the change for a group that does not get it. This page shows the main assumption behind the method. It also shows what happens to the estimate when this assumption is false.
In brief
A chain of stores starts a new policy in some of its stores in period 6. These stores are the treated group, and the other stores are the comparison group. We observe an average outcome, for example weekly sales, in both groups in periods 1 to 10.
- The difference-in-differences (DiD) estimate is the change in the treated group minus the change in the comparison group. Each change is the average in periods 6 to 10 minus the average in periods 1 to 5.
- The average treatment effect on the treated (ATT) is the average effect of the policy on the treated stores after the start. The simulation knows the ATT, so the readouts show it as the true effect. Under the assumptions in the explanation, the DiD estimate estimates the ATT.
- Estimate minus true effect shows how far the DiD estimate misses the ATT in the current sample.
- The estimated extra growth per period uses periods 1 to 5, before the start. It estimates how much faster the treated group grows than the comparison group in each period.
Move the sliders and watch these numbers. The explanation below the simulation gives the reasons.
Try it
The simulation has 50 stores in each group. Without the policy and apart from random noise, both groups have the same changes from one period to the next. Two sliders break this: the extra-growth slider and the other-change slider.
How the simulation makes the data
Each store has its own level of the outcome. The outcome of each store also moves up and down at random from period to period. This random part is the noise.
The simulation also keeps the outcome that each treated store would have had without the policy. So it can show the true effect.
| Group | Before (periods 1 to 5) | After (periods 6 to 10) | Change |
|---|---|---|---|
| Treated group | |||
| Comparison group | |||
| Difference-in-differences | |||
| Treated group without the policy (true, simulation only) |
The table rounds each number to two decimals. So a difference of two printed numbers can be off by 0.01.
- DiD estimate
- 95% confidence interval
- True effect (ATT)
- Estimate minus true effect
- Estimated extra growth per period (periods 1 to 5)
For the 95% confidence interval, the page first turns each store into one number: its average after the start minus its average before the start. Second, it compares these numbers between the two groups, as for any difference between two means. The first step matters because the outcomes of one store are correlated from period to period. A standard error that treats every store-period as a new, independent observation is then too small. Averaging each store into one before period and one after period is one of the fixes that Cunningham (2021, ch. 9) describes. The 95% confidence interval and other terms are defined in the key terms on the home page.
The idea
A chain of stores starts a new policy in some of its stores in period 6. The other stores do not start the policy. We call the first set of stores the treated group and the second set the comparison group. We observe an average outcome, for example weekly sales, in both groups in periods 1 to 10.
To measure the effect, we need a number that nobody observes: the average outcome of the treated group after the start, without the policy. There are three common ways to fill in this number. Each way needs its own assumption (Cunningham 2021, ch. 9).
- Use the comparison group after the start. This assumes that, without the policy, both groups would have the same average outcome.
- Use the treated group before the start. This assumes that, without the policy, the outcome of the treated group would not change over time. A before-and-after comparison mixes the effect of the policy with everything else that changed over the same time. For example, the season or prices in the whole market may have changed.
- Use the treated group before the start, plus the change in the comparison group. This is difference-in-differences.
Difference-in-differences (DiD) uses the comparison group to remove the second thing (Angrist and Pischke 2009, ch. 5; Cunningham 2021, ch. 9; Huntington-Klein 2025, ch. 18). It subtracts the change in the comparison group from the change in the treated group. Some textbooks write DD or DID for the same method.
\[\begin{aligned} \text{DiD} = {} & (\text{treated after} - \text{treated before}) \\ & - (\text{comparison after} - \text{comparison before}) \end{aligned}\]
The change in the comparison group stands in for the change that the treated group would have had without the policy. This step is correct only under the parallel trends assumption. This assumption is about the treated group without the policy. Its average outcome would have changed by the same amount as the average outcome of the comparison group.
In symbols, write \(Y(1)\) for the outcome with the policy and \(Y(0)\) for the outcome without the policy. \(E[\,\cdot\,]\) is an expected value, that is, an average over the population of stores. A vertical bar means among: \(E[Y(0) \mid \text{treated}]\) is the average of \(Y(0)\) among the treated stores. Parallel trends says:
\[\begin{aligned} & E[Y_{\text{after}}(0) - Y_{\text{before}}(0) \mid \text{treated}] \\ = {} & E[Y_{\text{after}}(0) - Y_{\text{before}}(0) \mid \text{comparison}] \end{aligned}\]
The two groups do not need the same level of the outcome. Only the changes over time without the policy must match.
Parallel trends depends on how the outcome is measured. On this page, the treated stores start at a higher level. If both groups would gain the same amount of sales, the treated stores would gain a smaller percentage. Then the trends are parallel in sales but not in percentages or in logarithms. So a study must explain why the assumption holds on the scale that it uses (Cunningham 2021, ch. 9).
The policy must also leave the comparison group unaffected. Suppose that the policy also changes sales in the comparison stores. Then their change no longer shows what would have happened without the policy (Huntington-Klein 2025, ch. 18).
Suppose that parallel trends holds and that the policy has no effect before it starts (no anticipation). Then DiD estimates the average effect of the policy on the stores that got it, in the periods after the start. This quantity is the average treatment effect on the treated (ATT). DiD says nothing about the effect that the policy would have on the comparison group (Huntington-Klein 2025, ch. 18).
Assume parallel trends, no anticipation, and no spillovers. Then, in symbols, the DiD calculation equals the ATT:
\[\text{ATT} = E[Y_{\text{after}}(1) - Y_{\text{after}}(0) \mid \text{treated}]\]
In general, DiD equals the ATT plus a bias term. The bias term is the change in \(Y(0)\) for the treated group minus the change in \(Y(0)\) for the comparison group. Under parallel trends, this term is zero (Cunningham 2021, ch. 9).
Parallel trends is an assumption about outcomes that nobody observes: the outcomes of the treated group after the start date without the policy. So the data cannot test it directly. Parallel lines before the start date make the assumption more believable. They do not prove it (Cunningham 2021, ch. 9).
Lines that move apart before the start date do not prove that the assumption fails, either. The gap could stop growing at the start date for reasons other than the policy. Then parallel trends would still hold (Huntington-Klein 2025, ch. 18).
An example comes from a study of the minimum wage (Card and Krueger 1994). On April 1, 1992, the minimum wage in New Jersey rose from $4.25 to $5.05 per hour. The minimum wage in Pennsylvania did not change. The authors measured employment at fast-food restaurants in New Jersey and in eastern Pennsylvania before and after the rise. The Pennsylvania restaurants were the comparison group.
DiD as a regression: two-way fixed effects
Many studies compute DiD with a regression instead of a table. The regression has a separate intercept for each store and a separate intercept for each period. It also has a policy indicator that is 1 for treated stores from period 6 on. This regression is called two-way fixed effects (TWFE).
On this page, the TWFE coefficient on the policy indicator equals the DiD number in the table. The reason is that all treated stores start in the same period and every store is observed in every period. When groups start the policy in different periods, TWFE can mislead. Module 5.2 shows why.
References
- Angrist, J. D., & Pischke, J.-S. (2009). Mostly harmless econometrics: An empiricist's companion. Princeton University Press. Chapter 5, section 5.2, Differences-in-Differences. https://doi.org/10.1515/9781400829828
- Card, D., & Krueger, A. B. (1994). Minimum wages and employment: A case study of the fast-food industry in New Jersey and Pennsylvania. American Economic Review, 84(4), 772-793. https://www.jstor.org/stable/2118030
- Cunningham, S. (2021). Causal inference: The mixtape. Yale University Press. Chapter 9, Difference-in-Differences. https://doi.org/10.2307/j.ctv1c29t27. Free online first edition: chapter 9.
- Huntington-Klein, N. (2025). The effect: An introduction to research design and causality (2nd ed.). Chapman & Hall. Chapter 18, Difference-in-Differences. Free online edition: https://theeffectbook.net/ch-DifferenceinDifference.html