Synthdid
Project description
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.5733 | -1.6299 | 0.1031 |
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>
Plots
california_estimate.plot_outcomes();
california_estimate.plot_weights()
d:\work\synthdid.py\synthdid\plots.py:136: UserWarning: FixedFormatter should only be used together with FixedLocator
ax.set_xticklabels(units, rotation = 90, fontsize = ns);
<synthdid.synthdid.Synthdid at 0x247c18bd340>
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.9112 | 4.2037 | 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 0x247f469aeb0>
quota_cov_est.plot_weights()
d:\work\synthdid.py\synthdid\plots.py:136: UserWarning: FixedFormatter should only be used together with FixedLocator
ax.set_xticklabels(units, rotation = 90, fontsize = ns);
d:\work\synthdid.py\synthdid\plots.py:136: UserWarning: FixedFormatter should only be used together with FixedLocator
ax.set_xticklabels(units, rotation = 90, fontsize = ns);
d:\work\synthdid.py\synthdid\plots.py:136: UserWarning: FixedFormatter should only be used together with FixedLocator
ax.set_xticklabels(units, rotation = 90, fontsize = ns);
d:\work\synthdid.py\synthdid\plots.py:136: UserWarning: FixedFormatter should only be used together with FixedLocator
ax.set_xticklabels(units, rotation = 90, fontsize = ns);
d:\work\synthdid.py\synthdid\plots.py:136: UserWarning: FixedFormatter should only be used together with FixedLocator
ax.set_xticklabels(units, rotation = 90, fontsize = ns);
d:\work\synthdid.py\synthdid\plots.py:136: UserWarning: FixedFormatter should only be used together with FixedLocator
ax.set_xticklabels(units, rotation = 90, fontsize = ns);
d:\work\synthdid.py\synthdid\plots.py:136: UserWarning: FixedFormatter should only be used together with FixedLocator
ax.set_xticklabels(units, rotation = 90, fontsize = ns);
<synthdid.synthdid.Synthdid at 0x247f469aeb0>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.