0/70 completed
Econometrics Interactive

Difference-in-Differences

Estimate causal treatment effects by comparing changes over time between treatment and control groups. The gold standard for policy evaluation.

๐Ÿ“Š The DiD Framework

DiD = (Y_T,post - Y_T,pre) - (Y_C,post - Y_C,pre)

Compare the change in treatment group to the change in control group. The difference removes time trends affecting both.

Key Insight: If both groups would have changed equally without treatment, any extra change in treatment group = causal effect.

PrePostChange
Treatment66.8110.1+43.2
Control57.488.6+31.2
DiD12.0

Parameters

True Treatment Effect 15
-20 30
Baseline Level 50
30 70
Time Trend (per period) 5
0 10
Pre-existing Group Diff 10
0 20

๐Ÿ“Š Estimates

True Effect 15
DiD Estimate 12.0
Estimation Error -3.0

Treatment vs Control Over Time

Vertical gap after T5 between green line and dashed gray = treatment effect. DiD estimates this by comparing changes.

The Parallel Trends Assumption

โœ“ Valid DiD

Pre-treatment trends are parallel. Any difference post-treatment is attributable to the intervention.

โœ— Invalid DiD

Pre-treatment trends diverge. Groups were already on different trajectoriesโ€”DiD estimate is biased.

โš ๏ธ Key Assumptions

Parallel Trends

Critical

Without treatment, groups would have followed same trajectory

No Spillovers

Critical

Treatment doesn't affect control group

Stable Composition

Group membership doesn't change due to treatment

No Anticipation

Behavior doesn't change before treatment

๐Ÿ’ฐ Pricing Applications

What to Test

  • โ†’ New pricing tier impact (launch in one region first)
  • โ†’ Promotional campaign effectiveness
  • โ†’ Feature launch impact on engagement
  • โ†’ Regulatory change effects

When to Use DiD vs A/B

  • DiD: Can't randomize, observational data, policy changes
  • A/B: Can randomize, want cleanest causal estimate

R Code Equivalent

# Difference-in-Differences regression
library(fixest)

# Prepare data
panel_data <- data.frame(
  id = rep(1:n_units, each = n_periods),
  time = rep(1:n_periods, n_units),
  treated = rep(c(0, 1), each = n_units/2 * n_periods),
  post = as.numeric(time > treatment_period),
  outcome = y
)

# DiD regression with fixed effects
did_model <- feols(outcome ~ treated * post | id + time, 
                   data = panel_data)

# The coefficient on 'treated:post' is the DiD estimate
summary(did_model)

# Event study (test parallel trends)
event_study <- feols(outcome ~ i(time, treated, ref = treatment_period) | id + time,
                     data = panel_data)
iplot(event_study)  # Should be flat pre-treatment

โœ… Key Takeaways

  • โ€ข DiD estimates causal effects from observational data
  • โ€ข Parallel trends assumption is critical
  • โ€ข Compare CHANGES, not levels
  • โ€ข Use when randomization isn't possible
  • โ€ข Validate with pre-treatment trend tests
  • โ€ข Works for policy/feature rollouts

Pricing Models & Frameworks Tutorial

Built for mastery ยท Interactive learning