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}")

# Jackknife standard error
import numpy as np
from mad_sdid.inference import vcov_synthdid
se = np.sqrt(vcov_synthdid(result, method="jackknife"))
print(f"SE = {se:.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
import numpy as np
from mad_sdid import synthdid_estimate, panel_matrices
from mad_sdid.inference import vcov_synthdid

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

result = synthdid_estimate(setup["Y"], setup["N0"], setup["T0"])
se = np.sqrt(vcov_synthdid(result, method="jackknife"))

print(f"tau_hat = {result.estimate:.2f}")
print(f"SE = {se:.2f}")
print(f"95% CI = ({result.estimate - 1.96 * se:.2f}, {result.estimate + 1.96 * se:.2f})")

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.1.0.tar.gz (72.0 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.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mad_sdid-0.1.0.tar.gz
  • Upload date:
  • Size: 72.0 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.1.0.tar.gz
Algorithm Hash digest
SHA256 148763db926b458f005fa78afa2218129e474c92d026af5030b9234ff3706263
MD5 db75534d2151fefbb94ef159cf6d4fd7
BLAKE2b-256 d7d680178b68af93c694cd618795d1dca69a17b86d878e6ecc34c61c5b95588b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mad_sdid-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac8e4630601487c6478cef350d6551a8ae857393d6b4dbb60a3b4eea1c0c9aab
MD5 102bdb70fe6eb7911e10db8eb6247736
BLAKE2b-256 f078659ea97945827f1af59db65efdc438a591566bed89beb80b0f8a85c9ce85

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