liveBook · Manning

Difference-in-differences

As explained in Causal Inference for Data Science

Difference in differences is a causal estimation method that compares changes over time between treated and comparison groups.

Difference-in-differences (DiD) estimates the effect of a time-related event by comparing the before–after change in a treated group with the corresponding change in an unaffected comparison group. This separates the event’s apparent effect from changes that affect both groups over time. section 11.4 section 11.8

Apply the method by following this structure:

  • Measure the treated group’s change: outcome after treatment minus outcome before treatment. section 11.4.5
  • Measure the comparison group’s change over the same periods. section 11.4.5
  • Subtract the comparison-group change from the treated-group change. The result estimates the average treatment effect on the treated. section 11.4 section 11.4.5
  • Treat the estimate as causal only when, without the event, both groups would have followed the same path of development. section 11.4

A movie-release comparison

Suppose a streaming service wants to know whether releasing Star Wars movie VII increased views of the previous six Star Wars films. Compare their before–after change with the change for three unaffected Lord of the Rings films. If Star Wars views rise by 300 relative to their earlier level while Lord of the Rings views rise by 100, DiD attributes the remaining 200 increase to the release, subject to the same-path assumption. section 11.4

Figure 11.18 Simulated panel data example. The group with D = 1 represents Star Wars movies, and the group with D = 0 represents LoTR movies. Lines help us to visualize the change of trend due to the release of the new movie.
figure

Use the simulated panel-data figure to inspect the treated and control groups, their before–after trends, and the change attributed to the release. section 11.4

How Causal Inference for Data Science covers it

How deep it goes
Explains the comparison, assumption, direct estimator, regression implementation, covariates, and confidence intervals.
Examples
Uses Star Wars and Lord of the Rings movie groups, simulated panel data, direct calculations, and R or Python regressions.
What it assumes
Assumes familiarity with causal effects, treated and control groups, time-indexed outcomes, and basic regression.
What you can do after
Apply DiD by computing two time differences, subtracting them, or estimating the treatment interaction with linear regression.
How it connects
Connects causal estimation with panel data, synthetic controls, regression discontinuity designs, A/B tests, and linear regression.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Causal Inference for Data Science. The section links point to the parts of the book it draws on.