Course contentsShow
← Data Science
Lesson 1452 of 2,14536. Causal Inference BasicsFree lesson

The Difference-in-Differences Setup

Learn the basic DiD framework with treatment and control groups measured before and after an intervention.

The Difference-in-Differences Setup

What you'll learn: How to estimate causal effects by comparing changes over time between treated and untreated groups.

The Core Idea

Difference-in-Differences (DiD) is a powerful causal inference technique that measures the effect of an intervention by comparing the change in outcomes for a treatment group to the change in outcomes for a control group over the same time period.

Think of it like this: You want to know if a new training program improves employee productivity. Some departments get the training (treatment group), others don't (control group). You measure productivity before and after the training for both groups. The key insight: if other factors affect productivity equally across groups, the difference in how much each group changed reveals the training's causal effect.

The Setup

DiD requires four key measurements:

  1. Treatment group, before intervention (baseline)
  2. Treatment group, after intervention
  3. Control group, before intervention (baseline)
  4. Control group, after intervention

The calculation has two steps:

  • First difference: Treatment group's change = (After - Before)
  • Second difference: Control group's change = (After - Before)
  • DiD estimate: Treatment effect = Treatment change - Control change

Why This Works

The control group accounts for time trends that would have happened anyway (economic conditions, seasonality, etc.). By "differencing out" these common trends, you isolate the intervention's unique impact.

This assumes parallel trends: without treatment, both groups would have changed similarly over time—a critical assumption you'll need to verify in practice.

Key Takeaway: Difference-in-Differences estimates causal effects by comparing how treatment and control groups change over time, using the control group to subtract away confounding time trends.