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 & LEARNING OBJECTIVES

Most marketing interventions cannot be randomized at the individual customer level: a regional TV flight airs in specific DMAs, store renovations happen in selected locations, or a mobile app rollout debuts in test cities first. When stakeholders ask “did it work?”, the two most common answers are almost always wrong:

1. Before vs. After

Wrongly credits everything else that happened.

Comparing test stores before and after launch credits the campaign with seasonality, macroeconomic growth, competitor supply disruptions, and general category momentum.

2. Test vs. Control After

Wrongly credits differences that were always there.

Comparing test stores to control stores after launch credits the campaign with pre-existing market size, demographic advantages, and brand maturity that existed long before the launch.

3. Difference-in-Differences

Subtracts both to isolate the true incremental lift.

DiD takes the test group’s change and subtracts the control group’s change. The remainder is the lift that occurred above and beyond what test stores would have done anyway.

The Core Parallel Trends Assumption

The entire validity of DiD rests on one unprovable assumption: without the campaign, the test and control groups would have moved along parallel paths. You can never prove this would have held into the future, but you can check whether they moved together in the pre-period. The pre-period check is the single most important diagnostic on this page.

🎯 What You’ll Learn
  • How to subtract the counterfactual trend: Decompose a $45K sales jump into $15K of market drift and $30K of incremental campaign lift.
  • Why non-significant pre-trends do not prove parallel trends: With few markets, statistical power is low. You must inspect both the joint lead test and the lead magnitude ratio.
  • Why small market counts require honest inference: With 4 to 8 test cities, standard errors are noisy; randomization inference provides exact, truthful confidence bounds.
  • How anticipation and transition periods distort findings: Detect pre-launch disruption (e.g. renovation dips) and adjust the transition window.

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.

Reproducible Python Export & Data Pipeline

Export a standalone, executable Python script using pandas and statsmodels with Liang-Zeger cluster-robust standard errors, or download the full augmented dataset with fitted values, counterfactuals, and estimated causal lifts appended to every observation.

Exploratory Questions for Marketing Analysts