Skip to main content

Synthetic Difference in Differences (Arkhangelsky et al.)

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mad_sdid-0.2.0.tar.gz (133.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mad_sdid-0.2.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file mad_sdid-0.2.0.tar.gz.

File metadata

  • Download URL: mad_sdid-0.2.0.tar.gz
  • Upload date:
  • Size: 133.8 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for mad_sdid-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ec912f97424207d8331c673c39668c8a99f69681cd70ea0fbbc5228e37a89730
MD5 bd08f07742b85e10975fb825db378e32
BLAKE2b-256 2f5afbb9ca025b5b8fc798cf60b3ecf9f272650da5d1e93a60f85d39d722f44e

See more details on using hashes here.

File details

Details for the file mad_sdid-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mad_sdid-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for mad_sdid-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f27658bca8b045939ee35e547fa6989ac25fdfdc1e63eb1ffe67dfc3fb826ca2
MD5 35b4a23eca4813577b32fbb01780a324
BLAKE2b-256 680e43ba06b65b5e00e3751dd2ce20032315223a10c4168ecb65e6755c90780e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page