Skip to main content

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
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.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
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.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();

png

california_estimate.plot_weights();

png

Quota

quota_estimate = sdid(quota(), "country", "year", "quota", "womparl").fit()
quota_estimate.vcov().summary().summary2 ## placebo 
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.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
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.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
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.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>

png

png

png

png

png

png

png

quota_cov_est.plot_weights()
<synthdid.synthdid.Synthdid at 0x2313747f880>

png

png

png

png

png

png

png

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

synthdid-0.10.1.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

synthdid-0.10.1-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file synthdid-0.10.1.tar.gz.

File metadata

  • Download URL: synthdid-0.10.1.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.5

File hashes

Hashes for synthdid-0.10.1.tar.gz
Algorithm Hash digest
SHA256 483e23c0d12ff7a8e7225acc86c6e37bad7e8367d3b8dd4b9aa9a297bd789221
MD5 6a91e68fee06c42a5c4179de34505a83
BLAKE2b-256 ff9178a40a3e6aafc1b3b8a65c7e5e2a2ffeaa831c0d70823938c11ff14c9906

See more details on using hashes here.

File details

Details for the file synthdid-0.10.1-py3-none-any.whl.

File metadata

  • Download URL: synthdid-0.10.1-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.5

File hashes

Hashes for synthdid-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a4f4d711bab01501f50532dbf4781892114b4775d5210c413a1379ca6799e8e5
MD5 1bd71f5533e0078e7c67fa0e2a5a5edb
BLAKE2b-256 91370ab7b990f831973b2d11e2b4a64895ce7c4aaa03d7db9ff4a6640b4d7885

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