Skip to main content

SDID — Synthetic Difference in Differences

Python arXiv PyPI License

⚠️ Pre-release — This implementation is not fully tested against the paper's full simulation suite. The API and numerical defaults are subject to breaking changes without notice. Use at your own risk.

Python implementation of the synthetic difference-in-differences estimator from Arkhangelsky, Athey, Hirshberg, Imbens & Wager (2021).

Quick start (cloned repo with test data)

import pandas as pd
from mad_sdid import synthdid_estimate, panel_matrices

panel = pd.read_csv("tests/data/california_prop99.csv", sep=";")
setup = panel_matrices(panel, unit="State", time="Year",
                       outcome="PacksPerCapita", treatment="treated")
result = synthdid_estimate(setup["Y"], setup["N0"], setup["T0"])
print(f"tau_hat = {result.estimate:.2f}")

Installation

pip install mad-sdid

Dev extras (cvxpy reference solver):

pip install "mad-sdid[dev]"

Using with your own data

Your panel must be a balanced CSV with the following columns:

  • unit: unit identifier
  • time: time period
  • outcome: outcome variable
  • treatment: binary indicator (0 = control, 1 = treated)

All treated units must share the same treatment onset time.

import pandas as pd
from mad_sdid import synthdid_estimate, synthdid_summary, panel_matrices

panel = pd.read_csv("my_data.csv")
setup = panel_matrices(panel, unit="unit", time="time",
                       outcome="outcome", treatment="treatment")

# Point estimate only
result = synthdid_estimate(setup["Y"], setup["N0"], setup["T0"])
print(f"tau_hat = {result.estimate:.2f}")

# Full results: τ̂, SE, CI, p-values
s = synthdid_summary(setup["Y"], setup["N0"], setup["T0"])
print(f"SE = {s['se']:.2f}, 95% CI = {s['ci']}, p = {s['p_value_two_sided']:.3f}")

Input format

unit time outcome treatment
Alabama 1970 89.8 0
California 1970 123.0 0
... ... ... ...
California 1989 76.5 1

The first N0 rows of the outcome matrix are control units, and the first T0 columns are pre-treatment periods — done automatically by panel_matrices().

Reference

Arkhangelsky, D., Athey, S., Hirshberg, D. A., Imbens, G. W., & Wager, S. "Synthetic Difference in Differences." American Economic Review, 2021. arXiv:1812.09970

Metadata

Release files for mad-sdid 0.2.1

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

Source distribution (sdist)

Source distribution for mad-sdid 0.2.1
File Size Uploaded Provenance Actions
mad_sdid-0.2.1.tar.gz 133.8 kB Without provenance Details for mad_sdid-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mad-sdid 0.2.1
File Interpreter ABI Platform Actions
mad_sdid-0.2.1-py3-none-any.whl Python 3 none any Details for mad_sdid-0.2.1-py3-none-any.whl

Total release size: 143.7 kB

Release files / mad_sdid-0.2.1.tar.gz

Download URL mad_sdid-0.2.1.tar.gz
Size 133.8 kB
Tags Source
SHA-256 checksum
How to use checksums
24f82cc494ab780077b90498f563c145d8590031ad0726a457d735ceb1b0f0a4
BLAKE2b-256 checksum
How to use checksums
43fa1186aa0340e5ea41d2b74dba40515e5dc2c2b1db83870b5b61aa81fec138
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / mad_sdid-0.2.1-py3-none-any.whl

Download URL mad_sdid-0.2.1-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9771fedc20b297181c2b3509d55ff950a5915ece1e8bca86b98937b3b1b0cdbf
BLAKE2b-256 checksum
How to use checksums
89208b0915280aa4e22c1ddceb1bd1fd21ec3535b96536dcca14ea582f5b77fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for mad-sdid 0.2.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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