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.1.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.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mad_sdid-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 24f82cc494ab780077b90498f563c145d8590031ad0726a457d735ceb1b0f0a4
MD5 e382a8de86f8564b44ade33aed184f95
BLAKE2b-256 43fa1186aa0340e5ea41d2b74dba40515e5dc2c2b1db83870b5b61aa81fec138

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mad_sdid-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9771fedc20b297181c2b3509d55ff950a5915ece1e8bca86b98937b3b1b0cdbf
MD5 74a6bedc7c87561c105f0870ec0fe6ad
BLAKE2b-256 89208b0915280aa4e22c1ddceb1bd1fd21ec3535b96536dcca14ea582f5b77fd

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