Daniel-Pailanir / sdid

Synthetic Difference in Differences for Stata
GNU General Public License v3.0
72 stars 36 forks source link

Stata GitHub Starts GitHub forks issues issues close GitHub license

sdid -- Synthetic Difference-in-Differences for Stata

This Stata package implements the synthetic difference-in-differences estimation procedure, along with a range of inference and graphing procedures, following Arkhangelsky et al., (2021). Arkhangelsky et al. provide a code implementation in R, with accompanying materials here: synthdid. Here we provide a native Stata implementation, principally written in Mata. This package extends the funcionality of the original R package, allowing very simply for estimation in contexts with staggered adoption over multiple treatment periods (as well as in a single adoption period as in the original code). Some further details can be found in the accompanying working paper here.

[!Tip] If you wish to implement Event Study analysis with SDiD, please check out sdid_event and its technical note.

To install directly into Stata:

ssc install sdid, replace

or using net install command:

net install sdid, from("https://raw.githubusercontent.com/daniel-pailanir/sdid/master") replace

Inputs

Syntax

sdid Y S T D [if] [in], vce(method) seed(#) reps(#) covariates(varlist [, method])
                        zeta_lambda(real) zeta_omega(real) min_dec(real) max_iter(real)
                        method(methodtype) unstandardized graph_export([stub] , type) mattitles
                        graph g1on g1_opt(string) g2_opt(string) msize() 

Running an example

webuse set www.damianclarke.net/stata/
webuse prop99_example.dta, clear

#delimit ;
sdid packspercapita state year treated, vce(placebo) reps(100) seed(123) 
     graph g1on g1_opt(xtitle("") ylabel(-35(5)10) scheme(plotplainblind)) 
     g2_opt(ylabel(0(50)150) xlabel(1970(5)2000) ytitle("Packs per capita") 
            xtitle("") text(125 1995 "ATT = -15.604" " SE = (9.338)") scheme(plotplainblind))
    graph_export(sdid_, .png);
#delimit cr

The code returns the following results

Placebo replications (100). This may take some time.
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................     50
..................................................     100

Synthetic Difference-in-Differences Estimator

-----------------------------------------------------------------------------
packsperca~a |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
   treatment | -15.60383    9.33752    -1.67    0.095   -33.90504     2.69738
-----------------------------------------------------------------------------
95% CIs and p-values are based on Large-Sample approximations.
Refer to Arkhangelsky et al., (2020) for theoretical derivations.
(file sdid_weights1989.eps written in EPS format)
(file sdid_trends1989.eps written in EPS format)

To export results, you can use eststo and esttab:

*create a uniform variable to use as a control
gen r=runiform()

*run sdid
eststo sdid_1: sdid packspercapita state year treated, vce(placebo) seed(2022)
eststo sdid_2: sdid packspercapita state year treated, vce(placebo) seed(2022) covariates(r, projected)

*create a table
esttab sdid_1 sdid_2, starlevel ("*" 0.10 "**" 0.05 "***" 0.01) b(%-9.3f) se(%-9.3f)

The code returns the following results

--------------------------------------------
                      (1)             (2)   
             packsperca~a    packsperca~a   
--------------------------------------------
treated           -15.604*        -15.750*  
                  (7.981)         (8.039)   
--------------------------------------------
N                    1209            1209   
--------------------------------------------
Standard errors in parentheses
* p<0.10, ** p<0.05, *** p<0.01

Acknowledgments

We are grateful to Noah Spencer, Jared Greathouse and Asjad Naqvi for very useful feedback related to this code. We are also very grateful to many other users who have suggested a range of useful extensions and filed bug reports which have made this code better.

References

Arkhangelsky, D., Athey, S., Hirshberg, D., Imbens, G., Wager, S. (2019) Synthetic difference in differences, American Economic Review, December 2021.

Ciccia, D. (2024) A Short Note on Event-Study Synthetic Difference-in-Differences Estimators

Clarke, D. Pailanir, D. Athey, S., Imbens, G. (2023) Synthetic difference in differences estimation, IZA Discussion Paper, January 2023.