1 Star 0 Fork 15

李春莹/did2s_stata

forked from 连享会/did2s_stata 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
README.Rmd 3.17 KB
一键复制 编辑 原始数据 按行查看 历史
Kyle F. Butts 提交于 2021-06-02 10:09 . Update readme with new syntax
output bibliography
github_document
references.bib
```{r setup, include=FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) library(Statamarkdown) ``` # did2s The goal of did2s is to estimate TWFE models without running into the problem of staggered treatment adoption. For details on the methodology, view this [vignette](http://kylebutts.com/did2s/articles/Two-Stage-Difference-in-Differences.html) ## Installation You can install did2s from github with: ``` stata net install did2s, from("https://raw.githubusercontent.com/kylebutts/did2s_stata/main/ado/") * ssc install did2s ``` ## Two-stage Difference-in-differences [@Gardner_2021] I have created an Stata package with the help of John Gardner to estimate the two-stage procedure. The command is `did2s` which estimates the two-stage did procedure. This function requires the following syntax `did2s depvar [if] [in] [weight], first_stage(varlist) treat_formula(varlist) treat_var(varname) cluster(varname)` - `first_stage`: formula for first stage, can include fixed effects and covariates, but do not include treatment variable(s)! - `treat_formula`: Second stage, these should be the treatment indicator(s) (e.g. treatment variable or es leads/lags), use i() for factor variables, following fixest::feols. - `treat_var`: This has to be the 0/1 treatment variable that marks when treatment turns on for a unit. If you suspect anticipation, see note above for accounting for this. - `cluster`: Which variable to cluster on. To view the documentation, type `help did2s` into the console. ## Example Usage ```{stata} ******************************************************************************** * Static ******************************************************************************** use data/df_het.dta * Manually (note standard errors are off) qui reg dep_var i.state i.year if treat == 0, nocons predict adj, residuals reg adj i.treat, cluster(state) nocons * With did2s standard error correction did2s dep_var, first_stage(i.state i.year) treat_formula(i.treat) treat_var(treat) cluster(state) ``` You can also do event-study by changing the `treat_formula` ```{stata} use data/df_het.dta * can not have negatives in factor variable gen rel_year_shift = rel_year + 20 replace rel_year_shift = 100 if rel_year_shift == . did2s dep_var, first_stage(i.state i.year) treat_formula(ib100.rel_year_shift) treat_var(treat) cluster(state) ``` This method works with pre-determined covariates as well! ```{stata} ******************************************************************************** * Castle Doctrine ******************************************************************************** use https://github.com/scunning1975/mixtape/raw/master/castle.dta, clear * Define Covariates global demo blackm_15_24 whitem_15_24 blackm_25_44 whitem_25_44 * No Covariates did2s l_homicide [aweight=popwt], first_stage(i.sid i.year) treat_formula(i.post) treat_var(post) cluster(sid) * Covariates did2s l_homicide [aweight=popwt], first_stage(i.sid i.year $demo) treat_formula(i.post) treat_var(post) cluster(sid) ``` ## References
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/li-chunying/did2s_stata.git
git@gitee.com:li-chunying/did2s_stata.git
li-chunying
did2s_stata
did2s_stata
absorb

搜索帮助