Skip to the workspace
Pebellslearn by building
Experiments and Causal Effects  ›  Capstone Project

Difference-in-Differences

Econometrics 14 minDifference-in-differences estimates an effect by subtracting a comparison group's change over time from the treated group's change, which removes shared trends as long as both groups would otherwise have moved in parallel.

ai data scientist / Difference-in-Differences

Explore each scene at your own pace.

01 · The rule

The rule

Difference-in-Differences

In March, Pantry launched 20-minute express delivery in Pune but not in Nashik. By April, Pune's orders were up sharply, and the launch team wants credit for all of it. But March also brought Holi and the start of wedding season, and orders rose in Nashik too, where nothing launched. How much of Pune's rise did express delivery actually cause?

The rule

Subtract the comparison group's change to remove the shared trend.

Neither simple comparison works on its own:

  • Pune before versus after mixes the launch with everything else that changed over those months: season, marketing, prices.
  • Pune versus Nashik after the launch mixes the launch with the gaps that already existed between the two cities.

Difference-in-differences (DiD) subtracts both problems away. First take each city's change over time, then take the difference between those changes:

DiD=(treatedafter−treatedbefore)−(controlafter−controlbefore)\text{DiD} = (\text{treated}_{\text{after}} - \text{treated}_{\text{before}}) - (\text{control}_{\text{after}} - \text{control}_{\text{before}})

Weekly orders per 1,000 customers:

City February April Change
Pune, with express 40 52 +12
Nashik, without 30 36 +6

Nashik's +6 shows what happened anyway. Pune's extra rise beyond that, 12 − 6 = +6 orders per 1,000 customers a week, is the estimated effect of express delivery.

The whole method rests on one assumption, parallel trends: without the launch, Pune would have changed by the same amount as Nashik. The levels may differ (40 against 30); the trends must match. You cannot see the Pune that never got express, but you can check the months before the launch. If both cities rose in step from October to February, the assumption is believable. If Pune was already pulling away, the estimate will credit that head start to express delivery.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.