Difference-in-Differences

Advanced Analytics Causal Inference

Estimate whether a campaign, launch or price change really moved results, by comparing the markets that got it with similar markets that didn’t.

👨‍🏫 Professor Mode: Guided Learning Experience

New to Difference-in-Differences? Professor Mode walks you through the 2×2 logic, the counterfactual trend line, the pre-period check, and why a naive DiD can easily manufacture a fake lift.

OVERVIEW & WHAT THIS TOOL SOLVES

Most geo-experiments, store remodels, and regional TV flights cannot be randomized at the individual shopper level. Comparing test markets before vs. after launch wrongly credits macro seasonality, while comparing test vs. control markets after launch wrongly credits pre-existing city size differences. Difference-in-Differences (DiD) subtracts the control group's pre-to-post trend from the treated group's pre-to-post jump to isolate the true incremental lift above the counterfactual trajectory.

🎯 Questions It Answers

  • How much of the post-launch sales jump in our treated markets was truly caused by the intervention vs. background market drift?
  • Did Treated and Control markets move along parallel trajectories during the pre-launch periods?
  • How does the treatment effect evolve week-by-week after launch (immediate spike, gradual ramp, or habituation)?

📂 What Data You Need

  • Panel Dataset: Repeated observations across multiple units (stores, DMAs, states) over pre- and post-treatment periods
  • Treatment Assignment: A binary indicator marking which units received the intervention and the exact launch period
  • Optional Covariates: Time-varying local controls (e.g., weather, local promos) or transition-window exclusions

💡 What You'll Discover

  • 2×2 & Two-Way Fixed Effects Lift: Point estimate of causal lift (ATT), cluster-robust SEs, and randomization-inference p-values
  • Event-Study Lead/Lag Plot: Period-by-period dynamic coefficients testing pre-trends and post-launch dynamics
  • Pre-Trend Diagnostics: Joint Wald test on pre-launch leads and MDE sensitivity for small market counts
🔍 Key Nuances & Common Traps to Watch For
  • The Unprovable Parallel Trends Assumption: DiD assumes that without the campaign, Treated and Control units would have changed by the exact same amount. Always inspect the Event-Study pre-launch leads to verify they tracked together before launch.
  • Non-Significant Pre-Trends ≠ Proven Parallel Trends: With only 6 to 10 DMAs, a pre-trend test has low statistical power. Check both the joint lead p-value and the visual magnitude of pre-launch drift relative to your post-launch effect.
  • Cluster Standard Errors at the Unit Level: Weekly sales within the same store are serially correlated; failing to cluster by unit (or use Randomization Inference when cluster counts are small) severely understates uncertainty.
📐 Under the Hood: Model Equations & Variable Definitions

1. Canonical 2×2 Difference-in-Differences Estimator

\[ \hat{\delta}_{\text{DiD}} = \left(\bar{Y}_{\text{Treat, Post}} - \bar{Y}_{\text{Treat, Pre}}\right) - \left(\bar{Y}_{\text{Ctrl, Post}} - \bar{Y}_{\text{Ctrl, Pre}}\right) \]

💬 Read it in plain English: Take the average pre-to-post change in the treated markets and subtract the average pre-to-post change in the untreated control markets to strip out both baseline level differences and shared time drift.

ȲTreat,Pre, ȲTreat,Post
Treated Group MeansYOUR DATA ⓘ
Average outcome in treated units before and after the intervention.
ȲCtrl,Pre, ȲCtrl,Post
Control Group MeansYOUR DATA ⓘ
Average outcome in untreated control units over the exact same pre and post windows.
δ̂DiD
Estimated Causal Lift (ATT)OUTPUT ⓘ
Average Treatment Effect on the Treated isolated above the parallel counterfactual trend.

2. Two-Way Fixed Effects (TWFE) & Dynamic Event-Study Specification

\[ Y_{it} = \alpha_i + \lambda_t + \delta\,\left(D_i \times \text{Post}_t\right) + \mathbf{X}_{it}^\top\boldsymbol{\beta} + \varepsilon_{it}, \qquad Y_{it} = \alpha_i + \lambda_t + \sum_{k \neq -1} \gamma_k\,\mathbb{I}(t - t_0 = k)\cdot D_i + \varepsilon_{it} \]

💬 Read it in plain English: Unit fixed effects (α_i) absorb permanent store/city differences and time fixed effects (λ_t) absorb common period shocks, while event-study coefficients γ_k trace out pre-launch parallel trends (k < 0) and post-launch lift dynamics (k ≥ 0).

Yit
Unit-Period OutcomeYOUR DATA ⓘ
Observed metric (e.g., sales, conversions) for unit i in period t.
αi, λt
Unit & Time Fixed EffectsESTIMATED ⓘ
Time-invariant unit baseline α_i and common period shock λ_t shared across all units.
Di, Postt
Treatment & Post IndicatorsYOUR DATA ⓘ
Binary indicators for treated group membership (D_i = 1) and post-launch period (Post_t = 1).
γk
Dynamic Event-Study Leads/LagsINFERENCE ⓘ
Period-specific difference at relative time k from launch (normalized against reference period k = −1).

Step 1 CHOOSE YOUR DATA & MODE

Work with panel data (markets tracked over time) or start with a textbook Quick 2×2 calculation.

📚

Use a Case Study

📤

Upload Your Data

Upload panel CSV data

Provide a long-format CSV with at least four columns: market, period, outcome, and a market-level treated indicator (0 or 1).

Drag & Drop CSV file (.csv, .tsv, .txt, .xls, .xlsx)

Include headers with market, period, outcome, and treated columns.

No file uploaded.
Measurement Level & Panel Requirements:
  • Outcome: Continuous numerical scale (e.g. sales revenue, orders, app sessions, visits). Do not use nominal categories or qualitative choices as the outcome.
  • Market: Categorical cluster identifier (store ID, city, DMA, territory) tracked over time.
  • Period: Ordered integer time steps (1, 2, 3...) or consecutive calendar intervals.
  • Treated: Binary indicator (1 = test market receiving treatment, 0 = control market).

Step 2 CONFIGURE COLUMN ROLES & SETTINGS

Verify column mappings and declare the campaign launch period.

The first period when the campaign is active in test markets.

Shown on charts and in managerial reports.

Advanced Diagnostics: Placebo & Transition Periods

In-time falsification test: a real campaign cannot have worked before it started.

Exclude disruption/anticipation period immediately prior to launch (e.g. construction).

🤔 Try This: Three Revealing Experiments

  1. Decompose the Textbook Case: In Quick 2×2 mode, see how the $45K test gain ($420K → $465K) separates into $15K of market trend ($400K → $415K) and exactly $30K of true DiD lift.
  2. Catch the Selection Trap in Pinnacle Fitness: Load Pinnacle Fitness and click Estimate the Effect. Naive DiD claims a lift of +$2,377. Now open the Pre-period check tab: see the pre-trend test fail completely (\(p < .001\)), proving the lift was an illusion.
  3. Diagnose Anticipation in Oakline Furniture: Load Oakline Furniture. Notice the sharp dip at \(r = -1\) (month 9) from renovation closures. Then open Advanced Diagnostics and exclude month 9.

Augmented Data Pipeline Export

Download the full augmented dataset with fitted values, counterfactuals, and estimated causal lifts appended to every observation, or use the code export bar below to download or copy the standalone Python script.

Exploratory Questions for Marketing Analysts