Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PySynthCon — Synthetic control in Python. After California’s tobacco tax, cigarette sales averaged 15.6 fewer packs per person per year than its synthetic counterfactual, 1989–2000.

PyPI beta Documentation Tests and documentation Python 3.10 and newer License GPL-3.0-only Purpose Research

Quick start · Six worked examples · Estimators · Documentation

PySynthCon lets you fit several synthetic controls to the same panel and see how the estimated effect changes with the method or donor pool. Compare held-out pretreatment predictions, refit after excluding donors, and put published benchmarks beside the estimates that reproduce them.

Quick start

Install the 0.1 beta with Python 3.10 or newer. The distribution is pysynthcon and the Python import is pysynth.

python -m pip install "pysynthcon[plot]==0.1.0b2"

California introduced its tobacco-control program in 1989. Use the same states and years to fit outcome-matching synthetic control (SCM) and synthetic difference-in-differences (SDID).

from pysynth import SyntheticControl, SyntheticDID, compare, plot_effects, save_figure
from pysynth.datasets import DATASETS, load_dataset

panel = DATASETS["california"].panel(load_dataset("california"))
fits = {"SCM": SyntheticControl().fit(panel), "SDID": SyntheticDID().fit(panel)}

print(compare(fits)[["att", "pre_rmse"]])
fig, axes = plot_effects(fits, ylabel="Effect on sales (packs per capita)", xlabel="Year")
save_figure(fig, "outputs/custom/california-effects")

The SDID estimate is −15.60 packs per capita per year, averaged over 1989–2000. Effects are observed outcomes minus estimated untreated outcomes. The reference fit reports an iteration-limit warning for one set of weights and reproduces the original R estimate. California notebook · SDID convergence and inference

For your own data, Panel.from_frame takes unit, time and outcome columns, an explicit treatment date and an optional donor list. The treatment date is the first affected observation. Panels are balanced and use a common onset within each panel. ISC and 2SISC also accept case-specific panels and aggregate in event time. Prepare a panel

Six worked examples

Open the notebook What to look for
California · tobacco control Recover the published SDID effect of −15.6 packs per person and SE of 8.4. With the original tobacco predictors, both R Synth and the Python optimizer rank California first of 39. Allowing one state to be twice as likely to receive treatment puts the reassignment p-value between 0.013 and 0.050.
Basque Country · conflict Recover the published SCM donor weights for Catalonia (0.8508) and Madrid (0.1492), and compare the GDP path with the original R fit.
West Germany · reunification Rebuild the historical predictor specification and compare the GDP gap with the paper’s roughly US$1,600 annual loss per person (1990–2003, PPP-adjusted).
Kansas · tax cuts Match the authors’ ridge-augmented SCM vignette at −0.0401 log points and check all 16 quarterly effects.
Rhode Island · decriminalization of indoor sex work Test a six-year effect path against every cyclic shift in time. Reproduce the joint p-value of 0.04 and the six annual pointwise confidence sets for female gonorrhea incidence.
Simulation · donor spillovers Across 200 economies with a known +6-point effect, spillovers shift full-pool SCM by −2.78 points on average while its pretreatment fit stays identical.

Four studies compare eleven estimators on a common panel. Rhode Island focuses on inference for outcome-matching SCM. All five empirical notebooks download hash-verified data into memory. Rhode Island and the simulation both run entirely in Python. The simulation generates its own data. Figures are embedded in the notebooks. Executing them also writes PDF, SVG, PNG and numerical tables under outputs/empirical_examples/<study>/ or outputs/simulated_examples/donor_spillovers/. Reference targets and tolerances · Figure exports

git clone --branch v0.1.0b2 --depth 1 https://github.com/crahal/pysynthcon.git
cd pysynthcon
python -m pip install -e ".[notebooks]"
python scripts/execute_notebooks.py --examples rhode_island donor_spillovers

For all six notebooks, use Python 3.11 or 3.12, install the pinned replication requirements and provision the separately supplied local R reference bundle. SCUL and vanilla ISC use the original R backends. The California reassignment comparison also requires local R Synth 1.1-10 and the optional rpy2 bridge. Reproducing the California paper’s exact placebo sampling plan also uses the bundle. Once provisioned, python scripts/execute_notebooks.py runs all six. Local R setup

Estimators

Method Python interface What determines the counterfactual
Outcome-matching SCM SyntheticControl() Convex weights match the full pretreatment outcome path, with equal weight on each period. This is an outcome-only specification of classical SCM.
Predictor-based SCM PredictorSyntheticControl() Convex weights balance predictors. Their relative importance can be fitted against pretreatment outcomes. Abadie & Gardeazabal (2003) · Abadie, Diamond & Hainmueller (2010)
Ridge-augmented SCM AugmentedSyntheticControl() A ridge outcome model corrects residual imbalance. Donor weights can be negative. Ben-Michael, Feller & Rothstein (2021)
Penalized SCM PenalizedSyntheticControl(lambda_=0.01) A pairwise penalty discourages weight on donors far from the treated unit in predictor space. Abadie & L’Hour (2021)
Differenced SCM DifferencedSyntheticControl() Fit changes, then restore the average pretreatment level gap. The default uses zero pairwise penalty. Engelbrektson (2021), working paper
Robust SCM RobustSyntheticControl(lambda_=0.1, sv_count=3) Singular-value truncation denoises donor outcomes. Ridge weights fitted before treatment combine the denoised donor series. Amjad, Shah & Shen (2018)
SCUL SCUL() Lasso with rolling-origin tuning, signed weights and an intercept. Hollingsworth & Wing (2020)
Individual synthetic control IndividualSC() Fit each treated individual against the full eligible donor pool. Vagni & Breen (2021)
Two-stage individual synthetic control TwoStageIndividualSC(n_neighbors=10) Screen the nearest donors on pretreatment features, then fit SCM in that group. Petrillo et al. (2025)
Synthetic difference-in-differences SyntheticDID() Weight both donors and pretreatment periods. Arkhangelsky et al. (2021)
Difference-in-differences DifferenceInDifferences() The comparison baseline uses uniform weights across donors and pretreatment periods.

The penalty and rank values shown above are example choices. Use python -m pip install "pysynthcon[backends]==0.1.0b2" for predictor-based, augmented, penalized and differenced SCM and the default 2SISC fit. Method definitions and tuning · Implementation credits and backend details

Compare specifications

select_estimator scores each candidate on the same withheld pretreatment periods and refits the selected candidate on the full panel. donor_sensitivity refits after each donor exclusion. Pass named groups to examine a possible spillover region, as in the simulation.

from pysynth import donor_sensitivity, select_estimator

candidates = {"SCM": SyntheticControl, "SDID": SyntheticDID}
selection = select_estimator(panel, candidates, initial_window=12, horizon=4)
print(selection.validation.summary)
print(donor_sensitivity(panel, candidates).summary)

plot_comparison aligns ATT estimates with pretreatment RMSE, and plot_effects preserves a common outcome scale across methods. Both return editable Matplotlib figures. Evaluation guide · Plotting guide

Is the effect unusual across units or across time?

Use state reassignments when the comparison is across units. When the question concerns the timing of a particular effect path, impose that path on the treated outcome and compare its residuals across time. The methods make different assumptions. Inference guide

from pysynth import conformal_test
from pysynth.datasets import DATASETS, load_dataset

ri = DATASETS["rhode_island"].panel(load_dataset("rhode_island"))
test = conformal_test(ri, null_effect=0)
print(test.p_value)  # 0.04: one of 25 cyclic windows is at least as extreme
print(test.rotations.nlargest(3, "statistic"))

The Rhode Island notebook also tests each annual effect on the authors’ full grid. The spillover simulation applies the same sharp-path test to a known treatment effect and measures what happens when donors themselves respond to treatment. Rhode Island replication · Spillover experiment

Documentation

The full manual on Read the Docs includes the statistical methods, inference conventions, API and worked examples. The versioned documentation sources accompany the beta.

Authors · Charles Rahal, Anda Raluca Epure, and Daniel Valdenegro.

When publishing, cite PySynthCon together with the method papers and upstream packages used in your analysis. Software citation · Method references

Metadata

Release files for pysynthcon 0.1.0b2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysynthcon 0.1.0b2
File Size Uploaded Provenance Actions
pysynthcon-0.1.0b2.tar.gz 4.1 MB With provenance Details for pysynthcon-0.1.0b2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pysynthcon 0.1.0b2
File Interpreter ABI Platform Actions
pysynthcon-0.1.0b2-py3-none-any.whl Python 3 none any Details for pysynthcon-0.1.0b2-py3-none-any.whl

Total release size: 4.8 MB

Release files / pysynthcon-0.1.0b2.tar.gz

Download URL pysynthcon-0.1.0b2.tar.gz
Size 4.1 MB
Tags Source
SHA-256 checksum
How to use checksums
1429a6f3645ee0e91ed58501ae0127e56b3b579c16981cd14f412b57d4e26244
BLAKE2b-256 checksum
How to use checksums
a43d3c026998204ea43df17c0bad55c539867b85a656f0549ca715c893d9ae13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / pysynthcon-0.1.0b2-py3-none-any.whl

Download URL pysynthcon-0.1.0b2-py3-none-any.whl
Size 726.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78e7fb9affa05015b9ea1894df8ef1e70e8ebb042da6e803c187722d80c48f1b
BLAKE2b-256 checksum
How to use checksums
588a6eb54d3e7a5878a59ec77b6a3de4d1cc7491f5b60468fa59586c2ee3e7f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for pysynthcon 0.1.0b2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pysynthcon-0.1.0b2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page