-
Notifications
You must be signed in to change notification settings - Fork 9
/
11-class.Rmd
273 lines (187 loc) · 8.46 KB
/
11-class.Rmd
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
---
title: "Class 11: IV I"
author: "Andrew Heiss"
date: "`r Sys.Date()`"
output:
xaringan::moon_reader:
lib_dir: "libs"
chakra: "libs/remark-latest.min.js"
css: ["default", "css/ath-slides.css", "css/ath-inferno-fonts.css", "css/animate.css"]
seal: false
anchor_sections: false
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
ratio: "16:9"
navigation:
scroll: false
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(warning = FALSE, message = FALSE,
fig.retina = 3, fig.align = "center")
```
```{r packages-data, include=FALSE}
library(tidyverse)
library(kableExtra)
library(scales)
library(ggdag)
set.seed(123456)
status_colors <- c(exposure = "#0074D9", outcome = "#FF851B", latent = "grey50")
status_colors_backdoor <- c(exposure = "#0074D9", outcome = "#FF851B", latent = "#FF4136")
node_details <- tribble(
~plot1, ~plot2, ~plot3, ~name, ~label, ~x, ~y, ~generic, ~mathy,
TRUE, TRUE, TRUE, "treatment", "Education", 1, 1, "Program/policy", "X",
TRUE, TRUE, TRUE, "outcome", "Earnings", 3, 1, "Outcome", "Y",
FALSE, TRUE, TRUE, "unmeasured", "Ability", 2, 2, "Unmeasured confounders", "U",
FALSE, FALSE, TRUE, "instrument", "Father's education", 0, 1, "Instrument", "Z"
)
node_labels <- node_details$label %>%
set_names(node_details$name)
node_labels_generic <- node_details$generic %>%
set_names(node_details$name)
```
```{r xaringanExtra, echo=FALSE}
xaringanExtra::use_xaringan_extra(c("tile_view"))
```
class: center middle main-title section-title-3
# In-person<br>session 11
.class-info[
**March 30, 2023**
.light[PMAP 8521: Program evaluation<br>
Andrew Young School of Policy Studies
]
]
---
name: outline
class: title title-inv-8
# Plan for today
--
.box-5.medium[Super quick R things]
--
.box-2.medium[IV questions]
--
.box-6.medium[IV fun times]
---
layout: false
name: r-stuff
class: center middle section-title section-title-5 animated fadeIn
# Quick R stuff
---
class: middle
.box-5.large[Selecting things!]
---
class: middle
.box-5.large[Reprexes!]
???
- <https://datavizs22.classes.andrewheiss.com/slides/08-slides.html#15>
- <https://gist.github.com/andrewheiss/b85c72e2cadb496fed0b8715ef5cacf5>
- <https://gist.github.com/andrewheiss/542e2882f21f155d52bdd7fecf24b487>
```r
library(tidyverse)
library(rdrobust)
blah <- mpg |>
mutate(treated = displ > 4)
asdf <- rdrobust(blah$hwy, blah$displ, c = 4)
summary(asdf)
rdplot(blah$hwy, blah$displ, c = 4)
```
---
class: middle
.box-5.large[Why can't we use `rdrobust()`<br>with `tidy()` or `modelsummary()`?]
???
<https://github.com/tidymodels/broom/issues/777#issuecomment-643251123>
---
layout: false
name: iv
class: center middle section-title section-title-2 animated fadeIn
# IV questions
---
layout: true
class: middle
---
.box-2[Given the strict criteria for instrumental variables,<br>they seem pretty impractical and uncommon<br>(especially compared to diff-in-diff and RDD).<br><br>Why do you include instrumental variables<br>as a part of this course?]
.box-2[What's really the point of doing IV if finding instruments<br>is so difficult and easy to mess up?]
.box-2.large[Why even bother?]
---
.box-2.medium[Is there like a “bank” of good IVs?]
.box-2.medium[Do you have a method that helps you think of instruments, or a popular process that people usually use to come up with ideas?]
---
.box-2.medium[What does it mean to tell a good story about excludability and exogeneity?]
???
- https://braddelong.substack.com/p/podcast-hexapodia-is-e-key-insight-331
- Matthew Suandi, "Promoting to Opportunity: Evidence and Implications from the U.S. Submarine Service" - https://are.berkeley.edu/sites/are.berkeley.edu/files/job-candidates/paper/MatthewSuandi_JMP_Nov_21_Berkeley.pdf
---
.center[
<figure>
<img src="img/14-class/torpedo.png" alt="WWII torpedo" title="WWII torpedo" width="70%">
</figure>
]
???
Via <https://braddelong.substack.com/p/podcast-hexapodia-is-e-key-insight-331>:
- In the early stages of the Pacific War, whether a US submarine-launched torpedo exploded was a matter of luck.
- If a submarine captain had an enlisted man marked out for promotion, those promotions happened much more often if the submarine returned from its cruise having succeeded in sinking ships.
- Those promoted because they happened to be on lucky submarines with torpedoes that exploded lived 2.4 years longer than their counterparts who happened to be on unlucky submarines and were not promoted.
- Those promoted because they happened to be on lucky submarines with torpedoes that exploded are recorded as having a last known address in a zip code with housing prices higher by 7 percentiles than their counterparts who happened to be on unlucky submarines and were not promoted.
- Early promotion to a job with more responsibility and scope—at least in the WWII-era USN—shapes your life to a remarkable degree by giving you scope to develop and exercise your talents.
- If the WWII-era USN is typical, we waste huge amounts of human potential by not giving people workplace opportunities to show what they can learn to do.
- Equality isn’t just about money: it is about scope for action, about developing and exercising talents, and about receiving external validation.
- A good society would give people much more opportunity to discover how big a deal they are and can become, and remind them of this at every opportunity.
---
.box-2[Why would we use instrumental variables when we can simply use DAGs to control for things instead?]
.box-2[What is the advantage of using an IV versus trying to find a variable that is correlated with the excluded variable of interest? For example, trying to find a variable highly correlated with "ability"? This seems also difficult but less difficult than finding a true IV.]
.box-2[Could we assume that things like “ability” are latent variables and then try to model them directly?]
---
```{r iv-dag-example, echo=FALSE, fig.width=12, fig.height=6, out.width="100%"}
iv_dag2 <- dagify(outcome ~ treatment + unmeasured,
treatment ~ unmeasured,
exposure = "treatment",
outcome = "outcome",
latent = "unmeasured",
coords = filter(node_details, plot2),
labels = node_labels) %>%
tidy_dagitty() %>%
node_status() %>%
node_exogenous() %>%
node_dconnected() %>%
control_for("unmeasured")
ggplot(iv_dag2, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_dag_edges(aes(edge_colour = adjusted),
start_cap = ggraph::circle(3, "lines"),
end_cap = ggraph::circle(3, "lines"),
edge_width = 1.5,
arrow_directed = grid::arrow(length = grid::unit(0.75, "lines"), type = "closed")) +
geom_dag_point(aes(color = status), size = 30) +
geom_dag_label_repel(aes(label = label, fill = status), seed = 1234,
color = "white", fontface = "bold", size = 14,
family = "Fira Sans Condensed",
label.padding = grid::unit(0.75, "lines"),
box.padding = grid::unit(6, "lines"),
direction = "y") +
scale_color_manual(values = status_colors_backdoor, na.value = "grey20") +
ggraph::scale_edge_colour_manual(values = c(unadjusted = "black", adjusted = "#FF4136")) +
scale_fill_manual(values = status_colors_backdoor, na.value = "grey20") +
guides(color = "none", fill = "none", edge_colour = "none") +
theme_dag(base_size = 28)
```
---
.box-2.less-medium[In the lecture you mentioned that the instrumental variable should be weird (or make people say huh?). However, in *The Effect*, the author states that the instrument should be relevant. This is a bit mixed messaging. Which approach should we use?]
.center[[Formal definitions of relevancy, excludability, and exogeneity](/slides/11-slides.html#43)]
---
.box-2.less-medium[Why are things like weather, distance, or terrain bad instruments? How do they violate the exclusion restriction?]
.center[[Lecture slides](/slides/11-slides.html#75)]
---
.box-2.medium[Fuzzy RDD requires an instrument,<br>but instruments seem impossible to find,<br>so can we ever really do fuzzy RDD?]
---
layout: false
name: schedule
class: center middle section-title section-title-3 animated fadeIn
# Schedule update
---
layout: false
name: iv
class: center middle section-title section-title-6 animated fadeIn
# IV fun times