-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathexample.do
57 lines (38 loc) · 2.07 KB
/
example.do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
********************************************************************************
* 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) second_stage(i.treat) treatment(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) second_stage(b100.rel_year_shift) treatment(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) second_stage(i.post) treatment(post) cluster(sid)
* Covariates
did2s l_homicide [aweight=popwt], first_stage(i.sid i.year $xvar) second_stage(i.post) treatment(post) cluster(sid)