-
Notifications
You must be signed in to change notification settings - Fork 20
/
05_OM.Rmd
1783 lines (1423 loc) · 87.3 KB
/
05_OM.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
# Observational Methods {#OM}
In this lecture, we are going to study how to estimate the effect of an intervention on an outcome using observational methods, that is methods which try to correct for selection bias by accounting for as many observed confounders as possible.
The key assumption that we are going to make is that of conditional independence:
```{hypothesis,CIAExp,name="Conditional Independence (in Expectation)"}
We assume that there exists a known set of observable covariates $X_i$ such that:
\begin{align*}
\esp{Y_i^0|X_i,D_i=1} & = \esp{Y_i^0|X_i,D_i=0}.
\end{align*}
```
Under Assumption \@ref(hyp:CIAExp), the expected potential outcomes of the treated in the absence of the treatment are independent of the treatment conditional on a set of observed covariates $X_i$.
As a consequence, selection bias is zero after conditioning on $X_i$, and we can recover the treatment on the treated parameter by using the With/Without comparison conditional on $X_i$:
\begin{align*}
\Delta^Y_{WW}(X_i) & = \esp{Y_i|X_i,D_i=1} - \esp{Y_i|X_i,D_i=0} \\
& = \esp{Y^1_i|X_i,D_i=1} - \esp{Y^0_i|X_i,D_i=0} \\
& = \esp{Y^1_i|X_i,D_i=1} - \esp{Y^0_i|X_i,D_i=1} \\
& = \esp{Y^1_i-Y_i^0|X_i,D_i=1}\\
& = \Delta^Y_{TT}(X_i),
\end{align*}
where the third equality uses Assumption \@ref(hyp:CIAExp).
There are several ways to use Assumption \@ref(hyp:CIAExp) (and thus Assumption \@ref(hyp:CIA)) to build estimators of the treatment effect.
Let's start with the parametric approaches and then we'll study the non-parametric approaches.
```{remark}
Assumption \@ref(hyp:CIAExp) is the minimal assumption needed to indentify the average effect of the treatment on the treated.
Researchers often use a stronger version of that assumption:
```
```{hypothesis,CIA,name="Conditional Independence"}
We assume that there exists a known set of observable covariates $X_i$ such that:
\begin{align*}
(Y_i^1,Y_i^0)\Ind D_i|X_i.
\end{align*}
```
Assumption \@ref(hyp:CIA) is stronger than Assumption \@ref(hyp:CIAExp) because it imposes conditional independence of all the distribution of $Y_i^0$, not only of its mean, and also because it imposes conditional independence of $Y_i^1$ and moreover that this independence is jointly holding for $(Y_i^1,Y_i^0)$.
```{remark}
Assumptions \@ref(hyp:CIAExp) and \@ref(hyp:CIA) are sometimes called Ignorability, Unconfoundedness or Selection on Observables.
```
## Parametric methods
We are going to study two approaches uses increasingly strong parametric assumptions.
The first assumes the functional form of $\esp{Y_i^0|X_i}$ is known.
The second assumes furthermore that the functional form of $\esp{Y_i^1|X_i}$ is known.
We finaly are going to discuss the conditions under which a simple OLS regressions identifies the treatment effect on the treated.
### Assuming $\esp{Y_i^0|X_i}$ is known
Let's study identification, estimation and inference when $\esp{Y_i^0|X_i}$ is known
#### Identification
The most simple assumption that we can make in order to identify the treatment on the treated parameter under Conditional Indepedence is that the functional form of $\esp{Y_i^0|X_i}$ is known (and for example is linear):
```{hypothesis,paramff0,names='Parametric functional form for the untreated'}
We assume that there exists a known set of observable covariates $X_i$ such that:
\begin{align*}
\esp{Y_i^0|X_i} & = \alpha_0+\beta_0'X_i.
\end{align*}
```
One way to use this assumption to identify the effect of the treatment on the treated is to follow the following steps:
1. Estimate $\alpha_0$ and $\beta_0$ on the population of untreated individuals.
2. Use these estimates to predict potential outcomes for the treated.
3. Compute the difference between the observed potential outcomes and the simulated ones for the treated observations.
In practice, this estimator, which I call $\Delta^Y_{WWOLS(X)}$, is equal to:
\begin{align*}
\Delta^Y_{WWOLS(X)} & = \esp{Y_i-\alpha_0-\beta_0'X_i|D_i=1}.
\end{align*}
Under the assumptions we've made so far, $\Delta^Y_{WWOLS(X)}$ identifies $TT$:
```{theorem,olsid,name='Identification of TT using OLS'}
Under Assumptions \@ref(hyp:CIAExp) and \ref@(hyp:paramff0), TT is identified using the WW comparison adjusted by the OLS projection.
\begin{align*}
\Delta^Y_{WWOLS(X)} & = \Delta^Y_{TT}.
\end{align*}
```
```{proof}
Under Assumptions \@ref(hyp:CIAExp) and \ref@(hyp:paramff0), we have:
\begin{align*}
\esp{Y_i^0|D_i=0,X_i} & = \esp{Y_i^0|X_i} = \alpha_0+\beta_0'X_i.
\end{align*}
As a consequence, $\alpha_0$ and $\beta_0$ are identified by using the untreated population, as long as the components of $X$ are not colinear.
Then, we have:
\begin{align*}
\Delta^Y_{WWOLS(X)} & = \esp{Y_i-\alpha_0-\beta_0'X_i|D_i=1}\\
& = \esp{Y_i-\esp{Y_i^0|D_i=1,X_i}|D_i=1}\\
& = \esp{Y_i|D_i=1}-\esp{\esp{Y_i^0|D_i=1,X_i}|D_i=1}\\
& = \esp{Y^1_i|D_i=1}-\esp{Y^0_i|D_i=1}\\
& = \Delta^Y_{TT},
\end{align*}
where the first equality is the definition of the second step of the OLS projection procedure, the second equality is a consequence of Assumptions \@ref(hyp:CIAExp) and \ref@(hyp:paramff0), the third and fifth equalities use the linearity of conditional expectations and the fourth equality uses the Law of Iterated Expectations.
```
#### Estimation
Estimation can follow in the sample steps similar to the ones taken in the population:
1. Estimate $\hat{\alpha_0}$ and $\hat{\beta_0}$ using an OLS regression of $Y_i$ on $X_i$ on the sample of untreated individuals.
2. Predict the counterfactual values for each treated using $\hat{Y_i^0}=\hat{\alpha_0}+\hat{\beta_0}'X_i$.
3. Compute $\hat{\Delta}^Y_{WWOLS(X)}=\frac{1}{\sum_{i=1}^ND_i}\sum_{i=1}^ND_i(Y_i^1-\hat{Y_i^0})$.
```{example}
Let's see how this works in our example.
```
Let's first choose some parameter values:
```{r paramMatch,eval=TRUE,echo=TRUE,results='hide'}
param <- c(8,.5,.28,1500,0.9,0.01,0.05,0.05,0.05,0.1)
names(param) <- c("barmu","sigma2mu","sigma2U","barY","rho","theta","sigma2epsilon","sigma2eta","delta","baralpha")
```
Let us now simulate the data:
\begin{align*}
y_i^1 & = y_i^0+\bar{\alpha}+\theta\mu_i+\eta_i \\
y_i^0 & = \mu_i+\delta+U_i^0 \\
U_i^0 & = \rho U_i^B+\epsilon_i \\
y_i^B & =\mu_i+U_i^B \\
U_i^B & \sim\mathcal{N}(0,\sigma^2_{U}) \\
D_i & = \uns{y_i^B\leq\bar{y}} \\
(\eta_i,\mu_i,\epsilon_i) & \sim\mathcal{N}(0,0,0,\sigma^2_{\eta},\sigma^2_{\mu},\sigma^2_{\epsilon},0,0,0).
\end{align*}
```{r simulMatch,eval=TRUE,echo=TRUE,results='hide'}
set.seed(1234)
N <-1000
mu <- rnorm(N,param["barmu"],sqrt(param["sigma2mu"]))
UB <- rnorm(N,0,sqrt(param["sigma2U"]))
yB <- mu + UB
YB <- exp(yB)
Ds <- rep(0,N)
Ds[YB<=param["barY"]] <- 1
epsilon <- rnorm(N,0,sqrt(param["sigma2epsilon"]))
eta<- rnorm(N,0,sqrt(param["sigma2eta"]))
U0 <- param["rho"]*UB + epsilon
y0 <- mu + U0 + param["delta"]
alpha <- param["baralpha"]+ param["theta"]*mu + eta
y1 <- y0+alpha
Y0 <- exp(y0)
Y1 <- exp(y1)
y <- y1*Ds+y0*(1-Ds)
Y <- Y1*Ds+Y0*(1-Ds)
```
Let us now plot the sample and the procedure to estimate $\hat{\Delta}^Y_{WWOLS(X)}$:
```{r plotOLSEstimSteps,eval=TRUE,echo=TRUE,results='hide',fig.cap='Estimating treatment effects using WWOLS(X)',fig.subcap=c('Sample','Step 1','Step 2','Step 3'),fig.align='center',out.width='45%',fig.pos='htbp'}
col.obs <- 'black'
col.unobs <- 'red'
lty.obs <- 1
lty.unobs <- 2
xlim.big <- c(-1.5,0.5)
xlim.small <- c(-0.15,0.55)
adj <- 0
# Sample
plot(yB[Ds==0],y0[Ds==0],pch=1,xlim=c(5,11),ylim=c(5,11),xlab="yB",ylab="Outcomes")
points(yB[Ds==1],y0[Ds==1],pch=1,col=col.unobs)
abline(v=log(param["barY"]),col=col.unobs)
legend(5,11,c('y0|D=0','y0|D=1'),pch=c(1,1),col=c(col.obs,col.unobs),ncol=1)
# Step 1
ols.reg.0 <- lm(y[Ds==0]~yB[Ds==0])
plot(yB[Ds==0],y0[Ds==0],pch=1,xlim=c(5,11),ylim=c(5,11),xlab="yB",ylab="Outcomes")
points(yB[Ds==1],y0[Ds==1],pch=1,col=col.unobs)
points(yB[Ds==0],ols.reg.0$fitted.values,col='blue')
abline(v=log(param["barY"]),col=col.unobs)
legend(5,11,c('y0|D=0','y0|D=1',expression(hat('y0|D=0'))),pch=c(1,1,1),col=c(col.obs,col.unobs,'blue'),ncol=2)
# step 2
y.pred <- ols.reg.0$coef[[1]]+ols.reg.0$coef[[2]]*yB[Ds==1]
plot(yB[Ds==0],y0[Ds==0],pch=1,xlim=c(5,11),ylim=c(5,11),xlab="yB",ylab="Outcomes")
points(yB[Ds==1],y0[Ds==1],pch=1,col=col.unobs)
points(yB[Ds==0],ols.reg.0$fitted.values,col='blue')
points(yB[Ds==1],y.pred,pch=3,col='blue')
abline(v=log(param["barY"]),col=col.unobs)
legend(5,11,c('y0|D=0','y0|D=1',expression(hat('y0|D=0')),expression(hat('y0|D=1'))),pch=c(1,1,1,3),col=c(col.obs,col.unobs,'blue','blue'),ncol=2)
# step 3
ww.ols <- mean(y[Ds==1]-y.pred)
plot(yB[Ds==0],y0[Ds==0],pch=1,xlim=c(5,11),ylim=c(5,11),xlab="yB",ylab="Outcomes")
points(yB[Ds==1],y0[Ds==1],pch=1,col=col.unobs)
points(yB[Ds==0],ols.reg.0$fitted.values,col='blue')
points(yB[Ds==1],y.pred,col='blue')
points(yB[Ds==1],y[Ds==1],pch=3,col='black')
abline(v=log(param["barY"]),col=col.unobs)
legend(5,11,c('y0|D=0','y0|D=1','y1|D=1',expression(hat('y0|D=0')),expression(hat('y0|D=1'))),pch=c(1,1,3,1,3),col=c(col.obs,col.unobs,col.obs,'blue','blue'),ncol=2)
```
Let's also compute the true values of the treatment effects in the population:
```{r delta.y.tt.again,eval=TRUE,echo=TRUE,results='hide'}
delta.y.tt <- function(param){
return(param["baralpha"]+param["theta"]*param["barmu"]-param["theta"]*((param["sigma2mu"]*dnorm((log(param["barY"])-param["barmu"])/(sqrt(param["sigma2mu"]+param["sigma2U"]))))/(sqrt(param["sigma2mu"]+param["sigma2U"])*pnorm((log(param["barY"])-param["barmu"])/(sqrt(param["sigma2mu"]+param["sigma2U"]))))))
}
delta.y.ate <- function(param){
return(param["baralpha"]+param["theta"]*param["barmu"])
}
```
The true effect of the treatment on the treated in the population is equal to `r round(delta.y.tt(param),2)` and our estimator, $\hat{\Delta}^Y_{WWOLS(X)}$, is equal to `r round(ww.ols,2)`.
#### Estimating precision
Estimating the precision of this estimator can be done using the bootstrap.
Or we could derive its distribution using the CLT.
**TO DO**
### Assuming $\esp{Y_i^1|X_i}$ is known
One way to make our estimation procedure even simpler than using the $WWOLS(X)$ estimator is to assume that $\esp{Y_i^1|X_i}$ is also linear.
In that case, we are going to be able to use the OLS estimator conditioning on $X_i$ to estimate the average treatment effect on the treated.
We are going to see that this estimator will have a peculiar shape.
We'll understand better why in Section \@ref(BiasOLS).
Let's start with how to use OLS under linearity of conditional expectations.
#### Identification
Let's assume that we also know the functional form of $\esp{Y_i^1|X_i}$:
```{hypothesis,paramff1,names='Parametric functional form for the treated'}
We assume that there exists a known set of observable covariates $X_i$ such that:
\begin{align*}
\esp{Y_i^1|X_i} & = \alpha_1+\beta_1'X_i.
\end{align*}
```
The first thing we can show is that we now have a parametric formula for our target parameter $TT$ (using the slighlty stronger version of the Conditional Indepedence Assumption):
```{theorem,TTff,name='TT under Linearity of Conditional Expectations'}
Under Assumptions \@ref(hyp:CIA), \@ref(hyp:paramff0) and \@ref(hyp:paramff1), the Treatment on the Treated parameter simplifies to:
\begin{align*}
\Delta^Y_{TT} & = \alpha_1-\alpha_0+(\beta_1-\beta_0)'\esp{X_i|D_i=1}.
\end{align*}
```
```{proof}
\begin{align*}
\Delta^Y_{TT} & = \esp{Y_i^1-Y_i^0|D_i=1} \\
& = \esp{\esp{Y_i^1-Y_i^0|X_i,D_i=1}|D_i=1} \\
& = \esp{\esp{Y_i^1|X_i,D_i=1}-\esp{Y_i^0|X_i,D_i=1}|D_i=1} \\
& = \esp{\esp{Y_i^1|X_i}-\esp{Y_i^0|X_i}|D_i=1} \\
& = \esp{\alpha_1+\beta_1'X_i-(\alpha_0+\beta_0'X_i)|D_i=1} \\
& = \alpha_1-\alpha_0+(\beta_1-\beta_0)'\esp{X_i|D_i=1},
\end{align*}
where the second equality follows from the Law of Iterated Exppectations, the third equality from Assumption \@ref(hyp:CIA) and the fourth equality from Assumptions \@ref(hyp:paramff0) and \@ref(hyp:paramff1).
```
```{remark}
Theorem \@ref(thm:TTff) shows that under our assumptions, treatment effects are heterogenous in a way that is correlated with the treatment only because of differences in $X_i$.
```
Equipped with this result, we can now state the identification result of this section:
```{theorem,WWOLS10,name='OLS Identifies TT under Linearity and Conditional Independence'}
Under Assumptions \@ref(hyp:CIA), \@ref(hyp:paramff0) and \@ref(hyp:paramff1), the OLS coefficient $\delta$ in the following regression:
\begin{align*}
Y_i & = \alpha_0 + \beta_0'X_i + (\beta_1-\beta_0)'\left(X_i-\esp{X_i|D_i=1}\right)D_i + \delta D_i + U_i
\end{align*}
identifies the effect of the treatment on the treated.
We denote: $\delta=\Delta^Y_{OLS(X)}$.
```
```{proof}
Under Assumptions \@ref(hyp:paramff0) and \@ref(hyp:paramff1), we have $Y_i^d=\alpha_d + \beta_d'X_i +Y_i^d-\esp{Y_i^d|X_i}$, for $d\in\left\{0,1\right\}$.
As a consequence, we have:
\begin{align*}
Y_i & = Y_i^0+D_i(Y_i^1-Y_i^0) \\
& = \alpha_0 + \beta_0'X_i +D_i(\alpha_1-\alpha_0 + (\beta_1-\beta_0)'X_i)\\
& \phantom{=}+Y_i^0-\esp{Y_i^0|X_i}+D_i(Y_i^1-Y_i^0-(\esp{Y_i^1|X_i}-\esp{Y_i^0|X_i}))\\
& = \alpha_0 + \beta_0'X_i + (\beta_1-\beta_0)'\left(X_i-\esp{X_i|D_i=1}\right)D_i + (\alpha_1-\alpha_0 + (\beta_1-\beta_0)'\esp{X_i|D_i=1})D_i\\
& \phantom{=}+\underbrace{Y_i^0-\esp{Y_i^0|X_i}+D(Y_i^1-Y_i^0-\esp{Y_i^1-Y_i^0|X_i})}_{U_i}\\
& = \alpha_0 + \beta_0'X_i + (\beta_1-\beta_0)'\left(X_i-\esp{X_i|D_i=1}\right)D_i + \Delta^Y_{TT}D_i +U_i,
\end{align*}
where the first equation uses the Switching Equation, the second equation uses Assumptions \@ref(hyp:paramff0) and \@ref(hyp:paramff1) and the last equation uses Theorem \@ref(thm:TTff).
We are now going to show that $\esp{U_i|X_i,D_i}=0$.
\begin{align*}
\esp{U_i|X_i,D_i=0} & = \esp{Y_i^0-\esp{Y_i^0|X_i}|X_i,D_i=0}\\
& =\esp{Y_i^0|X_i,D_i=0}-\esp{\esp{Y_i^0|X_i}|X_i,D_i=0}\\
& =\esp{Y_i^0|X_i,D_i=0}-\esp{\esp{Y_i^0|X_i,D_i=0}|X_i,D_i=0}\\
& =\esp{Y_i^0|X_i,D_i=0}-\esp{Y_i^0|X_i,D_i=0}\\
& = 0\\
\esp{U_i|X_i,D_i=1} & = \esp{Y_i^0-\esp{Y_i^0|X_i}|X_i,D_i=1}+\esp{Y_i^1-Y_i^0-\esp{Y_i^1-Y_i^0|X_i}|X_i,D_i=1}\\
& =\esp{Y_i^1-Y_i^0|X_i,D_i=1}-\esp{\esp{Y_i^1-Y_i^0|X_i}|X_i,D_i=1} \\
& =\esp{Y_i^1-Y_i^0|X_i,D_i=1}-\esp{\esp{Y_i^1-Y_i^0|X_i,D_i=1}|X_i,D_i=1} \\
& = 0,
\end{align*}
where the third and eighth equalities follow from Assumption \@ref(hyp:CIA).
We thus have $\esp{Y_i|X_i,D_i}=\alpha_0 + \beta_0'X_i + (\beta_1-\beta_0)'\left(X_i-\esp{X_i|D_i=1}\right)D_i + \Delta^Y_{TT}D_i$.
Theorem \@ref(thm:LinearCEF) ensures that the OLS estimator identifies the parameters of this model.
As a consequence, $\Delta^Y_{TT}$ is identified by the OLS estimator of $\delta$ in the model.
This completes the proof.
```
#### Estimation
What is pretty nice with Theorem \@ref(thm:WWOLS10) is that it suggests directly an estimation strategy.
Let's estimate $\hat\delta^{OLS}$ in the following regression:
\begin{align*}
Y_i & = \alpha_0 + \beta_0'X_i + (\beta_1-\beta_0)'\left(X_i-\esp{X_i|D_i=1}\right)D_i + \delta D_i + U_i.
\end{align*}
```{example}
Let's see what happens in our example when doing that.
```
```{r ww.ols.direct,eval=TRUE,echo=TRUE,results='hide'}
# deameaning the control variable
yB.Ds <-(yB-mean(yB[Ds==1]))*Ds
# running the OLS estimator with interactions between treatment and demeaned covariate
ols.direct <- lm(y~yB+Ds+yB.Ds)
# estimate of TT
ww.ols.direct <- ols.direct$coef[[3]]
```
Our estimator is equal to `r round(ww.ols.direct,2)`, while the true effect of the treatment on the treated in the population is equal to `r round(delta.y.tt(param),2)`.
**Monte Carlo simulations**
#### Estimating precision
Estimating precision is pretty straightforward in our case.
What is going to happen with respect to a simple WW estimator that does not condition on covariates is that the asymptotic variance of the estimated treatment effect is going to depend on the variance of outcomes conditional on observed covariates $X_i$.
As a consequence, and as we have already seen in Chapter \@ref(RCT), precision will increase as long as the covariates we control for explain part of the variance of the outcome.
The main issue that we have to deal with is that of heteroskedasticity: $U_i$ is correlated with both $X_i$ and $D_i$.
So we need to use a heteroskedasticity-robust estimator for the variance of the treatment effect.
Let us first state the main result.
For that, we need to reformulate the classical assumptions so that they cover the case with covariates:
```{hypothesis,iidX,name='i.i.d. sampling with covariates'}
We assume that the observations in the sample are identically and independently distributed:
\begin{align*}
\forall i,j\leq N\text{, }i\neq j\text{, } & (Y_i,D_i,X_i)\Ind(Y_j,D_j,X_j),\\
& (Y_i,D_i,X_i)\&(Y_j,D_j,X_j)\sim F_{Y,D,X}.
\end{align*}
```
```{hypothesis,finitevarX,name='Finite variances of potential outcomes conditional on covariates'}
We assume that $\var{Y_i^1|X_i,D_i=1}$ and $\var{Y_i^0|X_i,D_i=0}$ are finite.
```
We can now state our main result:
```{theorem,AsympWWOLS10,name='Distribution of the OLS Estimator of TT under Conditional Independence'}
Under Assumptions \@ref(hyp:CIA), \@ref(hyp:paramff0), \@ref(hyp:paramff1), \@ref(hyp:fullrank), \@ref(hyp:iidX) and \@ref(hyp:finitevarX), we have:
\begin{align*}
\sqrt{N}(\hat\Delta^Y_{OLS(X)}-\Delta^Y_{TT}) & \stackrel{d}{\rightarrow}
\mathcal{N}\left(0,\frac{\var{Y^0_i|X_i,D_i=0}}{1-p}+\frac{\var{Y^1_i|X_i,D_i=1}}{p}\right),
\end{align*}
with $p=\Pr(D_i=1)$.
```
```{proof}
See Section \@ref(proofAsympWWOLS10) in the Appendix.
```
```{remark}
Theorem \@ref(thm:AsympWWOLS10) is super powerful: it tells us that conditioning on observed covariates yields an improvement in precision equivalent to the part of the variance of $Y_i$ explained by the observed covariates.
What is nice as well is that the distribution of the OLS estimator with controls has the same flavor as the distribution of the silpler With/Without estimator derived in Theorem \@ref(thm:asympnoiseWW) (and in Lemma \@ref(lem:asymWW)).
```
```{remark}
In order to operationalize Theorem \@ref(thm:AsympWWOLS10), one can either use the formula or simply use the heteroskedasticity-robust variance-covariance matrix proposed for the OLS estimator.
Both estimators should be similar.
Let $\Theta=(\alpha_0,\beta_0,\beta_1,\delta)$ and $X$ be the matrix of all regressors, with a first column of ones and the last column of $D_i$.
Most available heteroskedasticity robust estimators based on the CLT can be written in the following way:
\begin{align*}
\var{\hat{\Theta}_{OLS}} & \approx (X'X)^{-1}X'\hat{\Omega}X(X'X)^{-1},
\end{align*}
where $\hat{\Omega}=\diag(\hat{\sigma}^2_{U_1},\dots,\hat{\sigma}^2_{U_N})$ is an estimate the covariance matrix of the residuals $U_i$.
Here are various classical estimators for $\hat{\Omega}$:
\begin{align*}
\text{HC0:} & & \hat{\sigma_{U_i}}^2 & = \hat{U_i}^2 \\
\text{HC1:} & & \hat{\sigma_{U_i}}^2 & = \frac{N}{N-K}\hat{U_i}^2 \\
\text{HC2:} & & \hat{\sigma_{U_i}}^2 & = \frac{\hat{U_i}^2}{1-h_i} \\
\text{HC3:} & & \hat{\sigma_{U_i}}^2 & = \frac{\hat{U_i}^2}{(1-h_i)^2},
\end{align*}
where $\hat{U}_i$ is the residual from the OLS regression, $K$ is the number of regressors, $h_i$ is the leverage of observation $i$, and is the $i^{\text{th}}$ diagonal element of $H=X(X'X)^{-1}X'$.
HC1 is the one reported by Stata when using the 'robust' option.
All of these estimators are programmed in the [sandwich](https://cran.r-project.org/web/packages/sandwich/vignettes/sandwich.pdf) package.
```
```{example}
Let's see how our estimator works to estimate precision.
```
We can first try to implement the formula.
```{r WWOLSWForm,echo=TRUE}
# regs on X in both smaples
ols.reg.0 <- lm(y[Ds==0]~yB[Ds==0])
ols.reg.1 <- lm(y[Ds==1]~yB[Ds==1])
# variance
var.delta.ols <- 1/N*(var(ols.reg.0$residuals)/(1-mean(Ds))+var(ols.reg.1$residuals)/(mean(Ds)))
```
We can now try to see what the heteroskedasticity-robust variance estimator gives.
```{r ww.ols.direct.HC1,echo=TRUE}
ols.direct.HC1 <- vcovHC(ols.direct,type='HC1')
```
The robust standard error using HC1 is thus `r round(sqrt(ols.direct.HC1[3,3]),2)`, while the default standard error assuming homoskedasticity is `r round(sqrt(vcov(ols.direct)[3,3]),2)`.
The estimate obtained using Theorem \@ref(thm:AsympWWOLS10) directly is equal to `r round(sqrt(var.delta.ols),2)`.
### Properties of the OLS estimator under Conditional Independence {#BiasOLS}
As we have seen in Chapter \@ref(RCT), we could also have estimated $TT$ using a regression omitting the interaction between the treatment indicator and control variables.
With RCTs, this did not matter for the final result.
With Observational Methods, this might make a huge difference.
The reason is that the distribution of the observed covariates in the treatment and control group are the same in expectation in an RCT, while they are by essence different under Conditional Independence.
As a consequence, when we estimate a model by OLS which does not insert interactions of the covariates, we might end up with a different parameter than the one we are after.
[Sloczynski (2020)](https://doi.org/10.1162/rest_a_00953) studies this issue in great detail ([Goldsmith-Pinkham, Hull and Kolesar (2022)](http://arxiv.org/abs/2106.05024) make also progress on this front, but in a more general way.)
In order to derive his result, [Sloczynski (2020)](https://doi.org/10.1162/rest_a_00953) slightly strengthens the assumptions we have made so far, especially by making potential outcomes dependent on $X_i$ only through the propensity score: $p(X_i)=\Pr(D_i=1|X_i)$.
[Sloczynski (2020)](https://doi.org/10.1162/rest_a_00953)'s main result concerns $\delta$ estimated by OLS in the following regression:
\begin{align*}
Y_i & = \alpha + \beta' X_i + \delta D_i + U_i.
\end{align*}
```{theorem,OLSWeights,name='Weighted Average Interpretation of OLS'}
Under Assumptions \@ref(hyp:CIAExp), \@ref(hyp:paramff0), \@ref(hyp:paramff1), \@ref(hyp:finitevarX) (modified to hold with $p(X_i)$ replacing $X_i$) and assuming that $\esp{Y_i^2}$ and $\esp{\lVert X_i^2 \rVert}$ are finite and that the covariance matrix of $(D_i,X_i)$ is non singular, we have $\delta$ in the previous equation when estimated by OLS equal to:
\begin{align*}
\delta^{OLS} & = w_1\Delta^Y_{TT}+w_0\Delta^Y_{TUT},
\end{align*}
with:
\begin{align*}
w_1 & = \frac{(1-p)\var{p(X_i)|D_i=0}}{p\var{p(X_i)|D_i=1}+(1-p)\var{p(X_i)|D_i=0}}\\
w_0 & = \frac{p\var{p(X_i)|D_i=1}}{p\var{p(X_i)|D_i=1}+(1-p)\var{p(X_i)|D_i=0}} = 1-w_1.
\end{align*}
and $p=\Pr(D_i=1)$.
```
```{proof}
See [Sloczynski (2020)](https://doi.org/10.1162/rest_a_00953).
```
```{remark}
Theorem \@ref(thm:OLSWeights) shows that OLS without interactions between the treatment and the covariates is a weighted average of the effect of the treatment on the treated ($\Delta^Y_{TT}$) and of the effect of the treatment on the untreated ($\Delta^Y_{TUT}=\esp{Y_i^1-Y_i^0|D_i=1}$).
This is thus not the parameter we are after.
Fortunately, the weights are positive and sum to one, so that we still find a weighted average of treatment effects with positive weights
Unfortunately, the weigths do not behave as we would like.
For example, $w_1$, the weight on $TT$, becomes larger as the proportion of the UNtreated increases.
This is inconvenient for estimating the $ATE$.
It is also inco,venient for estimating $TT$, since how close $\delta^{OLS}$ is to $TT$ depends on whether there are a lot of treated units in the population (in which case $\delta^{OLS}$ will be closer to $TUT$) or not (in which case, $\delta^{OLS}$ will be closer to $TT$).
```
```{example}
Let's see how this result plays out in our example.
Note however than treatment effect heterogeneity might not be enough to alter our estimates strongly.
```
Let's estimate a model without interactions:
```{r estimOLSSimp,eval=TRUE,echo=TRUE}
# running the OLS estimator without interactions
ols.simp <- lm(y~yB+Ds)
# estimate of TT
ww.ols.simp <- ols.simp$coef[[3]]
```
The estimate of $TT$ using the OLS regression without interactions is equal to `r round(ww.ols.simp,3)`, while our estimate obtained with the added interaction term is equal to `r round(ww.ols.direct,3)`.
### Problems with parametric methods
When the conditional expectation of outcomes given the covariates is not linear, parametric methods which make this assumption will be erroneous.
We will talk of specification bias.
```{example}
Let's see why in our example:
```
We write outcomes as a non linear function of the pre-treatment covariate $y_i^B$:
\begin{align*}
y^0_i & =\mu_i+\delta+\gamma (y_i^B - \bar{y^B})^2 + U_i^0.
\end{align*}
Let's choose some parameters:
```{r param.nonlin.match,eval=TRUE,echo=TRUE,results='hide'}
param <- c(param,0.1,7.98)
names(param) <- c("barmu","sigma2mu","sigma2U","barY","rho","theta","sigma2epsilon","sigma2eta","delta","baralpha","gamma","baryB")
```
and then simulate a dataset:
```{r simul.nonlin,eval=TRUE,echo=TRUE,results='hide'}
set.seed(1234)
N <-1000
mu <- rnorm(N,param["barmu"],sqrt(param["sigma2mu"]))
UB <- rnorm(N,0,sqrt(param["sigma2U"]))
yB <- mu + UB
YB <- exp(yB)
Ds <- rep(0,N)
Ds[YB<=param["barY"]] <- 1
epsilon <- rnorm(N,0,sqrt(param["sigma2epsilon"]))
eta<- rnorm(N,0,sqrt(param["sigma2eta"]))
U0 <- param["rho"]*UB + epsilon
y0 <- mu + U0 + param["delta"] + param["gamma"]*(yB-param["baryB"])^2
alpha <- param["baralpha"]+ param["theta"]*mu + eta
y1 <- y0+alpha
Y0 <- exp(y0)
Y1 <- exp(y1)
y <- y1*Ds+y0*(1-Ds)
Y <- Y1*Ds+Y0*(1-Ds)
```
If we estimate the conditional expectation on the untreated population using a linear model, we are going to have biased predictions of the truth.
Let's first estimate the regression function:
```{r ols.reg.0.nonlin,eval=TRUE,echo=TRUE,results='hide'}
ols.reg.0 <- lm(y[Ds==0]~yB[Ds==0])
# predicted values for the treated
y.pred <- ols.reg.0$coef[[1]]+ols.reg.0$coef[[2]]*yB[Ds==1]
# estimated treatment effect by WWOLSX
ww.ols <- mean(y[Ds==1]-y.pred)
# true value of TT in the sample
tt.sample <- mean(alpha[Ds==1])
```
```{r PlotOLSNonLin,eval=TRUE,echo=TRUE,fig.cap='Biased parametric estimator',fig.align='center',out.width='65%',fig.pos='htbp'}
plot(yB[Ds==0],y0[Ds==0],pch=1,xlim=c(5,11),ylim=c(5,11),xlab="yB",ylab="Outcomes")
points(yB[Ds==1],y0[Ds==1],pch=1,col='red')
points(yB[Ds==0],ols.reg.0$fitted.values,col='blue')
points(yB[Ds==1],y.pred,pch=3,col='blue')
points(yB[Ds==1],y[Ds==1],pch=3,col='black')
abline(v=log(param["barY"]),col='red')
legend(5,11,c('y0|D=0','y0|D=1','y1|D=1',expression(hat('y0|D=0')),expression(hat('y0|D=1'))),pch=c(1,1,3,1,3),col=c('black','red','black','blue','blue'),ncol=2)
```
We can see on Figure \@ref(fig:PlotOLSNonLin) that the predicted values for the potential outcomes of the treated in the absence of the treatment ($\hatesp{y_i^0|D_i=1,y_i^B}$) based on the regression estimated on the untreated observations (in blue) are too low compared with the true values (in red).
As a consequence, the OLS estimator is going to over estimate the true effect of the treatment.
Indeed, the OLS estimate of the effect of the treatment is equal to `r round(ww.ols,2)` while the true value of the treatment effect in the sample is equal to `r round(tt.sample,2)`.
## Nonparametric methods
Nonparametric observational methods enable to avoid (or at least mitigate) the issue of specification bias.
In exchange, they have stronger requirements than parametric methods in terms of comparability between treated and control observations.
The idea is that nonparametric methods rely on local comparisons to avoid specification bias.
For that, we need that treated and untreated observations overlap.
We call this assumption the Common Support Assumption, and it is required for nonparametric methods to solve the issue of specification bias.
```{hypothesis,comsupp,name='Common Support'}
We assume that, for the known set of observable covariates $X_i$ for which the Selection on Observables Assumption holds, we have:
\begin{align*}
0<\Pr(D_i=1|X_i)<1.
\end{align*}
```
```{example}
Assumption \@ref(hyp:comsupp) does not hold on Figure \@ref(fig:PlotOLSNonLin).
The probability of receiving treatment jumps discontinuously at $y_i^B=\bar{y}$ from $1$ to $0$.
```
Let's generate some data with common support.
For that, we are going to modify the selection equation to add some noise so that units with similar $y_i^B$ might end up treated or untreated:
\begin{align*}
D_i & = \uns{y_i^B+V_i\leq\bar{y}} \\
V_i & \Ind Y_i^0 \\
V_i & \sim\mathcal{N}(0,\sigma^2_{\mu}+\sigma^2_{U})
\end{align*}
Let's now generate some data following this new selection equation:
```{r simul.com.supp.match,eval=TRUE,echo=TRUE,results='hide'}
set.seed(1234)
mu <- rnorm(N,param["barmu"],sqrt(param["sigma2mu"]))
UB <- rnorm(N,0,sqrt(param["sigma2U"]))
yB <- mu + UB
YB <- exp(yB)
Ds <- rep(0,N)
V <- rnorm(N,0,sqrt(param["sigma2mu"]+param["sigma2U"]))
Ds[yB+V<=log(param["barY"])] <- 1
epsilon <- rnorm(N,0,sqrt(param["sigma2epsilon"]))
eta<- rnorm(N,0,sqrt(param["sigma2eta"]))
U0 <- param["rho"]*UB + epsilon
y0 <- mu + U0 + param["delta"] + param["gamma"]*(yB-param["baryB"])^2
alpha <- param["baralpha"]+ param["theta"]*mu + eta
y1 <- y0+alpha
Y0 <- exp(y0)
Y1 <- exp(y1)
y <- y1*Ds+y0*(1-Ds)
Y <- Y1*Ds+Y0*(1-Ds)
```
Let's plot this new dataset and examine it for common support:
```{r PlotComSupp,eval=TRUE,echo=TRUE,fig.cap='Common Support Holds',fig.align='center',out.width='65%',fig.pos='htbp'}
par(mar=c(5,4,4,5))
plot(yB[Ds==0],y0[Ds==0],pch=1,xlim=c(5,11),ylim=c(5,11),xlab="yB",ylab="Outcomes")
points(yB[Ds==1],y[Ds==1],pch=3,col='blue')
abline(v=log(param["barY"]),col='red')
legend(5,10.5,c('y0|D=0','y1|D=1','D'),pch=c(1,3,2),col=c(col.obs,'blue',col.unobs),ncol=1)
par(new=TRUE)
plot(yB,Ds,pch=2,col=col.unobs,xlim=c(5,11),xaxt="n",yaxt="n",xlab="",ylab="")
axis(4)
mtext("D",side=4,line=3)
```
Figure \@ref(fig:PlotComSupp) shows that we now have treated and untreated units on both sides of $y_i^B=\bar{y}$.
Before we move to the identification of $TT$ under Assumption \@ref(hyp:comsupp), we need to compute the true value of the $TT$ parameter in the population in our new example:
Because we have changed the selection rule, the value of $TT$ in the population has changed also:
\begin{align*}
\Delta_{TT}^y & =\bar{\alpha}+\theta\bar{\mu} -\theta\frac{\sigma^2_{\mu}}{\sqrt{2(\sigma^2_{\mu}+\sigma^2_{U})}}\frac{\phi\left(\frac{\bar{y}-\bar{\mu}}{\sqrt{2(\sigma^2_{\mu}+\sigma^2_{U})}}\right)}{\Phi\left(\frac{\bar{y}-\bar{\mu}}{\sqrt{2(\sigma^2_{\mu}+\sigma^2_{U})}}\right)}.
\end{align*}
Let's write a fiunction to compute this parameter:
```{r delta.y.tt.com.supp,eval=TRUE,echo=TRUE,results='hide'}
delta.y.tt.com.supp <- function(param){
return(param["baralpha"]+param["theta"]*param["barmu"]-param["theta"]*((param["sigma2mu"]*dnorm((log(param["barY"])-param["barmu"])/(sqrt(2*(param["sigma2mu"]+param["sigma2U"])))))/(sqrt(2*(param["sigma2mu"]+param["sigma2U"]))*pnorm((log(param["barY"])-param["barmu"])/(sqrt(2*(param["sigma2mu"]+param["sigma2U"])))))))
}
delta.y.tt.CS.pop <- delta.y.tt.com.supp(param)
```
The value of $TT$ in the population in our new example is `r round(delta.y.tt.CS.pop,2)`.
### Identification
Let's now derive identification of $TT$:
```{theorem,socsid,name='Identification of TT Under Conditional Independence and Common Support'}
Under Assumptions \@ref(hyp:CIAExp) (or the stronger \@ref(hyp:CIA)) and \@ref(hyp:comsupp), $TT$ is identified using either a nonparametric regression approach or a reweighting approach:
\begin{align*}
\Delta^Y_{TT} & = \Delta^Y_{NPR(X)} = \Delta^Y_{RW(X)},
\end{align*}
with:
\begin{align*}
\Delta^Y_{NPR(X)} & = \esp{Y_i-\esp{Y_i|X_i,D_i=0}|D_i=1} \\
\Delta^Y_{RW(X)} & = \esp{Y_i|D_i=1} \\
& \phantom{=} -\esp{Y_i\frac{\Pr(D_i=1|X_i)}{1-\Pr(D_i=1|X_i)}\frac{1-\Pr(D_i=1)}{\Pr(D_i=1)}|D_i=0}.
\end{align*}
```
```{proof}
Let us start with the first equality:
\begin{align*}
\Delta^Y_{NPR(X)} & = \esp{Y_i-\esp{Y_i|X_i,D_i=0}|D_i=1} \\
& = \esp{Y_i|D_i=1}-\esp{\esp{Y_i|X_i,D_i=0}|D_i=1}\\
& = \esp{Y^1_i|D_i=1}- \esp{\esp{Y^0_i|X_i,D_i=0}|D_i=1} \\
& = \esp{Y^1_i|D_i=1}- \esp{\esp{Y^0_i|X_i,D_i=1}|D_i=1} \\
& = \esp{Y^1_i|D_i=1}- \esp{Y^0_i|D_i=1} \\
& = \Delta^Y_{TT},
\end{align*}
where the second equality follows from the linearity of linear expectations, the fourth equality follows from Assumptions \@ref(hyp:CIAExp) and \@ref(hyp:comsupp) and the fifth equality follows from the Law of Iterated Expectations.
Let us now examine the second equality:
\begin{align*}
\Delta^Y_{RW(X)}-\esp{Y_i|D_i=1} & = \esp{Y_i\frac{\Pr(D_i=1|X_i)}{1-\Pr(D_i=1|X_i)}\frac{1-\Pr(D_i=1)}{\Pr(D_i=1)}|D_i=0} \\
& = \frac{1}{\Pr(D_i=1)}\esp{Y^0_i(1-D_i)\frac{\Pr(D_i=1|X_i)}{1-\Pr(D_i=1|X_i)}} \\
& = \frac{1}{\Pr(D_i=1)}\esp{\esp{Y^0_i(1-D_i)\frac{\Pr(D_i=1|X_i)}{1-\Pr(D_i=1|X_i)}|X_i}}\\
& = \frac{1}{\Pr(D_i=1)}\esp{\esp{Y_i^0|X_i}(1-\Pr(D_i=1|X_i))\frac{\Pr(D_i=1|X_i)}{1-\Pr(D_i=1|X_i)}} \\
& = \frac{1}{\Pr(D_i=1)}\esp{\esp{Y_i^0|X_i}\Pr(D_i=1|X_i)}\\
& = \frac{1}{\Pr(D_i=1)}\esp{\esp{Y_i^0D_i|X_i}}\\
& =\frac{1}{\Pr(D_i=1)}\esp{Y_i^0D_i} \\
& =\frac{1}{\Pr(D_i=1)}\esp{Y_i^0|D_i=1}\Pr(D_i=1)\\
& = \esp{Y_i^0|D_i=1},
\end{align*}
where Assumption \@ref(hyp:comsupp) ensures that $\Delta^Y_{RW(X)}$ is well-defined, the third and seven equalities follow from the Law of Iterated Expectations, and the fourth and sixth equalities use Assumption \@ref(hyp:CIAExp).
```
Theorem \@ref(thm:socsid) shows that we can identify the effect of the treatment on the treated in the population under Conditional Independence (and Common Support) by adopting one of two approaches.
With the regression-based approach, untreated observations help us estimate the predicted value of the treated with the same values of the observed covariates $X_i$.
This is very similar to what we did with the $OLS(X)$ estimator above.
The only exception is that we do not use a parametric model to predict the counterfactual value of the outcome of the untreated.
With the reweighting approach, we use the propensity score $\Pr(D_i=1|X_i)$ to reweight all untreated observations so that the weighted expectation is equal to those that the treated would have had absent the treatment.
Reweighting puts more weight on the untreated observations that have a large probability of being treated: they resemble the treated a lot in terms of their observed covariates and thus inform us on what would have happened to the treated in the absence of the treatment.
### Estimation
How do we implement matching estimators in practice?
There are almost zillions of way to implement them.
What's nice is that mosst (all?) of them can be written as a reweighting estimator:
\begin{align*}
\hat{\Delta}^Y_{M} & = \frac{1}{N_1^S}\sum_{i\in\mathcal{I}^1\cap S}\left(Y_i-\sum_{j\in\mathcal{I}^0}w_{i,j}Y_j\right)
\end{align*}
with $\mathcal{I}^1$ is the set of treated individuals, $\mathcal{I}^0$ the set of untreated individuals, $S$ the set of individuals lying on the common support and $N_1^S$ the number of treated on the common support.
Each specific estimator differs on how it computes the weights $w_{i,j}$ and how it chooses the set of observations in the common support $S$.
Here are the methods we are going to detail in this section:
* Local Regression Matching (on the propensity score)
* Local Averaging Matching
* Nearest Neighbor Matching
* Reweighting Matching
* Doubly Robust Matching
#### Local Regression Matching (on the Propensity Score)
The idea of Local Regression Matching is very simple: run a separate regression for each treated observation using only untreated observations that are close enough to it.
Closeness is defined by a bandwidth, or a window around the treated observation of interest.
In order to be more efficient, more weight is given to untreated observations that lie closer to the treated observation.
Weights are given using a kernel function.
The key difficulty is what to do when the number of covariates is more than one (as it will very likely happen).
How do you define close observations then?
There are several possible approaches to that issue.
One is to use multivariate kernel functions (generally after standardizing covariates so that bandwidth choice is similar for all covariates).
Another approach more heavily used in practice is to summarize the influence of observed covariates on selection by using the propensity score.
A very nice result shows that conditioning on the propensity score is similar for estimating the $TT$ as conditioning on all the covariates.
The propensity score is also very useful to build the set of observations that lie on the common support.
Let's first study the Local Regression Matching and then add the propensity score to the mix.
##### Local Regression Matching
In practice, with LLR, $\sum_{j\in\mathcal{I}^0}w_{i,j}Y_j=\hatesp{Y_i|X_i,D_i=0}$ is equal to $\hat{\theta_0}$ estimated by weighted OLS in the following regression on the sample of untreated individuals
\begin{align*}
Y_j = \theta_0 + (X_i-X_j)\theta_1 + \epsilon_j,
\end{align*}
with weights $K\left(\frac{X_i-X_j}{h}\right)$, where $h$ is the bandwidth and $K$ is a kernel function.
Using some algebra, on can show, in the case of one-dimensional covariate $X_i$, that the weights of LLR are as follows ([Fan (1992)](https://www.jstor.org/stable/2290637) and [Smith and Todd (2005)](https://doi.org/10.1016/j.jeconom.2004.04.011)):
\begin{align*}
w_{i,j} & =\frac{K_{i,j}\sum^{}_{k\in \mathcal{I}_0}K_{i,k}(X_k-X_i)^2-[K_{i,j}(X_j-X_i)][\sum_{k\in \mathcal{I}_0}^{}K_{i,k}(X_k-X_i)]}{\sum_{j\in \mathcal{I}_0}^{}K_{i,j}\sum_{k\in \mathcal{I}_0}^{}K_{i,k}(X_k-X_i)^2-[\sum_{k\in \mathcal{I}_0}^{}K_{i,k}(X_k-X_i)]^2}
\end{align*}
with $K_{i,j}=K\left(\frac{X_i-X_j}{h}\right)$.
```{example}
Let us see how this works in our example.
```
Let us now run the LLR regression on the untreated sample, using as grid points all the observations in the treated sample, and let us then compute the estimated $TT$, with two candidates for the bandwidth:
```{r LLRMatchFirst, echo=TRUE,cache=TRUE}
kernel <- 'gaussian'
bw <- 1
# run LLR on the untreated sample using treated points as grid points
y0.llr.1 <- llr(y[Ds==0],yB[Ds==0],yB[Ds==1],bw=bw,kernel=kernel)
# compute TT
ww.llr.1 <- mean(y[Ds==1]-y0.llr.1)
bw <- 0.5
# run LLR on the untreated sample using treated points as grid points
y0.llr.0.5 <- llr(y[Ds==0],yB[Ds==0],yB[Ds==1],bw=bw,kernel=kernel)
# compute TT
ww.llr.0.5 <- mean(y[Ds==1]-y0.llr.0.5)
```
Let us now visualize how these estimates look like:
```{r PlotLLRStep2,eval=TRUE,echo=TRUE,fig.cap='LLR Matching estimates',fig.align='center',out.width='65%',fig.pos='htbp'}
plot(yB[Ds==0],y0[Ds==0],pch=1,xlim=c(5,11),ylim=c(5,11),xlab="yB",ylab="Outcomes")
points(yB[Ds==1],y0[Ds==1],pch=1,col='red')
points(yB[Ds==1],y0.llr.1,col='blue')
points(yB[Ds==1],y0.llr.0.5,col='green')
points(yB[Ds==1],y[Ds==1],pch=3)
legend(5,11,c('y0|D=0','y0|D=1',expression(hat(y0.1)),expression(hat(y0.0.5)),'y|D=1'),pch=c(1,1,1,1,3),col=c('black','red','blue','green','black'),ncol=2)
```
The LLR Matching estimate is equal to `r round(ww.llr.1,3)` with a bandwidth of $1$ and to `r round(ww.llr.0.5,3)` with a bandwidth of $0.5$, while the true value of the parameter in the population is equal to `r round(delta.y.tt.CS.pop,3)`.
Let us see how this estimator behaves over sample replications:
```{r monte.carlo.llr.match,eval=TRUE,echo=TRUE,warning=FALSE,error=FALSE,message=FALSE,results='hide',cache=TRUE}
# LLR matching fnciton
llr.match <- function(y,D,x,bw,kernel){
y0.llr <- llr(y[D==0],x[D==0],x[D==1],bw=bw,kernel=kernel)
return(mean(y[D==1]-y0.llr))
}
# Monte Carlos
monte.carlo.llr <- function(s,N,param,bw,kernel){
set.seed(s)
mu <- rnorm(N,param["barmu"],sqrt(param["sigma2mu"]))
UB <- rnorm(N,0,sqrt(param["sigma2U"]))
yB <- mu + UB
YB <- exp(yB)
Ds <- rep(0,N)
V <- rnorm(N,0,sqrt(param["sigma2mu"]+param["sigma2U"]))
Ds[yB+V<=log(param["barY"])] <- 1
epsilon <- rnorm(N,0,sqrt(param["sigma2epsilon"]))
eta<- rnorm(N,0,sqrt(param["sigma2eta"]))
U0 <- param["rho"]*UB + epsilon
y0 <- mu + U0 + param["delta"] + param["gamma"]*(yB-param["baryB"])^2
alpha <- param["baralpha"]+ param["theta"]*mu + eta
y1 <- y0+alpha
Y0 <- exp(y0)
Y1 <- exp(y1)
y <- y1*Ds+y0*(1-Ds)
Y <- Y1*Ds+Y0*(1-Ds)
ww.llr <- llr.match(y,Ds,yB,bw=bw,kernel=kernel)
return(ww.llr)
}
simuls.llr.N <- function(N,Nsim,param,bw,kernel){
simuls.llr <- matrix(unlist(lapply(1:Nsim,monte.carlo.llr,N=N,param=param,bw=bw,kernel=kernel)),nrow=Nsim,ncol=1,byrow=TRUE)
colnames(simuls.llr) <- c('LLR')
return(simuls.llr)
}
sf.simuls.llr.N <- function(N,Nsim,param,bw,kernel){
sfInit(parallel=TRUE,cpus=8)
sfExport('llr.match','llr')
sim.llr <- matrix(unlist(sfLapply(1:Nsim,monte.carlo.llr,N=N,param=param,bw=bw,kernel=kernel)),nrow=Nsim,ncol=1,byrow=TRUE)
sfStop()
colnames(sim.llr) <- c('LLR')
return(sim.llr)
}
Nsim <- 1000
#Nsim <- 10
#N.sample <- c(100,1000,10000,100000)
#N.sample <- c(100,1000,10000)
N.sample <- c(100,1000)
#simuls.llr <- lapply(N.sample,simuls.llr.N,Nsim=Nsim,param=param,bw=bw,kernel=kernel)
simuls.llr <- lapply(N.sample,sf.simuls.llr.N,Nsim=Nsim,param=param,bw=bw,kernel=kernel)
names(simuls.llr) <- N.sample
```
Let us now plot the resulting estimates:
```{r HistMCLLRMatch,eval=TRUE,echo=TRUE,warning=FALSE,error=FALSE,message=FALSE,results='hide',fig.cap='Distribution of the $LLR$ estimator over replications of samples of different sizes',fig.align='center',out.width='65%',fig.pos='htbp'}
par(mfrow=c(2,2))
for (i in 1:length(simuls.llr)){
hist(simuls.llr[[i]][,'LLR'],main=paste('N=',as.character(N.sample[i])),xlab=expression(hat(Delta^yLLR)),xlim=c(-0.15,0.55))
abline(v=delta.y.tt.com.supp(param),col="red")
}
```
```{remark}
On key limitation of the LLR Matching estimator that we have studies so far is the fact that it requires the use on only one covariate.
What to do when there is more than one covariate?
There are basically two solutions.
One is to use multidimensional kernels, which are simply products of unidimensionnal kernel functions.
In order to make things simpler, we generally standardize variables so that their dimensions are similar.
Another approach is to use the propensity score as a dimension reduction device.
```
##### Local Regression Matching on the Propensity Score
The propensity score, which we denote $P(X_i)$, is the probability that a unit is treated given its observed covariates: $P(X_i)=\Pr(D_i=1|X_i)$.
The key results that enables us to use the propensity score as dimension reduction device has been introduced by [Rosenbaum and Rubin (1983)]():
```{theorem,PScoreSuff,name='Sufficiency of Propensity Score'}
$(Y_i^1,Y_i^0)\Ind D_i|X_i \Rightarrow (Y_i^1,Y_i^0)\Ind D_i|P(X_i)$.
```
```{proof}
\begin{align*}
\Pr(D_i=1|Y_i^1,Y_i^0,P(X_i)) & = \esp{\Pr(D_i=1|Y_i^1,Y_i^0,X_i)|Y_i^1,Y_i^0,P(X_i)} \\
& = \esp{\Pr(D_i=1|X_i)|Y_i^1,Y_i^0,P(X_i)} \\
& = P(X_i) = \Pr(D_i=1|X_i),
\end{align*}
where the first equality uses the Law of Iterated Expectations and the second one uses $(Y_i^1,Y_i^0)\Ind D_i|X_i$.
```
In practice, in order to estimate LLR Matching using the propensity score, you can follow the following steps:
* Estimate a logit or probit regression: $D_i = \uns{\gamma_0 + \gamma_1'X_i + \zeta_i>0}$ (you might use series or splines to be more non-parametric here)
* Compute the predicted values (which are estimates of the propensity score): $\hat{P}(X_i)$ (you could also directly use multivariate non-parametric regression at this stage)
* Use $\hat{P}(X_i)$ as control variable in LLR Matching.
```{example}
Let's see how this works in our example.
```
First, we need to estimate the propensity score.
We are going to use a probit estimator, but things would be much similar with a logit.
The most important assumption is the linearity of the link function.
```{r prop.score,eval=TRUE,echo=TRUE}
probit.Ds <- glm(Ds~yB, family=binomial(link="probit"))
pscore <- predict(probit.Ds,type="response")
```
Let us now see how the propensity score looks like as a function of $y_i^B$:
```{r PlotPscore,eval=TRUE,echo=TRUE,fig.cap='Propensity score as a function of $y_i^B$',fig.align='center',out.width='65%',fig.pos='htbp'}
plot(yB,pscore, xlab="yB", ylab="Propensity score")
```
Let us now compute the LLR Matching estimator using the propensity score.
```{r LLRMatchingPscore,eval=TRUE,echo=TRUE}
bw <- 0.1
# run LLR on the untreated sample using treated points as grid points
y0.llr.pscore.0.1 <- llr(y[Ds==0],pscore[Ds==0],pscore[Ds==1],bw=bw,kernel=kernel)
# compute TT
ww.llr.pscore.0.1 <- llr.match(y,Ds,pscore,bw=bw,kernel=kernel)
```
Let's see how the LLR estimator using the propensity score works:
```{r PlotPscorePO,eval=TRUE,echo=TRUE,fig.cap='Propensity score and potential outcomes',fig.align='center',out.width='65%',fig.pos='htbp'}
plot(pscore[Ds==0],y[Ds==0], ylab="Outcomes", xlab="Propensity score",xlim=c(0,1),ylim=c(5,12))
points(pscore[Ds==1],y[Ds==1],pch=3,col='blue')
points(pscore[Ds==1],y0[Ds==1],pch=1,col='red')
points(pscore[Ds==1],y0.llr.pscore.0.1,col='green')
legend(0.7,11,c('y0|D=0','y1|D=1','y0|D=1',expression(hat(y0.0.1))),pch=c(1,3,1,1),col=c('black','blue','red','green'),ncol=1)
```
The estimated value of the $TT$ parameter using LLR Matching on the propensity score is equal to `r round(ww.llr.pscore.0.1,3)`.
Remember that the LLR Matching estimate using $y_i^B$ directly is equal to `r round(ww.llr.1,3)` with a bandwidth of $1$ and to `r round(ww.llr.0.5,3)` with a bandwidth of $0.5$, while the true value of the parameter in the population is equal to `r round(delta.y.tt.CS.pop,3)`.
```{remark}
We have not seen how to choose the bandwidth optimally.
A second thing we are missing is what to do when the density of the pscore is too low and the common support assumption almost does not hold.
```
##### Bandwidth choice
Choosing a bandwidth can be done using one of two approaches.
The smaller the bandwidth, the less biased the estimate is, but also the more noisy.
With a larger bandwidth, bias increases, but noise decreases.
This is the usual Bias/Variance trade-off in nonparametric estimation.
[Frolich (2005)](https://link.springer.com/article/10.1007/s11222-005-1309-6) derives formulae based on the asymptotic distribution of the LLR Matching estimator to help choose the optimal bandwidth.
The problem is that these formulae are complex and they are not very precise (the criteria is flat in the bandwidth).
In general, we thus prefer to use use Cross-Validation.
Cross validation estimates the MSE using leave-one out estimation and searches for the bandwidth having the lower MSE.
[Galdo, Smith and Black (2008)](https://www.jstor.org/stable/27917245) suggest to weighted the MSE search by importance of the treated.
```{example}
Let's see how this works in our example.
```
Let us first (re)define a function to compute the MSE and then compute is:
```{r llr.bw.cv,eval=TRUE,echo=FALSE,results='hide',cache=TRUE}
MSE.grid <- seq(0.1,1,by=.1)
MSE.grid.test <- sapply(MSE.grid,MSE.llr,y=y,D=Ds,x=pscore,kernel='gaussian',d=0)
MSE.grid.pscore <- seq(0.02,0.1,by=.02)
MSE.pscore <- sapply(MSE.grid.pscore,MSE.llr,y=y,D=Ds,x=pscore,kernel='gaussian',d=0)
bw <- MSE.grid.pscore[MSE.pscore==min(MSE.pscore)]
# run LLR on the untreated sample using treated points as grid points
y0.llr.pscore.bw <- llr(y[Ds==0],pscore[Ds==0],pscore[Ds==1],bw=bw,kernel=kernel)
# TT estimate
ww.llr.pscore.bw <- llr.match(y,Ds,pscore,bw=bw,kernel=kernel)