# Causal Inference in Python: How to Choose a Method

> Choose between difference-in-differences, synthetic control, regression discontinuity, interrupted time series and propensity score matching based on your data, with a flowchart and a tutorial for each method.

Source: https://www.pythoncharts.com/causal-inference/causal-inference-python-guide/ | Published: 2026-11-25 | Author: Alex Scott | Category: Causal Inference | Tags: causal inference, difference in differences, synthetic control, regression discontinuity, propensity score, interrupted time series, guide

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](https://www.pythoncharts.com/causal-inference/causal-inference-python-guide/images/causal-method-chooser.png)

## 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](https://www.pythoncharts.com/causal-inference/difference-in-differences-python/) |
| Treatment rolled out in waves, effect builds over time | Event study (staggered DiD) | Leads and lags plot | [Event Study Plot](https://www.pythoncharts.com/causal-inference/event-study-staggered-did-python/) |
| One treated unit, many possible comparison units, long history | Synthetic control | Treated vs synthetic line, placebo plot | [Synthetic Control](https://www.pythoncharts.com/causal-inference/synthetic-control-python/) |
| Treatment switches on at a threshold of a score | Regression discontinuity | RD plot with a jump at the cutoff | [Regression Discontinuity](https://www.pythoncharts.com/causal-inference/regression-discontinuity-python/) |
| Only the treated group, with a clear start date | Interrupted time series | Fitted trend and counterfactual | [Interrupted Time Series](https://www.pythoncharts.com/causal-inference/interrupted-time-series-python/) |
| One treated series plus unaffected control series, long history | CausalImpact-style structural time series | Forecast counterfactual, cumulative effect | [CausalImpact in Python](https://www.pythoncharts.com/causal-inference/causalimpact-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](https://www.pythoncharts.com/causal-inference/instrumental-variables-2sls-python/) |
| One snapshot, treatment chosen by observable traits | Propensity score matching or IPW | Love plot | [Propensity Score Matching](https://www.pythoncharts.com/causal-inference/propensity-score-matching-python/) |
| Observational data, many confounders with non-linear effects | Double machine learning | Residual-on-residual fit, comparison with plain OLS | [Double Machine Learning with DoubleML](https://www.pythoncharts.com/causal-inference/double-machine-learning-python/) |

## 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](https://www.pythoncharts.com/ab-testing/ab-testing-python-guide/) covers the analysis.

## Similar Topics

- [A/B Testing in Python: A Guide from Sample Size to Sequential Tests](https://www.pythoncharts.com/ab-testing/ab-testing-python-guide/)
- [Machine Learning Charts in Python](https://www.pythoncharts.com/machine-learning/machine-learning-python-guide/)
