This repository has been archived by the owner on Mar 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
csdid2_plot.ado
177 lines (133 loc) · 4.38 KB
/
csdid2_plot.ado
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
*! v1.01 csdid2_plot for csdid2 only
program csdid2_plot, rclass
syntax, [* ktype(string)]
local cmd `r(cmd)'
local agg `r(agg)'
tempname b V table bb vv
matrix `b' = r(b)
matrix `V' = r(V)
matrix `table' = r(table)
if "`agg'"=="group" local ktype = 3
if "`agg'"=="calendar" local ktype = 4
if "`agg'"=="event" local ktype = 5
capture noisily csdid2_plot_wh, `options' ktype(`ktype') table(`table')
return local cmd `cmd'
return local agg `agg'
return matrix b =`b'
return matrix V =`V'
return matrix table =`table'
end
program csdid2_plot_wh
syntax, [ * ktype(int 5) table(str)]
tempname tbl
matrix `tbl'=`table'
capture: confirm matrix `tbl'
*if det(`tbl')==. matrix `tbl'=rtb
if `ktype'==5 {
tempvar t b ll uu
mata:event_p("`t' `b' `ll' `uu'","`tbl'")
csdid_plot_eventx `t' `b' `ll' `uu', `options'
}
else if `ktype'==3 | `ktype'==4 {
// Group Calendar
tempvar t b ll uu
mata:other_p("`t' `b' `ll' `uu'","`tbl'")
csdid_plot_other `t' `b' `ll' `uu', `options' ktype(`ktype')
}
else {
display in red "Plot option not allowed"
}
end
program csdid2_default, sclass
syntax, [style(str) PSTYle1(str) color1(str) ///
PSTYLE2(str) color2(str) ///
LWidth1(str) lwidth2(str) ///
BARWidth1(str) barwidth2(str) * ]
if "`style'"=="" local style rspike
if "`pstyle1'"=="" local pstyle1 pstyle(p1)
else local pstyle1 pstyle(`pstyle1')
if "`pstyle2'"=="" local pstyle2 pstyle(p2)
else local pstyle2 pstyle(`pstyle2')
if "`color1'"=="" local color1 color(%40)
else local color1 color(`"`color1'"')
if "`color2'"=="" local color2 color(%40)
else local color2 color(`"`color2'"')
if "`style'"=="rspike" {
if "`lwidth1'"=="" local lwidth1 lwidth(3)
if "`lwidth2'"=="" local lwidth2 lwidth(3)
}
if "`style'"=="rarea" {
if "`lwidth1'"=="" local lwidth1 lwidth(0)
if "`lwidth2'"=="" local lwidth2 lwidth(0)
local conn connect(l)
}
if "`style'"=="rcap" {
if "`lwidth1'"=="" local lwidth1 lwidth(1)
if "`lwidth2'"=="" local lwidth2 lwidth(1)
local conn connect(l)
}
if "`style'"=="rbar" {
if "`lwidth1'"=="" local lwidth1 lwidth(0)
if "`lwidth2'"=="" local lwidth2 lwidth(0)
if "`barwidth1'"=="" local barwidth1 barwidth(0.5)
if "`barwidth2'"=="" local barwidth2 barwidth(0.5)
local conn connect(l)
}
sreturn local style `style'
sreturn local df11 `pstyle1' `color1' `lwidth1' `barwidth1'
sreturn local df12 `pstyle1' `conn'
sreturn local df21 `pstyle2' `color2' `lwidth2' `barwidth2'
sreturn local df22 `pstyle2' `conn'
sreturn local delse `options'
end
program csdid_plot_eventx
syntax varlist, [ xtitle(passthru) ytitle(passthru) ///
legend(passthru) * ]
gettoken t rest:varlist
gettoken b rest:rest
gettoken ll rest:rest
gettoken uu rest:rest
** defaults
** defaults
if `"`xtitle'"'=="" local xtitle xtitle("Periods to Treatment")
if `"`ytitle'"'=="" local ytitle ytitle("ATT")
if `"`legend'"'=="" local legend legend(order(1 "Pre-treatment" 3 "Post-treatment"))
csdid2_default , `options'
local gf11 `s(df11)'
local gf12 `s(df12)'
local gf21 `s(df21)'
local gf22 `s(df22)'
local style `s(style)'
local dels `s(delse)'
two (`style' `ll' `uu' `t' if `t'<=-1 , `gf11') ///
(scatter `b' `t' if `t'<=-1 , `gf12') ///
(`style' `ll' `uu' `t' if `t'>-1, `gf21') ///
(scatter `b' `t' if `t'>-1, `gf22') , ///
`legend' `xtitle' `ytitle' ///
yline(0 , lp(dash) lcolor(black)) `dels'
end
program csdid_plot_other
syntax varlist, [ktype(int 3) * ///
xtitle(passthru) ytitle(passthru) ///
legend(passthru)]
gettoken t rest:varlist
gettoken b rest:rest
gettoken ll rest:rest
gettoken uu rest:rest
local xlab `xlab' `=`j'+1' " "
csdid2_default , `options'
local gf11 `s(df11)'
local gf12 `s(df12)'
local style `s(style)'
local dels `s(delse)'
if `"`xtitle'"'=="" & `ktype' ==3 local xtitle xtitle("Group")
else if `"`xtitle'"'=="" & `ktype' ==4 local xtitle xtitle("Calendar")
if `"`ytitle'"'=="" local ytitle ytitle("ATT")
tempvar t2
qui:encode `t', gen(`t2')
two (`style' `ll' `uu' `t2' , `gf11' ) ///
(scatter `b' `t2' , `gf12' ) , ///
legend(off) `xtitle' `ytitle' ///
yline(0 , lp(dash) lcolor(black)) `title' ///
xlab( ,val) `name' `dels'
end