A city introduces a childcare subsidy in one region but not in a nearby comparison region. Employment among eligible parents rises after the subsidy in the treated region. Is that the program's effect? Perhaps—but employment could have risen everywhere because the economy improved. And the treated region might have started with a different employment rate before the subsidy.
Difference-in-differences, or DiD, uses both dimensions of the comparison: the difference between groups and the change over time. The goal is not to pretend the regions are identical. It is to ask whether the treated region changed more than a credible comparison suggests it would have changed without the program.
Why use two differences?
Consider two groups: a treated group and a comparison group . Observe each before () and after () the policy. The simple DiD estimate is
The first difference is the treated group's before-after change. That change includes both the policy and everything else that happened over time. The second difference is the comparison group's change over the same period. Subtracting it removes the time change shared by the groups—if that shared-change assumption is credible.
This also handles a stable starting difference. Suppose the treated region has lower employment than the comparison region both before and after the policy. The level gap itself does not invalidate DiD. What matters is whether, without the policy, the two groups would have followed the same trend.
The assumption that does the identifying work
Let be group 's average outcome at time if it does not receive the treatment. For DiD to identify the post-treatment effect on the treated group, the key parallel-trends assumption is
The treated group's post-policy no-treatment outcome, , is counterfactual: after treatment begins, we cannot observe what would have happened in that region without it. Parallel trends says the comparison group's change is a good estimate of that missing change. It does not say the groups have equal outcomes, equal characteristics, or flat trends. It says their average trends would have matched in the absence of treatment.
Under this assumption, the observed difference-in-differences subtracts the counterfactual change from the treated group's actual change, leaving the average treatment effect on the treated group in the post period. If parallel trends fails, DiD may attribute a pre-existing divergence or a treated-region-specific shock to the program.
A regression version of the same calculation
For two groups and two periods, the same estimate can be written as a regression:
Here equals one for the treated group, equals one after the policy, and their interaction equals one only for treated observations after the policy. Its coefficient is the DiD estimate. The group indicator absorbs stable level differences; the period indicator absorbs changes common to both groups. The interaction captures the additional post-period change in the treated group.
This is the simple two-by-two design. It is useful to understand before moving to many groups, many dates, or policies adopted at different times; those extensions require additional care and are outside this lesson's calculation.
What should make us cautious?
Parallel trends is an assumption about an unobserved counterfactual, so no graph or test can prove it. Several pre-treatment periods let us check whether the groups had similar trends before the policy. Similar pre-trends support the design's plausibility; they do not guarantee that the trends would have remained parallel after treatment. Pre-trend tests can also have little power when data are noisy or the pre-period is short.
Other threats deserve an explicit check:
- A simultaneous, group-specific shock: if another policy or industry change affects only the treated region at the same time, its effect can be mistaken for the program's.
- Anticipation: if people or firms change behavior before the official start, the “before” period may already be affected.
- Changing composition or measurement: if the populations or definitions differ across periods, a measured change may not reflect a change for comparable units.
- Spillovers: if the treatment affects the comparison region—for example, workers commute across the boundary—the comparison is partly treated too.
- Uncertainty at the assignment level: when a policy is adopted by region, outcomes within a region may move together. Treating every person as an independent policy assignment can make an estimate look more precise than it is.
DiD is therefore not a recipe that turns any two before-after series into a causal answer. The researcher must explain why the comparison group's trend is a credible stand-in for the treated group's missing counterfactual and examine evidence that could challenge that argument.
Worked example
A childcare subsidy begins in Region A but not Region B. Employment among eligible parents is 60% in A and 64% in B before the policy. One year later it is 68% in A and 66% in B. Calculate the difference-in-differences estimate. Under parallel trends, what would A's employment rate have been without the subsidy?
Step 1 — calculate the treated region's change. Region A moves from 60% to 68%, an increase of 8 percentage points.
Step 2 — calculate the comparison region's change. Region B moves from 64% to 66%, an increase of 2 percentage points.
Step 3 — subtract the common comparison trend.
The estimated effect is 6 percentage points. Notice that A began four points below B; DiD does not require their starting levels to match.
Step 4 — construct A's no-subsidy counterfactual. If A would have followed the same two-point trend as B without the subsidy, its counterfactual employment rate would be
The observed rate is 68%, which is six points above that counterfactual. Under parallel trends and the other design assumptions, we attribute that extra six-point rise to the subsidy for the treated group.
Step 5 — state what the arithmetic cannot establish. The estimate is not automatically causal just because it was calculated correctly. We still need to defend parallel trends, rule out a simultaneous shock unique to Region A, check for anticipation and spillovers, and quantify sampling uncertainty. The four numbers alone cannot verify those conditions.
Where this leads
DiD builds a counterfactual trend by combining a treated group's before-after change with a comparison group's before-after change. Its identifying claim rests on parallel trends—not on equal starting levels or on the arithmetic itself. This is the first of several applied designs in the roadmap. Next, we will study instrumental variables, which use a source of variation that shifts treatment while, under demanding assumptions, affecting the outcome only through that treatment; regression discontinuity will follow as a separate threshold-based design.