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.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>
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.
Source Distribution
Built Distribution
Hashes for synthdid-0.10.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4f4d711bab01501f50532dbf4781892114b4775d5210c413a1379ca6799e8e5 |
|
MD5 | 1bd71f5533e0078e7c67fa0e2a5a5edb |
|
BLAKE2b-256 | 91370ab7b990f831973b2d11e2b4a64895ce7c4aaa03d7db9ff4a6640b4d7885 |