sythdid: Synthetic Difference in Difference Estimation
This package implements the synthetic difference-in-differences estimation procedure, along with a range of inference and graphing procedures, following the work of the author. The package draws on R and Julia code for optimization and Stata code for implementation in contexts with staggered adoption over multiple treatment periods (as well as in a single adoption period as in the original code). The package extends the functionality of the original code, allowing for estimation in a wider range of contexts. Overall, this package provides a comprehensive toolkit for researchers interested in using the synthetic difference-in-differences estimator in their work.
Instalation
pip install synthdid
Usage
Class input Synthdid
outcome: Outcome variable (numeric)unit: Unit variable (numeric or string)time: Time variable (numeric)quota: Dummy of treatement, equal to 1 if units are treated, and otherwise 0 (numeric)
Methods:
.fit(cov_method = ["optimized", "projected"]).vcov(method = ["placebo", "bootstrap", "jackknife"], n_reps:int = 50)
Example
California
import matplotlib.pyplot as plt
import numpy as np, pandas as pd
from synthdid.synthdid import Synthdid as sdid
from synthdid.get_data import quota, california_prop99
pd.options.display.float_format = '{:.4f}'.format
Estimations with Standard Variance-Covariance Estimation
california_estimate = sdid(california_prop99(), unit="State", time="Year", treatment="treated", outcome="PacksPerCapita").fit().vcov(method='placebo')
california_estimate.summary().summary2
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
| ATT | Std. Err. | t | P>|t| | |
|---|---|---|---|---|
| 0 | -15.6038 | 9.6862 | -1.6109 | 0.1072 |
Estimations without Standard Variance-Covariance Estimation
california_estimate = sdid(california_prop99(), "State", "Year", "treated", "PacksPerCapita").fit()
california_estimate.summary().summary2
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
| ATT | Std. Err. | t | P>|t| | |
|---|---|---|---|---|
| 0 | -15.6038 | - | - | - |
Plots
To avoid messages from matplotlib, a semicolon ; should be added at the end of the function call.
This way:
estimate.plot_outcomes();estimate.plot_weights();
california_estimate.plot_outcomes();
california_estimate.plot_weights();
Quota
quota_estimate = sdid(quota(), "country", "year", "quota", "womparl").fit()
quota_estimate.vcov().summary().summary2 ## placebo
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
| ATT | Std. Err. | t | P>|t| | |
|---|---|---|---|---|
| 0 | 8.0341 | 1.8566 | 4.3272 | 0.0000 |
With covariates
quota_cov = quota().dropna(subset="lngdp")
quota_cov_est = sdid(quota_cov, "country", 'year', 'quota', 'womparl', covariates=['lngdp']).fit()
quota_cov_est.summary().summary2
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
| ATT | Std. Err. | t | P>|t| | |
|---|---|---|---|---|
| 0 | 8.0490 | - | - | - |
Covariable method = 'projected'
quota_cov_est.fit(cov_method="projected").summary().summary2
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
| ATT | Std. Err. | t | P>|t| | |
|---|---|---|---|---|
| 0 | 8.0590 | - | - | - |
quota_cov_est.plot_outcomes()
<synthdid.synthdid.Synthdid at 0x2313747f880>
quota_cov_est.plot_weights()
<synthdid.synthdid.Synthdid at 0x2313747f880>
Metadata
Release files for synthdid 0.10.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| synthdid-0.10.1.tar.gz | 16.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| synthdid-0.10.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.4 kB
Release files / synthdid-0.10.1.tar.gz
| Download URL | synthdid-0.10.1.tar.gz |
|---|---|
| Size | 16.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
483e23c0d12ff7a8e7225acc86c6e37bad7e8367d3b8dd4b9aa9a297bd789221
|
|
BLAKE2b-256 checksum How to use checksums |
ff9178a40a3e6aafc1b3b8a65c7e5e2a2ffeaa831c0d70823938c11ff14c9906
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.11.5
|
Release files / synthdid-0.10.1-py3-none-any.whl
| Download URL | synthdid-0.10.1-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a4f4d711bab01501f50532dbf4781892114b4775d5210c413a1379ca6799e8e5
|
|
BLAKE2b-256 checksum How to use checksums |
91370ab7b990f831973b2d11e2b4a64895ce7c4aaa03d7db9ff4a6640b4d7885
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.11.5
|