-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersuasio4ytz2lpr.ado
348 lines (239 loc) · 11.1 KB
/
persuasio4ytz2lpr.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/***
Title
-----
{phang}{cmd:persuasio4ytz2lpr} {hline 2} Conduct causal inference on the local persuasion rate
for binary outcomes _y_, binary treatments _t_ and binary instruments _z_
Syntax
------
> {cmd:persuasio4ytz2lpr} _depvar_ _treatvar_ _instrvar_ [_covariates_] [_if_] [_in_] [, {cmd:level}(#) {cmd:model}(_string_) {cmd:method}(_string_) {cmd:nboot}(#) {cmd:title}(_string_)]
### Options
| _option_ | _Description_ |
|-------------------|-------------------------|
| {cmd:level}(#) | Set confidence level; default is {cmd:level}(95) |
| {cmd:model}(_string_) | Regression model when _covariates_ are present |
| {cmd:method}(_string_) | Inference method; default is {cmd:method}("normal") |
| {cmd:nboot}(#) | Perform # bootstrap replications |
| {cmd:title}(_string_) | Title |
Description
-----------
{phang}{cmd:persuasio4ytz2lpr} conducts causal inference on causal inference on the local persuasion rate.
It is assumed that binary outcomes _y_, binary treatments _t_, and binary instruments _z_ are observed.
This command is for the case when persuasive treatment (_t_) is observed,
using estimates of the local persuasion rate (LPR) via
this package's command {cmd:lpr4ytz}.
_varlist_ should include _depvar_ _treatvar_ _instrvar_ _covariates_ in order.
Here, _depvar_ is binary outcome (_y_), _treatvar_ is binary treatment,
_instrvar_ is binary instrument (_z_), and _covariates_ (_x_) are optional.
There are two cases: (i) _covariates_ are absent and (ii) _covariates_ are present.
- Without _x_, the LPR is defined by
{cmd:LPR} = {Pr({it:y}=1|{it:z}=1)-Pr({it:y}=1|{it:z}=0)}/{Pr[{it:y}=0,{it:t}=0|{it:z}=0]-Pr[{it:y}=0,{it:t}=0|{it:z}=1]}.
The estimate and its standard error are obtained by the following procedure:
1. The numerator of the LPR is estimated by regressing _y_ on _z_.
2. The denominator is estimated by regressing (1-{it:y})*(1-{it:t}) on _z_.
3. The LPR is obtained as the ratio.
4. The standard error is computed via STATA command __nlcom__.
{p 4 8 2}5. Then, a confidence interval for the LPR is obtained via the usual normal approximation.
- With _x_, the LPR is defined by
{cmd:LPR} = E[{cmd:LPR}({it:x}){e(1|x) - e(0|x)}]/E[e(1|x) - e(0|x)]
where
{p 4 8 2} {cmd:LPR}({it:x}) = {Pr({it:y}=1|{it:z}=1,{it:x}) - Pr({it:y}=1|{it:z}=0,{it:x})}/{Pr[{it:y}=0,{it:t}=0|{it:z}=0,{it:x}] - Pr[{it:y}=0,{it:t}=0|{it:z}=1,{it:x}]},
e(1|x) = Pr({it:t}=1|{it:z}=1,{it:x}), and e(0|x) = Pr({it:t}=1|{it:z}=0,{it:x}).
The estimate is obtained by the following procedure.
If {cmd:model}("no_interaction") is selected (default choice),
1. The numerator of the LPR is estimated by regressing _y_ on _z_ and _x_.
2. The denominator is estimated by regressing (1-{it:y})*(1-{it:t}) on _z_ and _x_.
3. The LPR is obtained as the ratio.
4. The standard error is computed via STATA command __nlcom__.
{p 4 8 2}5. Then, a confidence interval for the LPR is obtained via the usual normal approximation.
Note that in this case, {cmd:LPR}({it:x}) does not depend on _x_ because of the linear regression model specification.
Alternatively, if {cmd:model}("interaction") is selected,
{p 4 8 2} 1. Pr({it:y}=1|{it:z},{it:x}) is estimated by regressing {it:y} on _x_ given _z_ = 0,1.
{p 4 8 2} 2. Pr[{it:y}=0,{it:t}=0|{it:z},{it:x}] is estimated by regressing (1-{it:y})*(1-{it:t}) on _x_ given _z_ = 0,1.
{p 4 8 2} 3. Pr({it:t}=1|{it:z},{it:x}) is estimated by regressing _t_ on _x_ given _z_ = 0,1.
{p 4 8 2} 4. For each _x_ in the estimation sample, both {cmd:LPR}({it:x}) and {e(1|x)-e(0|x)} are evaluated.
{p 4 8 2} 5. Then, the sample analog of {cmd:LPR} is constructed.
{p 4 8 2} 6. Finally, the bootstrap procedure is implemented via STATA command {cmd:bootstrap}.
Options
-------
{cmd:model}(_string_) specifies a regression model of _y_ on _z_ and _x_.
This option is only relevant when _x_ is present.
The default option is "no_interaction" between _z_ and _x_.
When "interaction" is selected, full interactions between _z_ and _x_ are allowed.
{cmd:level}(#) sets confidence level; default is {cmd:level}(95).
{cmd:method}(_string_) refers the method for inference.
The default option is {cmd:method}("normal").
Since the LPR is point-identified, usual two-sided confidence intervals are produced.
{p 4 8 2}1. When {cmd:model}("interaction") is chosen as an option, it needs to be set as {cmd:method}("bootstrap");
otherwise, the confidence interval will be missing.
{cmd:nboot}(#) chooses the number of bootstrap replications.
The default option is {cmd:nboot}(50).
It is only relevant when {cmd:method}("bootstrap") is selected.
{cmd:title}(_string_) specifies a title.
Remarks
-------
It is recommended to use {cmd:nboot}(#) with # at least 1000.
A default choice of 50 is meant to check the code initially
because it may take a long time to run the bootstrap part.
The bootstrap confidence interval is based on percentile bootstrap.
Normality-based bootstrap confidence interval is not recommended
because bootstrap standard errors can be unreasonably large in applications.
Examples
--------
We first call the dataset included in the package.
. use GKB, clear
The first example conducts inference on the LPR without covariates, using normal approximation.
. persuasio4ytz2lpr voteddem_all readsome post, level(80) method("normal")
The second example conducts bootstrap inference on the LPR.
. persuasio4ytz2lpr voteddem_all readsome post, level(80) method("bootstrap") nboot(1000)
The third example conducts bootstrap inference on the LPR with a covariate, MZwave2, interacting with the instrument, post.
. persuasio4ytz2lpr voteddem_all readsome post MZwave2, level(80) model("interaction") method("bootstrap") nboot(1000)
Stored results
--------------
### Matrices
> __e(lpr_est)__: (1*1 matrix) estimate of the local persuasion rate
> __e(lpr_ci)__: (1*2 matrix) confidence interval for the local persuasion rate in the form of [lb_ci, ub_ci]
### Macros
> __e(cilevel)__: confidence level
> __e(inference_method)__: inference method: "normal" or "bootstrap"
Authors
-------
Sung Jae Jun, Penn State University, <sjun@psu.edu>
Sokbae Lee, Columbia University, <sl3841@columbia.edu>
License
-------
GPL-3
References
----------
Sung Jae Jun and Sokbae Lee (2019),
Identifying the Effect of Persuasion,
[arXiv:1812.02276 [econ.EM]](https://arxiv.org/abs/1812.02276)
Version
-------
0.1.0 30 January 2021
***/
capture program drop persuasio4ytz2lpr
program persuasio4ytz2lpr, eclass sortpreserve byable(recall)
version 14.2
syntax varlist (min=3) [if] [in] [, level(cilevel) model(string) method(string) nboot(numlist >0 integer) title(string)]
marksample touse
gettoken Y varlist_without_Y : varlist
gettoken T varlist_without_YT : varlist_without_Y
gettoken Z X : varlist_without_YT
quietly lpr4ytz `Y' `T' `Z' `X' if `touse', model("`model'")
tempname lpr_coef lpr_se
scalar `lpr_coef' = e(lpr_coef)
scalar `lpr_se' = e(lpr_se)
* displaying results
if "`title'" != "" {
display "`title':"
}
* inference based on normal approximation
if "`method'" == "" | "`method'" == "normal" {
if "`level'" != "" {
local alpha_level = 1 - `level'/100
}
if "`level'" == "" {
local alpha_level = 0.05
}
tempname cv_cns lb_end ub_end
scalar `cv_cns' = invnormal(1-`alpha_level'/2) /* two-sided critical value */
scalar `lb_end' = max(0,`lpr_coef' - `cv_cns'*`lpr_se')
scalar `ub_end' = min(1,`lpr_coef' + `cv_cns'*`lpr_se')
*scalar `lb_end' = `lpr_coef' - `cv_cns'*`lpr_se'
*scalar `ub_end' = `lpr_coef' + `cv_cns'*`lpr_se'
* Displaying results
display " "
display as text "{hline 65}"
display "{bf:persuasio4ytz2lpr:} Causal inference on the local Persuasion rate"
display " when outcome, instrument and instrument are observed"
display as text "{hline 65}"
display " "
if "`title'" != "" {
display "Title: `title'"
}
display " - Binary outcome: `e(outcome)'"
display " - Binary treatment: `e(treatment)'"
display " - Binary instrument: `e(instrument)'"
display " - Covariates (if exist): `e(covariates)'"
display " - Regression model (if specified): `e(model)'"
display " "
display as text "{hline 25}{c TT}{hline 40}"
display as text %24s "Parameter" " {c |}" /*
*/ _col(28) "Estimate" /*
*/ _col(48) "`level'% Conf. Interval"
display as text "{hline 25}{c +}{hline 40}"
display as text %24s "Local Persuasion Rate" " {c |}" /*
*/ as result /*
*/ _col(27) %8.0g `lpr_coef' " " /*
*/ _col(47) %8.0g `lb_end' " " /*
*/ _col(53) %8.0g `ub_end' " "
display as text "{hline 25}{c BT}{hline 40}"
display " "
display "Note: `level'% conf. interval is based on normal approximation."
display " Conf. interval is missing (given as [0,1]) if interactions are"
display " allowed between x and z. Use option bootstrap for that case."
display " "
}
* inference based on bootstrap
if "`method'" == "bootstrap" {
* Displaying results
display " "
display as text "{hline 65}"
display "{bf:persuasio4ytz2lpr:} Causal inference on the local persuasion rate"
display " when outcome, instrument and instrument are observed"
display as text "{hline 65}"
display " "
if "`title'" != "" {
display "Title: `title'"
}
display " - Binary outcome: `e(outcome)'"
display " - Binary treatment: `e(treatment)'"
display " - Binary instrument: `e(instrument)'"
display " - Covariates (if exist): `e(covariates)'"
display " - Regression model (if specified): `e(model)'"
display " "
if "`level'" != "" {
local alpha_level = 1 - `level'/100
}
if "`level'" == "" {
local alpha_level = 0.05
}
local bs_level = round(10000*(1 - `alpha_level'))/100 /* level for bootstrap */
* lower bound
if "`nboot'" != "" {
bootstrap coef=e(lpr_coef), reps(`nboot') level(`bs_level') notable nowarn: lpr4ytz `Y' `T' `Z' `X' if `touse', model("`model'")
}
if "`nboot'" == "" {
bootstrap coef=e(lpr_coef), reps(50) level(`bs_level') notable nowarn: lpr4ytz `Y' `T' `Z' `X' if `touse', model("`model'")
}
tempname bs_ci_percentile lb_end ub_end
matrix `bs_ci_percentile' = e(ci_percentile)
scalar `lb_end' = max(0,`bs_ci_percentile'[1,1])
scalar `ub_end' = min(1,`bs_ci_percentile'[2,1])
* Displaying results further
display " "
display as text "{hline 25}{c TT}{hline 40}"
display as text %24s "Parameter" " {c |}" /*
*/ _col(28) "Estimate" /*
*/ _col(48) "`level'% Conf. Interval"
display as text "{hline 25}{c +}{hline 40}"
display as text %24s "Local Persuasion Rate" " {c |}" /*
*/ as result /*
*/ _col(27) %8.0g `lpr_coef' " " /*
*/ _col(47) %8.0g `lb_end' " " /*
*/ _col(53) %8.0g `ub_end' " "
display as text "{hline 25}{c BT}{hline 40}"
display " "
display "Note: `level'% conf. interval is based on percentile bootstrap."
display " "
}
tempname coef_matrix ci_matrix
matrix `coef_matrix' = (`lpr_coef')
matrix `ci_matrix' = (`lb_end',`ub_end')
ereturn clear
ereturn matrix lpr_est = `coef_matrix'
ereturn matrix lpr_ci = `ci_matrix'
ereturn local cilevel = (1-`alpha_level')*100
ereturn local inference_method "`method'"
display "Reference: Jun and Lee (2019), arXiv:1812.02276 [econ.EM]"
end