-
Notifications
You must be signed in to change notification settings - Fork 9
/
11-slides.Rmd
1476 lines (1060 loc) Β· 40.6 KB
/
11-slides.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
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Instrumental variables 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(broom)
library(ggdag)
library(kableExtra)
library(scales)
library(patchwork)
library(estimatr)
library(modelsummary)
set.seed(123456)
nrows <- 1000
father_education <- tibble(
ability = rnorm(nrows, 35000, 10000), # Ability
fathereduc = rnorm(nrows, 15000, 20000), # Father's education (IV)
e_y = 0.43 * rnorm(nrows, 50000, 10000) # Error for outcome
) %>%
mutate(educ = 3.7 + 0.52*fathereduc + 0.40*ability, # Education (policy variable)
wage = 5 + 0.23*educ + 0.5*ability - e_y) %>% # Wage (outcome variable)
mutate(wage = rescale(wage, to = c(7.75, 300)), # Rescale from minimum wage to director wage (hourly)
educ = rescale(educ, to = c(10, 23)), # Rescale as years of school. Min 10 to max 23 (PhD)
fathereduc = rescale(fathereduc, to = c(10, 23)), # Rescale father's education
ability = rescale(ability, to = c(0, 600))) %>% # Rescale as Hypothetical test scores
select(wage, educ, ability, fathereduc) %>%
mutate(across(everything(), ~round(., 2)))
```
```{r xaringanExtra, echo=FALSE}
xaringanExtra::use_xaringan_extra(c("tile_view"))
```
class: center middle main-title section-title-7
# Instrumental<br>variables I
.class-info[
**Session 11**
.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.sp-after-half[Endogeneity and exogeneity]
--
.box-6.medium.sp-after-half[Instruments]
--
.box-3.medium.sp-after-half[Using instruments]
---
name: endo-exo
class: center middle section-title section-title-5 animated fadeIn
# Endogeneity<br>and exoegneity
---
layout: true
class: title title-5
---
# Does education cause higher earnings?
```{r iv-dag-simple, echo=FALSE, fig.width=7, fig.height=3, out.width="70%"}
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)
iv_dag1 <- dagify(outcome ~ treatment,
exposure = "treatment",
outcome = "outcome",
coords = filter(node_details, plot1),
labels = node_labels) %>%
tidy_dagitty() %>%
node_status()
ggplot(iv_dag1, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_dag_edges(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 = 20) +
geom_dag_label_repel(aes(label = label, fill = status), seed = 1234,
color = "white", fontface = "bold", size = 7,
family = "Fira Sans Condensed",
label.padding = grid::unit(0.75, "lines"),
# box.padding = grid::unit(2.5, "lines"),
direction = "y") +
scale_color_manual(values = status_colors, na.value = "grey20") +
scale_fill_manual(values = status_colors, na.value = "grey20") +
guides(color = FALSE, fill = FALSE) +
theme_dag(base_size = 20)
```
--
.medium[
$$\color{#FF851B}{\text{Earnings}_i} = \beta_0 + \beta_1 \color{#0074D9}{\text{Education}_i} + \varepsilon_i$$
]
---
layout: false
.box-inv-5.medium[If we ran this regression, would Ξ²<sub>1</sub><br>give us the causal effect of education?]
.medium[
$$\text{Earnings}_i = \beta_0 + \beta_1 \text{Education}_i + \varepsilon_i$$
]
--
.box-5.medium[No!]
--
.float-left.center[.box-inv-5[Omitted variable bias!] .box-inv-5[Unclosed backdoors!]]
--
.box-inv-5[**Endogeneity!**]
---
layout: true
class: title title-5
---
# Exogeneity and endogeneity
.box-inv-5.medium[**Exogenous** variables]
--
.box-5[Value is not determined by<br>anything else in the model]
--
.box-5[In a DAG, a node that doesn't<br>have arrows coming into it]
---
# Exogeneity
.box-inv-5.medium[Education is exogenous: no arrows *into* it]
```{r show-iv-dag, echo=FALSE, out.width="100%"}
knitr::include_graphics(knitr::fig_chunk("iv-dag-simple", "png"))
```
---
# Exogeneity and endogeneity
.box-inv-5.medium[**Endogenous** variables]
--
.box-5[Value is determined by<br>something else in the model]
--
.box-5[In a DAG, a node that<br>has arrows coming into it]
---
# Endogeneity
.box-inv-5.medium[Education is endogenous: Ability β Education]
```{r iv-dag-endogenous, echo=FALSE, fig.width=7, fig.height=4, out.width="60%"}
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(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 = 20) +
geom_dag_label_repel(aes(label = label, fill = status), seed = 1234,
color = "white", fontface = "bold", size = 7,
family = "Fira Sans Condensed",
label.padding = grid::unit(0.75, "lines"),
box.padding = grid::unit(5, "lines"),
direction = "both") +
scale_color_manual(values = status_colors, na.value = "grey20") +
scale_fill_manual(values = status_colors, na.value = "grey20") +
guides(color = FALSE, fill = FALSE) +
theme_dag(base_size = 20)
```
---
# Exgoeneity
.box-inv-5.medium[What would exogenous variation<br>in education look like?]
--
.box-5[Choices to get more education that are essentially random<br>(or at least uncorrelated with omitted variables)]
---
layout: false
.box-5.medium[We'd like education to be exogenous<br>.smaller[(an outside decision or intervention)], but it's not!]
```{r show-iv-dag-endo, echo=FALSE, out.width="45%"}
knitr::include_graphics(knitr::fig_chunk("iv-dag-endogenous", "png"))
```
--
.box-inv-5[Part of it is exogenous, but part of it is<br>caused by ability, which is in the DAG]
---
class: title title-5
# Fixing endogeneity with DAGs
```{r show-iv-dag-endo-again, echo=FALSE, out.width="45%"}
knitr::include_graphics(knitr::fig_chunk("iv-dag-endogenous", "png"))
```
--
.box-5[Close backdoor and adjust for ability]
--
.box-inv-5.smaller[Adjustment filters out the endogenous part of education and leaves us with just the endogenous part]
$$\text{Earnings}_i = \beta_0 + \beta_1 \text{Education}_i + \beta_2 \text{Ability}_i + \varepsilon_i$$
---
```{r calculate-effects, echo=FALSE}
# IPW with continuous treatment
# https://meghapsimatrix.com/post/continuous-r-rmarkdown/
# model_num <- lm(educ ~ 1, data = father_education)
# num <- dnorm(father_education$educ,
# predict(model_num),
# sd(model_num$residuals))
#
# model_den <- lm(educ ~ ability, data = father_education)
# den <- dnorm(father_education$educ,
# predict(model_den),
# sd(model_den$residuals))
# Also works with ipw::ipwpoint
# weights_automatic <- ipw::ipwpoint(
# exposure = educ,
# family = "gaussian",
# numerator = ~ 1,
# denominator = ~ 1 + ability,
# trunc = 0.05,
# data = as.data.frame(father_education)
# )
# father_educ_ipw <- father_education %>%
# mutate(ipw = num / den)
# model3 <- lm(wage ~ educ, data = father_educ_ipw, weights = ipw)
model1 <- lm(wage ~ educ, data = father_education)
model2 <- lm(wage ~ educ + ability, data = father_education)
```
.pull-left-wide[
.small[
```{r show-table, echo=FALSE}
model_results <- modelsummary(list("Unadjusted" = model1, "Adjusted" = model2),
gof_omit = 'IC|Log|Adj', stars = TRUE)
model_results %>%
add_header_above(c(" " = 1, "Outome = wage" = 2)) %>%
row_spec(c(6, 9), extra_css = "border-bottom: 1px solid") %>%
row_spec(3, background = "#FFC6C6")
```
]
]
.pull-right-narrow[
.box-2[Unadjusted<br>is wrong!]
.box-5[Adjusted<br>is right!]
.box-inv-5.small[One year of education causes hourly wage to increase by $7.77]
.box-inv-5.smaller[(FAKE DATA)]
]
---
layout: true
class: title title-5
---
# But we can't measure ability!
```{r iv-dag-endogenous-confounding, echo=FALSE, fig.width=7, fig.height=4, out.width="40%"}
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")) +
ggraph::scale_edge_colour_manual(values = c(unadjusted = "black", adjusted = "#FF4136")) +
geom_dag_point(aes(color = status), size = 20) +
geom_dag_label_repel(aes(label = label, fill = status), seed = 1234,
color = "white", fontface = "bold", size = 7,
family = "Fira Sans Condensed",
label.padding = grid::unit(0.75, "lines"),
box.padding = grid::unit(5, "lines"),
direction = "both") +
scale_color_manual(values = status_colors_backdoor, na.value = "grey20") +
scale_fill_manual(values = status_colors_backdoor, na.value = "grey20") +
guides(color = FALSE, fill = FALSE, edge_colour = FALSE) +
theme_dag(base_size = 20)
```
$$\color{#FF851B}{\text{Earnings}_i} = \beta_0 + \beta_1 \color{#0074D9}{\text{Education}_i} + \beta_2 \color{#FF4136}{\text{Ability}_i} + \varepsilon_i$$
--
.box-inv-5.small[Unmeasurable ability node is in the error term (Ξ΅)]
$$\color{#FF851B}{\text{Earnings}_i} = \beta_0 + \beta_1 \color{#0074D9}{\text{Education}_i} + \color{#FF4136}{\varepsilon_i}$$
---
# Split exogeneity and endogeneity
.box-inv-5[What if we could somehow separate education<br>into its endogenous and exogenous parts?]
--
.SMALL[
$$
\begin{aligned}
\color{#FF851B}{\text{Earnings}_i} =& \beta_0 + \beta_1 \color{#B10DC9}{\text{Education}_i} + \varepsilon_i \\
& \beta_0 + \beta_1 (\color{#0074D9}{\text{Education}_i^\text{exog.}} + \color{#FF4136}{\text{Education}_i^\text{endog.}}) + \varepsilon_i \\
& \beta_0 + \beta_1 \color{#0074D9}{\text{Education}_i^\text{exog.}} + \underbrace{\beta_1 \color{#FF4136}{\text{Education}_i^{\text{endog.}}} + \varepsilon_i}_{\color{#AAAAAA}{\omega_i}} \\
& \beta_0 + \beta_1 \color{#0074D9}{\text{Education}_i^\text{exog.}} + \color{#AAAAAA}{\omega_i}
\end{aligned}
$$
]
---
# Find exogeneity with One Weird Trickβ’
.medium[
$$
\color{#FF851B}{\text{Earnings}_i} = \beta_0 + \beta_1 \color{#0074D9}{\text{Education}_i^\text{exog.}} + \color{#AAAAAA}{\omega_i}
$$
]
.box-inv-5.medium.sp-after[How do we find only Education<sup>exog.</sup>?]
--
.box-5.large[Use an instrument!]
---
layout: false
name: instruments
class: center middle section-title section-title-6 animated fadeIn
# Instruments
---
layout: true
class: title title-6
---
# What is an instrument?
--
.box-inv-6[Something that is correlated with the policy variable]
.box-6.small.sp-after[(Relevance)]
--
.box-inv-6[Something that does not directly cause the outcome]
.box-6.small.sp-after[(Exclusion)]
--
.box-inv-6[Something that is not correlated with the omitted variables]
.box-6.small[(Exogenity)]
---
layout: false
```{r iv-dag-general, echo=FALSE, fig.width=12, fig.height=6, out.width="100%"}
iv_dag4 <- dagify(outcome ~ treatment + unmeasured,
treatment ~ unmeasured + instrument,
exposure = "treatment",
outcome = "outcome",
latent = "unmeasured",
coords = filter(node_details, plot3),
labels = node_labels_generic) %>%
tidy_dagitty() %>%
node_status() %>%
node_exogenous() %>%
node_dconnected() %>%
control_for("unmeasured")
ggplot(iv_dag4, 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 = 1,
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 = FALSE, fill = FALSE, edge_colour = FALSE) +
theme_dag(base_size = 28)
```
---
```{r iv-dag-example, echo=FALSE, fig.width=12, fig.height=6, out.width="100%"}
iv_dag3 <- dagify(outcome ~ treatment + unmeasured,
treatment ~ unmeasured + instrument,
exposure = "treatment",
outcome = "outcome",
latent = "unmeasured",
coords = filter(node_details, plot3),
labels = node_labels) %>%
tidy_dagitty() %>%
node_status() %>%
node_exogenous() %>%
node_dconnected() %>%
control_for("unmeasured")
ggplot(iv_dag3, 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 = FALSE, fill = FALSE, edge_colour = FALSE) +
theme_dag(base_size = 28)
```
---
```{r iv-dag-letters, echo=FALSE, fig.width=12, fig.height=6, out.width="100%"}
mathy_coords <- node_details %>%
filter(plot3) %>%
select(name = mathy, x, y)
iv_dag_mathy <- dagify(Y ~ X + U,
X ~ U + Z,
exposure = "X",
outcome = "Y",
latent = "U",
coords = mathy_coords) %>%
tidy_dagitty() %>%
node_status() %>%
node_exogenous() %>%
node_dconnected()
ggplot(iv_dag_mathy, 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_text(aes(label = name),
color = "white", fontface = "bold", size = 14,
family = "Fira Sans Condensed") +
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 = FALSE, fill = FALSE, edge_colour = FALSE) +
theme_dag(base_size = 28)
```
---
.pull-left[
.box-6.SMALL[**Relevance**<br>Correlated with policy]
.box-inv-6.smaller[Z β X   Cor(Z, X) β 0]
.box-6.SMALL[**Excludability**<br>Correlated with outcome<br>*only through* policy]
.box-inv-6.smaller[Z β X β Y   Z ↛ Y   Cor(Z, Y | X) = 0]
.box-6.SMALL[**Exogeneity**<br>*Not* correlated<br>with omitted variables]
.box-inv-6.smaller[U ↛ Z   Cor(Z, U) = 0]
]
.pull-right[
![](`r knitr::fig_chunk("iv-dag-letters", "png")`)
.box-inv-6.smaller[**Relevance** testable with stats]
.box-inv-6.smaller[**Excludability** testable with stats + story]
.box-inv-6.smaller[**Exogeneity** requires story, no stats]
]
???
https://dlm-econometrics.blogspot.com/2020/08/horseshoes-and-hand-grenades.html
---
layout: true
class: title title-6
---
# Relevance
.box-6[Instrument causes change in policy]
.box-inv-6.smaller.sp-after[Z β X   Cor(Z, X) β 0]
<hr>
--
.center.float-left.sp-after[.box-inv-6.sp-before[Social security number] .box-2.smaller[Probably not relevant (uncorrelated with education)]]
--
.center.float-left.sp-after[.box-inv-6.sp-before[3rd grade test scores] .box-5.smaller[Potentially relevant (early grades cause more education)]]
--
.center.float-left[.box-inv-6.sp-before[Father's education] .box-5.smaller[Relevant (Educated parents cause more education)]]
---
# Excludability
.box-6[Instrument causes outcome *only through* policy]
.box-inv-6.smaller.sp-after[Z β X β Y   Z ↛ Y   Cor(Z, Y | X) = 0]
<hr>
--
.center.float-left.sp-after[.box-inv-6.sp-before[Social security number] .box-5.smaller[Exclusive (SSN isn't correlated with hourly wages)]]
--
.center.float-left.sp-after[.box-inv-6.sp-before[3rd grade test scores] .box-5.smaller[Potentially exclusive (early grades probably don't cause wages)]]
--
.center.float-left[.box-inv-6.sp-before[Father's education] .box-5.smaller[Exclusive (Parent's education doesn't cause your wages (lol))]]
---
# Exogeneity
.box-6[Instrument not correlated with omitted variables]
.box-inv-6.smaller.sp-after[U ↛ Z   Cor(Z, U) = 0]
<hr>
--
.center.float-left.sp-after[.box-inv-6.sp-before[Social security number] .box-5.smaller[Exogenous (Unrelated to anything related to education)]]
--
.center.float-left.sp-after[.box-inv-6.sp-before[3rd grade test scores] .box-2.smaller[Not exogenous (Grades correlated with other education factors)]]
--
.center.float-left[.box-inv-6.sp-before[Father's education] .box-5.smaller[Exogenous (Birth to parents is random)]]
---
# The huh? factor
.box-inv-6.medium["A necessary but not a sufficient condition<br>for having an instrument that can satisfy<br>the exclusion restriction is <span style="color: #A52C60;">if people are<br>confused when you tell them about the<br>instrument's relationship to the outcome.</span>"]
.box-6.small[Scott Cunningham, *Causal Inference: The Mixtape*, p. 123]
---
layout: false
.small[
```{r instrument-examples, echo=FALSE}
instruments <- tribble(
~`Outcome`, ~`Policy`, ~`Unobserved stuff`, ~`Instrument`,
"Income", "Education", "Ability", "Father's education",
"Income", "Education", "Ability", "Distance to college",
"Income", "Education", "Ability", "Military draft",
"Health", "Smoking cigarettes", "Other negative health behaviors", "Tobacco taxes",
"Crime rate", "Patrol hours", "# of criminals", "Election cycles",
"Crime", "Incarceration rate", "Simultaneous causality", "Overcrowding litigations",
"Labor market success", "Americanization", "Ability", "Scrabble score of name",
"Conflicts", "Economic growth", "Simultaneous causality", "Rainfall"
)
instruments %>%
kbl(align = "l") %>%
row_spec(c(2:8), extra_css = "color: #ffffff; background-color: #ffffff;")
```
]
---
.small[
```{r echo=FALSE}
instruments %>%
kbl(align = "l") %>%
row_spec(3:8, extra_css = "color: #ffffff; background-color: #ffffff;")
```
]
---
.small[
```{r echo=FALSE}
instruments %>%
kbl(align = "l") %>%
row_spec(4:8, extra_css = "color: #ffffff; background-color: #ffffff;")
```
]
---
.small[
```{r echo=FALSE}
instruments %>%
kbl(align = "l") %>%
row_spec(5:8, extra_css = "color: #ffffff; background-color: #ffffff;")
```
]
---
.small[
```{r echo=FALSE}
instruments %>%
kbl(align = "l") %>%
row_spec(6:8, extra_css = "color: #ffffff; background-color: #ffffff;")
```
]
---
.small[
```{r echo=FALSE}
instruments %>%
kbl(align = "l") %>%
row_spec(7:8, extra_css = "color: #ffffff; background-color: #ffffff;")
```
]
---
.small[
```{r echo=FALSE}
instruments %>%
kbl(align = "l") %>%
row_spec(8, extra_css = "color: #ffffff; background-color: #ffffff;")
```
]
---
.small[
```{r echo=FALSE}
instruments %>%
kbl(align = "l")
```
]
---
layout: true
class: title title-6
---
# Instruments are hard to find!
.box-inv-6.medium[The trickiest thing to prove is<br>the exclusion restriction]
.box-6.sp-after[Instrument causes the outcome *only through* the policy]
--
.box-inv-6.medium[Most proposed instruments fail this!]
---
# Rainfall as an instrument
.box-inv-6[People love using weather as an instrumentβ¦ buuuuutβ¦]
--
.center[
<figure>
<img src="img/11/weather-paper.png" alt="Rainfall exclusion restrictions paper" title="Rainfall exclusion restrictions paper" width="85%">
</figure>
]
???
<https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3715610>
---
layout: false
.center[
<figure>
<img src="img/11/weather-violations.png" alt="Rainfall exclusion restrictions paper" title="Rainfall exclusion restrictions paper" width="60%">
</figure>
]
---
layout: true
class: title title-6
---
# COVID-19 as an instrument
.box-inv-6.medium[A global pandemic is a huge<br>exogenous shock to<br>social systems everywhere]
.box-6[Maybe we can use it as an instrument!]
---
# COVID-19 as an instrument
.box-inv-6[What effect does closing schools have on<br>student performance or lifetime earnings?]
```{r covid-dag-1, echo=FALSE, fig.width=8, fig.height=4, out.width="70%"}
covid_nodes <- tribble(
~name, ~label, ~x, ~y,
"treatment", "School attendance", 1, 1,
"outcome", "Grades (or earnings)", 3, 1,
"unmeasured", "Unmeasured confounders", 2, 3,
"instrument", "COVID-19", 0, 2
)
node_labels_covid <- covid_nodes$label %>%
set_names(covid_nodes$name)
covid_dag1 <- dagify(outcome ~ treatment + unmeasured,
treatment ~ unmeasured + instrument,
exposure = "treatment",
outcome = "outcome",
latent = "unmeasured",
coords = covid_nodes,
labels = node_labels_covid) %>%
tidy_dagitty() %>%
node_status() %>%
node_exogenous() %>%
node_dconnected() %>%
control_for("unmeasured")
ggplot(covid_dag1, 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 = 20) +
geom_dag_label_repel(aes(label = label, fill = status), seed = 1,
color = "white", fontface = "bold", size = 7,
family = "Fira Sans Condensed",
label.padding = grid::unit(0.5, "lines"),
box.padding = grid::unit(4, "lines"),
direction = "both") +
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 = FALSE, fill = FALSE, edge_colour = FALSE) +
theme_dag(base_size = 20)
```
---
# lolnope
```{r covid-dag-2, echo=FALSE, fig.width=14, fig.height=6, out.width="100%"}
covid_nodes_2 <- tribble(
~name, ~label, ~x, ~y,
"treatment", "School attendance", 1, 1,
"outcome", "Grades (or earnings)", 3, 1,
"unmeasured", "Unmeasured confounders", 2, 4,
"instrument", "COVID-19", -2, 1,
"deaths", "Deaths", 0, 6,
"health", "Health", 0, 5,
"jobs", "Job losses", 0, 4,
"isolation", "Social isolation", 0, 3,
"anxiety", "Anxiety", 0, 2
)
node_labels_covid_2 <- covid_nodes_2$label %>%
set_names(covid_nodes_2$name)
covid_dag2 <- dagify(outcome ~ treatment + unmeasured + deaths + health + jobs + isolation + anxiety,
treatment ~ unmeasured + instrument + deaths + health + jobs + isolation + anxiety,
deaths ~ instrument,
health ~ instrument,
jobs ~ instrument,
isolation ~ instrument,
anxiety ~ instrument,
exposure = "treatment",
outcome = "outcome",
latent = "unmeasured",
coords = covid_nodes_2,
labels = node_labels_covid_2) %>%
tidy_dagitty() %>%
node_status() %>%
node_exogenous() %>%
node_dconnected() %>%
control_for("unmeasured")
ggplot(covid_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 = 20) +
geom_dag_label_repel(aes(label = label, fill = status), seed = 1234,
color = "white", fontface = "bold", size = 7,
family = "Fira Sans Condensed",
label.padding = grid::unit(0.75, "lines"),
box.padding = grid::unit(2.5, "lines"),
direction = "y", nudge_x = 0.5) +
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 = FALSE, fill = FALSE, edge_colour = FALSE) +
theme_dag(base_size = 20)
```
???
https://twitter.com/joshuasgoodman/status/1238517897829310464
---
# Falsifying exclusion assumptions
.box-inv-6[Can you think of some other way that the instrument<br>can cause the outcome outside of the policy?]
--
.box-inv-6[If so, the instrument doesn't meet exclusion restriction]
--
.pull-left[
![](`r knitr::fig_chunk("iv-dag-general", "png")`)
]
.pull-right[
.box-6.small[Instrument β ?? β outcome?]
.box-6.small[Rainfall β ?? β civil war?]
.box-6.small[Tobacco taxes β ?? β health?]
.box-6.small[Scrabble score β ?? β<br>Labor market success?]
]
---
layout: false
name: using-instruments
class: center middle section-title section-title-3 animated fadeIn
# Using instruments
---
$$\text{Earnings}_i = \beta_0 + \beta_1 \text{Education}_i + \varepsilon_i$$
.smaller[
```{r show-table-again, echo=FALSE}
model_results <- modelsummary(list("Unadjusted" = model1, "Forbidden" = model2),
gof_omit = 'IC|Log|Adj', stars = TRUE)
model_results %>%
row_spec(c(6, 9), extra_css = "border-bottom: 1px solid") %>%
row_spec(3, background = "#F5ABEA")