Causal Inference in Python: How to Choose a Method

A decision tree for picking a causal inference method in Python, with links to tutorials on difference-in-differences, synthetic control, regression discontinuity, interrupted time series and propensity scores.

The right causal inference method depends on how treatment was assigned and what data you have. If you can randomize, run an A/B test. If treatment was set by a cutoff, use regression discontinuity. If you have untreated units over time, use difference-in-differences or synthetic control. If you only have the treated group before and after, use interrupted time series. If you only have one cross-section, use propensity scores. Each method has a tutorial with seeded data and a chart of the effect.

Flowchart for choosing a causal inference method: randomize leads to an A/B test, a sharp cutoff leads to regression discontinuity, untreated units over time lead to synthetic control or difference-in-differences, a treated group alone leads to interrupted time series, and a cross-section leads to propensity score matching

Which Method Fits My Data?

Situation Method Key chart Tutorial
Treated and comparison groups, observed before and after Difference-in-differences Parallel-trends plot Difference-in-Differences
Treatment rolled out in waves, effect builds over time Event study (staggered DiD) Leads and lags plot Event Study Plot
One treated unit, many possible comparison units, long history Synthetic control Treated vs synthetic line, placebo plot Synthetic Control
Treatment switches on at a threshold of a score Regression discontinuity RD plot with a jump at the cutoff Regression Discontinuity
Only the treated group, with a clear start date Interrupted time series Fitted trend and counterfactual Interrupted Time Series
One treated series plus unaffected control series, long history CausalImpact-style structural time series Forecast counterfactual, cumulative effect CausalImpact in Python
Randomized encouragement, but only some users take up the treatment, or an unmeasured confounder Instrumental variables (2SLS) First stage and OLS vs 2SLS comparison Instrumental Variables
One snapshot, treatment chosen by observable traits Propensity score matching or IPW Love plot Propensity Score Matching
Observational data, many confounders with non-linear effects Double machine learning Residual-on-residual fit, comparison with plain OLS Double Machine Learning with DoubleML

What Each Method Assumes

Method Main assumption How to check it
Difference-in-differences Parallel trends: without treatment, both groups would have moved together Plot the pre-period trends
Synthetic control A weighted mix of donors can reproduce the treated unit before treatment Pre-period fit, then placebo tests on the donors
Regression discontinuity Units just either side of the cutoff are comparable and cannot manipulate the score Plot the data near the cutoff, vary the bandwidth
Interrupted time series No other change coincides with the start date, and the trend is modeled correctly Plot the counterfactual, try different trend shapes
CausalImpact-style model Controls are unaffected by the change, and their relationship to the target stays stable Placebo dates; expect intervals that are optimistic
Double machine learning Every confounder is measured and in the covariates, and treatment varies given them Compare with linear controls; try several learners and split seeds
Instrumental variables The instrument shifts treatment and affects the outcome only through it First-stage F statistic, plus an argument for exclusion
Propensity scores No unmeasured confounders Covariate balance plot, sensitivity analysis

The last row is the strongest assumption. A propensity score can only balance the traits you measured, so it is usually the method of last resort when nothing better is available.

Start with the Weakest Design That Answers the Question

Pre/post comparisons mislead because they credit the treatment with everything else that changed at the same time. The interrupted time series post shows this with a metric that was already trending upward before launch. Adding a comparison group (difference-in-differences) or a modeled counterfactual (synthetic control) removes most of that bias.

The synthetic control post uses placebo tests: apply the same method to every untreated donor and ask how unusual the treated unit's gap is. With 24 donors, the smallest p-value you can report is 1/25 = 0.04, and the post points this out.

Practical Tips

  • Draw the data before choosing a method. Most of the assumptions in the table above can be seen in a plot.
  • State the assumption in plain words next to the estimate, so a reader knows what to challenge.
  • Report an interval, and show a falsification check (placebo, pre-trend or balance plot) alongside it.
  • If you can randomize, do. The A/B testing guide covers the analysis.

Similar Topics