Data Science · Advanced level

Advanced level · Module 1: Causal Inference and Programme Evaluation · Lesson 3 of 4

Difference-in-Differences

Estimate effects from before-and-after data in treated and comparison groups, and check the parallel-trends assumption.

In this lesson you will

  • Calculate a difference-in-differences estimate
  • Check parallel trends and state the assumptions

Key concepts

before–after comparisoncomparison groupparallel trendsregression form of DiD

The lesson

Difference-in-differences (DiD) compares the change over time in a treated group with the change in a comparison group. Subtracting the comparison group's change removes trends that affected both.

Its key assumption is parallel trends: without the programme, both groups would have changed similarly. Check it by plotting several periods before the programme started.

DiD can be estimated with a regression including group, period and their interaction, which adds standard errors and control variables.

Step by step

  1. Calculate DiD by hand from a two-by-two table.
  2. Plot pre-programme trends for both groups.
  3. Estimate DiD with regression.
  4. Write the assumptions and limits.
Data and chart

Did school feeding raise attendance? A difference-in-differences estimate

Attendance before and after a feeding programme in programme and comparison districts.

Average attendance rate (%) in the term before and the term after feeding began (illustrative data)
GroupBefore (%)After (%)
Programme districts6274
Comparison districts6065
Gap (programme − comparison)29
Attendance before and after, by group Before (%): Programme districts 62, Comparison districts 60, Gap (programme − comparison) 2. After (%): Programme districts 74, Comparison districts 65, Gap (programme − comparison) 9 020406080Programme d…Comparison …Gap (progra…Before (%)After (%)

What the data shows

Attendance rose 12 points in programme districts (62 → 74) but also 5 points in comparison districts (60 → 65), probably because of something affecting everyone, such as a good harvest.

The difference-in-differences estimate is (74 − 62) − (65 − 60) = 7 percentage points: the rise beyond what happened anyway. Equivalently, the gap between the groups grew from 2 to 9 points.

Recommendation

Report an estimated effect of about 7 points, with its confidence interval from the regression version, after checking that the two groups had similar attendance trends in earlier terms — the parallel-trends assumption.

Practice activity

Complete the feeding programme DiD analysis from the practical activity.

Expected result: A DiD estimate with trend checks, standard errors and careful conclusions.

Check your understanding

  1. What does DiD subtract?

    Show answer

    The comparison group's change over the same period.

  2. What is the parallel-trends assumption?

    Show answer

    Without the programme, the groups would have changed similarly over time.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.