Metadata-Version: 2.4
Name: mad-sdid
Version: 0.2.1
Summary: Synthetic Difference in Differences (Arkhangelsky et al.)
Project-URL: Homepage, https://codeberg.org/divinemadman/mad-sdid
Project-URL: Repository, https://codeberg.org/divinemadman/mad-sdid
Author: The mad-sdid authors
License: Copyright 2026 The mad-sdid authors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.11
Requires-Dist: numpy>=1.21
Requires-Dist: pandas>=1.3
Provides-Extra: dev
Requires-Dist: cvxpy>=1.9.1; extra == 'dev'
Requires-Dist: pytest>=9.1.0; extra == 'dev'
Description-Content-Type: text/markdown

# SDID — Synthetic Difference in Differences

[![Python](https://img.shields.io/badge/python-3.14+-blue.svg)]()
[![arXiv](https://img.shields.io/badge/arXiv-1812.09970-b31b1b.svg)](https://arxiv.org/abs/1812.09970)
[![PyPI](https://img.shields.io/badge/pypi-pending%20submission-yellow.svg)]()
[![License](https://img.shields.io/badge/license-MIT-green.svg)]()

> **⚠️ 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)

```python
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

```bash
pip install mad-sdid
```

Dev extras (cvxpy reference solver):

```bash
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.

```python
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](https://arxiv.org/abs/1812.09970)
