1 Star 0 Fork 15

john-heng66/did2s_stata

forked from 连享会/did2s_stata 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
example.do 2.07 KB
一键复制 编辑 原始数据 按行查看 历史
Kyle F. Butts 提交于 2021-06-02 10:09 . Update readme with new syntax
********************************************************************************
* Example with simulated data
********************************************************************************
use https://github.com/kylebutts/did2s_stata/raw/main/data/df_hom.dta, clear
* net install did2s, from("https://raw.githubusercontent.com/kylebutts/did2s_stata/main/ado/") replace
do ado/did2s.ado
********************************************************************************
* Static
********************************************************************************
** Manual 2SDiD (with incorrect standard errors)
* Step 1: Manually
reg dep_var i.unit i.year if treat == 0, nocons
* Step 2: Regress transformed outcome onto treatment status for all units
predict adj, residuals
reg adj i.treat, vce(cluster state) nocons
** 2SDiD with correct se's
did2s dep_var, first_stage(i.unit i.year) treat_formula(i.treat) treat_var(treat) cluster(state)
* Example esttab
esttab, nobaselevels se
********************************************************************************
* Event Study
********************************************************************************
* factors can't be negative
gen rel_year_shift = rel_year + 20
replace rel_year_shift = 100 if rel_year_shift == .
did2s dep_var, first_stage(i.unit i.year) treat_formula(b100.rel_year_shift) treat_var(treat) cluster(state)
********************************************************************************
* Castle Doctrine
********************************************************************************
use https://github.com/scunning1975/mixtape/raw/master/castle.dta, clear
* Covariates
global demo blackm_15_24 whitem_15_24 blackm_25_44 whitem_25_44
global spending l_exp_subsidy l_exp_pubwelfare
global xvar l_police unemployrt poverty l_income l_prisoner l_lagprisoner $demo $spending
* 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 $xvar) treat_formula(i.post) treat_var(post) cluster(sid)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hengxia/did2s_stata.git
git@gitee.com:hengxia/did2s_stata.git
hengxia
did2s_stata
did2s_stata
absorb

搜索帮助