/
Replicate_Appendix.Rmd
2989 lines (2342 loc) · 142 KB
/
Replicate_Appendix.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: "Replication Output for: Can the Government Deter Discrimination? Evidence from a Randomized Intervention in New York City"
author: "Albert H. Fang, Andrew M. Guess, and Macartan Humphreys"
date: "December 2, 2017"
output:
html_document:
toc: true
number_sections: yes
theme: cosmo
---
# Appendix Tables and Figures
## Table A1 (p. A-2): Distribution of Experimental Subjects by Randomization Block
```{r tablea1, echo=T, warning=F}
blockLabs <- rep(c("Brooklyn","Bronx","Manhattan","Queens","Staten Island","Likely Discrimination Frame"), 3)
blockLabs <- blockLabs[-length(blockLabs)]
pcts <- round(prop.table(table(dat$block, dat$TA, useNA="ifany")), 3)
block_dist <- cbind(blockLabs,
table(dat$block, dat$TA, useNA="ifany")[,1], pcts[,1],
table(dat$block, dat$TA, useNA="ifany")[,2], pcts[,2],
table(dat$block, dat$TA, useNA="ifany")[,3], pcts[,3])
block_dist <- rbind(c("Regime 1: 13 Apr 2012 - 9 Sep 2012", rep(NA,6)),
block_dist[1:6,],
c("Regime 2: 10 Sep 2012 - 7 May 7, 2013", rep(NA,6)),
block_dist[7:12,],
c("Regime 3: 8 May 2013 to 20 Dec 2013", rep(NA,6)),
block_dist[13:17,],
c("Total", table(dat$TA)[1], round(table(dat$TA)[1]/sum(table(dat$TA)),3),
table(dat$TA)[2], round(table(dat$TA)[2]/sum(table(dat$TA)),3),
table(dat$TA)[3], round(table(dat$TA)[3]/sum(table(dat$TA)),3)
))
colnames(block_dist) <- c("Block","Control (N)","Control (Proportion)",
"Monitoring (N)","Monitoring (Proportion)",
"Punitive (N)","Punitive (Proportion)")
block_distcaption = "Distribution of Experimental Subjects by Randomization Block. Cells contain counts of the number and proportion of experimental subjects randomly assigned to each arm by randomization block. The 17 randomization blocks are defined by the ad's sampling stratum (New York City borough or the likely discrimination, or LD, oversample) and by treatment regime (defined as a distinct design and randomization procedure). There are three treatment regimes. Regime 1 was a 5-arm design (2 of which are not analyzed in this paper) with equal treatment assignment probabilities. Regime 2 was a 3-arm design where the probability of assignment to control was 0.5 and the probability of assignment to the monitoring or punitive conditions was 0.25. Regime 3 was a 3-arm design with equal treatment assignment probabilities. Proportions may not sum to 1 due to rounding."
# show table in Rmd output file
rownames(block_dist) <- NULL
kable(block_dist, caption="**Table A1**")
```
```{r, include=FALSE}
# export table to tex file
print(xtable(block_dist, caption = block_distcaption, label= "blockNs"), file="out_table_a1_dist_by_block.tex", hline.after=c(0,7,14,20,21), include.rownames=FALSE, only.contents=TRUE)
```
## Table A2 (p. A-3): Incidence of Early Stage Discrimination
```{r prep_tablea2, include=FALSE, warning=F}
# create table shells
wb <- matrix(NA, nrow=length(es.a), ncol=16)
wh <- matrix(NA, nrow=length(es.a), ncol=16)
bh <- matrix(NA, nrow=length(es.a), ncol=16)
# populate column headings
colnames(wb) <- c("Measure", paste( c(rep("AuditSamp-",5),rep("ExpSamp-",5),rep("Control-",5)) , rep(c("Maj-Mean","Min-Mean","Diff","P","N"),3), sep=""))
colnames(wh) <- c("Measure", paste( c(rep("AuditSamp-",5),rep("ExpSamp-",5),rep("Control-",5)) , rep(c("Maj-Mean","Min-Mean","Diff","P","N"),3), sep=""))
colnames(bh) <- c("Measure", paste( c(rep("AuditSamp-",5),rep("ExpSamp-",5),rep("Control-",5)) , rep(c("Maj-Mean","Min-Mean","Diff","P","N"),3), sep=""))
# populate first column - variable names
wb[,1] <- c(es.wb.labs)
wh[,1] <- c(es.wh.labs)
bh[,1] <- c(es.bh.labs)
# check variables
# for(i in 1:length(es.a)){
# cat("\n *********** variable : ", es.a.labs[i], "****************\n", sep="")
# print(table(aud[[es.a[i]]], useNA="ifany"))
# cat("\n *********** variable : ", es.b.labs[i], "****************\n", sep="")
# print(table(aud[[es.b[i]]], useNA="ifany"))
# cat("\n *********** variable : ", es.c.labs[i], "****************\n", sep="")
# print(table(aud[[es.c[i]]], useNA="ifany"))
# }
# convert all vars into numeric
cols <- c(es.a, es.b, es.c, es.wb, es.wh, es.bh)
aud[,cols] <- lapply(aud[,cols], as.numeric)
# populate table shells
```
```{r tablea2, include= TRUE, warning=F}
# A: BLACK , B: HISPANIC , C: WHITE
es <- c("contact", "sched", "numattr", "numskep", "numpos", "numneu",
"numneg", "pctskep", "pctpos", "pctneu", "pctneg", "anyskep", "anyneg")
summm <- function(x, group1 = "C", group2 = "A") {
es1 <- paste0(x, "_", group1); es2 <- paste0(x, "_", group2)
# audit sample
aud_maj_mean <- mean(aud[[es1]])
aud_min_mean <- mean(aud[[es2]])
aud_diff <- as.numeric(aud_maj_mean) - as.numeric(aud_min_mean)
aud_P <- t.test(x=aud[[es1]], y=aud[[es2]], alternative="two.sided",
paired=TRUE, conf.level=0.95)$p.value
aud_N <- length(aud[[es1]])
# experimental sample
exp_maj_mean <- mean(aud[[es1]][aud$insamp=="1" & !is.na(aud$insamp) ])
exp_min_mean <- mean(aud[[es2]][aud$insamp=="1" & !is.na(aud$insamp) ])
exp_diff <- exp_maj_mean - exp_min_mean
exp_P <- t.test(x=aud[[es1 ]][aud$insamp=="1" & !is.na(aud$insamp) ],
y=aud[[es2 ]][aud$insamp=="1" & !is.na(aud$insamp) ], alternative="two.sided", paired=TRUE, conf.level=0.95)$p.value
exp_N <- length(aud[[es1]][aud$insamp=="1" & !is.na(aud$insamp) ])
# control group
ctrl_maj_mean <- mean(aud[[es1]][aud$insamp=="1" & !is.na(aud$insamp) & aud$TA==0])
ctrl_min_mean <- mean(aud[[es2]][aud$insamp=="1" & !is.na(aud$insamp) & aud$TA==0])
ctrl_diff <- ctrl_maj_mean - ctrl_min_mean
ctrl_P <- t.test(x=aud[[es1 ]][aud$insamp=="1" & !is.na(aud$insamp) & aud$TA==0],
y=aud[[es2 ]][aud$insamp=="1" & !is.na(aud$insamp) & aud$TA==0], alternative="two.sided", paired=TRUE, conf.level=0.95)$p.value
ctrl_N <- length(aud[[es1]][aud$insamp=="1" & !is.na(aud$insamp) & aud$TA==0])
# return
c(aud_maj_mean = aud_maj_mean, aud_min_mean = aud_min_mean,
aud_diff = aud_diff, aud_P = aud_P, aud_N = aud_N,
exp_maj_mean = exp_maj_mean, exp_min_mean = exp_min_mean,
exp_diff = exp_diff, exp_P = exp_P, exp_N = exp_N,
ctrl_maj_mean = ctrl_maj_mean, ctrl_min_mean = ctrl_min_mean,
ctrl_diff = ctrl_diff, ctrl_P = ctrl_P, ctrl_N = ctrl_N)
}
wb <- cbind(es.wb.labs, t(sapply(es, summm, group1 = "C", group2 = "A")))
wh <- cbind(es.wh.labs, t(sapply(es, summm, group1 = "C", group2 = "B")))
bh <- cbind(es.bh.labs, t(sapply(es, summm, group1 = "A", group2 = "B")))
```
```{r tablea2_format, include= FALSE, warning=F}
for(i in 2:ncol(wb)){
wb[,i] <- round(as.numeric(wb[,i]), 3)
wh[,i] <- round(as.numeric(wh[,i]), 3)
bh[,i] <- round(as.numeric(bh[,i]), 3)
if(i %in% c(5,10,15)) {
wb[,i] <- paste("(",wb[,i],")",sep="")
wh[,i] <- paste("(",wh[,i],")",sep="")
bh[,i] <- paste("(",bh[,i],")",sep="")
}
if(i %in% c(6,11,16)) {
wb[,i] <- paste("[",wb[,i],"]",sep="")
wh[,i] <- paste("[",wh[,i],"]",sep="")
bh[,i] <- paste("[",bh[,i],"]",sep="")
}
}
```
```{r tablea2_print, include= TRUE, warning=F}
es_discrim_full_table <- rbind(wb, wh, bh)
table_a2 <- es_discrim_full_table[c(1,2,14,15,27,28),1:6]
kable(table_a2, caption="**Table A2**",
col.names = c("Measure", "Majority Group Mean", "Minority Group Mean",
"Difference (Maj-Min)", "p-value", "[N]"),
row.names = FALSE)
```
```{r tablea2_TEX, include= FALSE, warning=F}
print(xtable(table_a2, caption = c("Incidence of Early Stage Discrimination",
"Incidence of Early Stage Discrimination")),
file = "out_tablea2_early_stage_discrim.tex",
include.rownames = FALSE)
```
```{r tablea2_FTEST, include= TRUE, warning=F}
#### F-test for the null hypothesis that race does not matter for making any contact or for scheduling appointment
# A: BLACK , B: HISPANIC , C: WHITE
aud.rs <- melt(aud[,c("cid", "contact_A", "contact_B", "contact_C", "sched_A", "sched_B", "sched_C")], id.vars="cid")
aud.rs$ttype <- sapply(strsplit(as.character(aud.rs$variable), "_", fixed=TRUE), function(x) x[2])
aud.rs$variable <- sapply(strsplit(as.character(aud.rs$variable), "_", fixed=TRUE), function(x) x[1])
aud.rs <- dcast(aud.rs, cid + ttype ~ variable, value.var="value")
fit.contact <- lm(contact ~ ttype, data = aud.rs)
fit.sched <- lm(sched ~ ttype, data = aud.rs)
print("F-test of the null that tester race predicts whether the tester makes any contact with the landlord")
print(summary(fit.contact))
print("F-test of the null that tester race predicts whether the tester successfully schedules an appointment")
print(summary(fit.sched))
```
## Figure A2 (p. A-5): Cumulative Number of Cases Over Implementation Period
```{r figurea2png, echo=T, warning=F}
dat$casedate <- as.Date(dat$casedate, format="%Y-%m-%d")
casedate <- dat$casedate[order(dat$casedate)]
# generate .png
png("out_figurea2_cases_over_time.png", height=500, width=1200)
par(oma=c(2,0,3,0), xpd=TRUE)
plot(casedate, 1:length(casedate), xaxt="n", yaxt="n", type="l", ylim=c(0,700), xlab="", ylab="Cumulative Number of Cases", xaxs="i", yaxs="i")
axis.Date(side=1, at=seq(as.Date("2012-04-01"), as.Date("2014-01-01"), "month"), format="%m/%Y", las=2, cex.axis=0.9)
axis(side=2, at=seq(0,700,100), labels=seq(0,700,100), cex.axis=0.9, las=1)
polygon(x=c(rep(as.Date("2012-10-29"),2), rep(as.Date("2012-11-11"),2)),
y=c(700,0,0,700),
col=rgb(.8,.8,.8,.25),
border=rgb(.8,.8,.8,.25))
text(x=as.Date("2012-11-11"), y=600, "Implementation Halted \nDue to Hurricane Sandy", cex=.9, pos=1)
mtext(side=1, "Date", outer=TRUE)
segments(x0=as.Date("2012-09-09"), y0=700, x1=as.Date("2012-09-09"), y1=0, lty=5, col="grey80")
segments(x0=as.Date("2013-05-07"), y0=700, x1=as.Date("2013-05-07"), y1=0, lty=5, col="grey80")
text(x=as.Date("2012-07-01"), y=840, "Regime 1: 5-Arm Design \nApril 13, 2012 to September 9, 2012 \nEqual Assignment Probabilities", cex=.9, pos=1)
text(x=as.Date("2013-01-15"), y=840, "Regime 2: 3-Arm Design \nSeptember 10, 2012 to May 7, 2013 \nPr(Control)=.5, Pr(Monitoring)=Pr(Punitive)=.25", cex=.9, pos=1)
text(x=as.Date("2013-09-01"), y=840, "Regime 3: 3-Arm Design \nMay 8, 2013 to December 20, 2013 \nEqual Assignment Probabilities", cex=.9, pos=1)
invisble(dev.off())
```
```{r figurea2pdf, echo=F, warning=F, include = FALSE}
pdf("out_figurea2_cases_over_time.pdf", height=5, width=12)
par(oma=c(2,0,0,0), xpd=TRUE)
plot(casedate, 1:length(casedate), xaxt="n", yaxt="n", type="l", ylim=c(0,700), xlab="", ylab="Cumulative Number of Cases", xaxs="i", yaxs="i")
axis.Date(side=1, at=seq(as.Date("2012-04-01"), as.Date("2014-01-01"), "month"), format="%m/%Y", las=2, cex.axis=0.9)
axis(side=2, at=seq(0,700,100), labels=seq(0,700,100), cex.axis=0.9, las=1)
polygon(x=c(rep(as.Date("2012-10-29"),2), rep(as.Date("2012-11-11"),2)),
y=c(700,0,0,700),
col=rgb(.8,.8,.8,.25),
border=rgb(.8,.8,.8,.25))
text(x=as.Date("2012-11-11"), y=600, "Implementation Halted \nDue to Hurricane Sandy", cex=.9, pos=1)
mtext(side=1, "Date", outer=TRUE)
segments(x0=as.Date("2012-09-09"), y0=700, x1=as.Date("2012-09-09"), y1=0, lty=5, col="grey80")
segments(x0=as.Date("2013-05-07"), y0=700, x1=as.Date("2013-05-07"), y1=0, lty=5, col="grey80")
text(x=as.Date("2012-07-01"), y=840, "Regime 1: 5-Arm Design \nApril 13, 2012 to September 9, 2012 \nEqual Assignment Probabilities", cex=.9, pos=1)
text(x=as.Date("2013-01-15"), y=840, "Regime 2: 3-Arm Design \nSeptember 10, 2012 to May 7, 2013 \nPr(Control)=.5, Pr(Monitoring)=Pr(Punitive)=.25", cex=.9, pos=1)
text(x=as.Date("2013-09-01"), y=840, "Regime 3: 3-Arm Design \nMay 8, 2013 to December 20, 2013 \nEqual Assignment Probabilities", cex=.9, pos=1)
invisble(dev.off())
```
![**Figure A2**](out_figurea2_cases_over_time.png)
## Figure A3 (p. A-6): Discrimination Levels and Treatment Effects using the Subjective Discrimination Index
**Note:** Analysis and figure construction code for Figure A3 is shown above in _"1.1 Figure 1: Main Results on Discrimination Levels and Treatment Effects"_
![**Figure A3: Net Discrimination in Subjective Discrimination Index**](out_figurea3_6x6_index.png)
## Figure A4 (p. A-17): Estimates of Tester Random Effects on Outcome Measures
```{r figurea4code, echo=T, eval=T, warning=F}
ctx$weekday <- as.factor(weekdays(as.Date(ctx$sfa_B4_apptdate, format="%m/%d/%y")))
anova_fig <- data.frame(outcome = c("cb","off","qualpraise","sales","posedit","posbg","prof"),
ylab = c("Callbacks", "Offers", "Praise", "Perceived Sales Efforts",
"Positive Editorializing", "Positive Reactions", "Professionalism"),
title = c("Tester Random Effects on Callback Incidence",
"Tester Random Effects on Offer Incidence",
"Tester Random Effects on Praise re: Qualifications to Rent",
"Tester Random Effects on Sales Efforts",
"Tester Random Effects on Positive Editorializing",
"Tester Random Effects on Positive Reactions to Background",
"Tester Random Effects on Professionalism"))
# MAKE GRAPHS
for(ii in 1:nrow(anova_fig)){
model <- lmer(paste0(anova_fig$outcome[ii],
" ~ (1|tid) + (1|ttype) + callorder + weekday + partnered
+ numbr + anyskep + anyneg + (1|team_gender)"), data=ctx)
model_off <- lmer(paste0(anova_fig$outcome[2],
" ~ (1|tid) + (1|ttype) + callorder + weekday + partnered
+ numbr + anyskep + anyneg + (1|team_gender)"), data=ctx)
ifelse(ii>=2, se <- se.ranef(model_off)[[1]][i,1], se <- se.ranef(model)[[1]][i,1])
i <- 1:(length(ranef(model)[[1]][,1]))
y <- ranef(model)[[1]][,1] # individual tester RE
types <- c(rep(0,14), rep(1,19), rep(2,15))
col <- rainbow(3)[types+1]
# output PNG file for Rmd output
png(paste0("out_figurea4",letters[ii],"_anova_",anova_fig$outcome[ii],".png"), width=800)
par(0,0,0,0)
plot(i, y, col = col, ylim=c(-1.0,1),xlim=c(1,50),xlab="Testers", ylab=anova_fig$ylab[ii],main=anova_fig$title[ii],pch=20,bty="n")
legend("bottom", c("Black","Hispanic","White"), pch=20, col=rainbow(3),horiz=T,bty="n")
segments(i, y + 2*se, i, y - 2*se, col = col)
abline(a=0,b=0,lty=2)
invisble(dev.off())
}
```
```{r figure4_tex, include=FALSE}
# output PDF file for tex
pdf(paste0("out_figurea4",letters[ii],"_anova_",anova_fig$outcome[ii],".pdf"), width=8)
plot(i, y, col = col, ylim=c(-1.0,1),xlim=c(1,50),xlab="Testers", ylab=anova_fig$ylab[ii],main=anova_fig$title[ii],pch=20,bty="n")
legend("bottom", c("Black","Hispanic","White"), pch=20, col=rainbow(3),horiz=T,bty="n")
segments(i, y + 2*se, i, y - 2*se, col = col)
abline(a=0,b=0,lty=2)
invisble(dev.off())
```
![**Figure A4, panel a: Post-Visit Callback**](out_figurea4a_anova_cb.png){width=60%}
![**Figure A4, panel b: Post-Visit Offer**](out_figurea4b_anova_off.png){width=60%}
![**Figure A4, panel c: Positive Biographical Feedback**](out_figurea4f_anova_posbg.png){width=60%}
![**Figure A4, panel d: Positive Editorializing**](out_figurea4e_anova_posedit.png){width=60%}
![**Figure A4, panel e: Praised Rental Qualifications**](out_figurea4c_anova_qualpraise.png){width=60%}
![**Figure A4, panel f: Sales Efforts**](out_figurea4d_anova_sales.png){width=60%}
![**Figure A4, panel g: Professionalism**](out_figurea4g_anova_prof.png){width=60%}
```{r randfxmodels, echo=T, eval=T, warning=F}
### The following analysis corresponds to the analyses described in footnote 22 in the article.
ctx$weekday <- as.factor(weekdays(as.Date(ctx$sfa_B4_apptdate, format="%m/%d/%y")))
dat_tid <- dat[,c("cid","TA",names(dat)[grepl("tid",names(dat))])]
dat_tid <- cbind(dat_tid[,c("cid","TA")], t(apply(dat_tid[,3:ncol(dat_tid)], 1, function(J) names(dat_tid[,3:ncol(dat_tid)])[which(J==1)])))
dat_tid_1 <- as.data.frame(dat_tid[,c(1,2,3)], stringsAsFactors=FALSE)
dat_tid_2 <- as.data.frame(dat_tid[,c(1,2,4)], stringsAsFactors=FALSE)
dat_tid_3 <- as.data.frame(dat_tid[,c(1,2,5)], stringsAsFactors=FALSE)
dat_tid_1[,3] <- as.character(dat_tid_1[,3])
dat_tid_2[,3] <- as.character(dat_tid_2[,3])
dat_tid_3[,3] <- as.character(dat_tid_3[,3])
names(dat_tid_1)[3] <- names(dat_tid_2)[3] <- names(dat_tid_3)[3] <- "tid"
dat_tid <- rbind(dat_tid_1, dat_tid_2, dat_tid_3)
dat_tid$tid <- gsub("tid.","",dat_tid$tid,fixed=TRUE)
dat_tid$ttype <- substr(dat_tid$tid, 1, 1)
dat_sub <- dat[,c("cid","TA","team_gender","callorder","partnered","numbr",
paste0(rep(c("anyskep","anyneg","cb","off","prof","posedit","posbg","qualpraise","sales"), 3),
rep(c("_A","_B","_C"), each=9))
)]
dmelt <- melt(dat_sub, id.vars=c("cid", "TA", "team_gender", "callorder", "partnered", "numbr"))
dmelt$ttype <- ifelse(grepl("_A", dmelt$variable, fixed=TRUE), "A",
ifelse(grepl("_B", dmelt$variable, fixed=TRUE), "B", "C"))
dmelt$variable <- gsub("_A", "", dmelt$variable, fixed=TRUE)
dmelt$variable <- gsub("_B", "", dmelt$variable, fixed=TRUE)
dmelt$variable <- gsub("_C", "", dmelt$variable, fixed=TRUE)
dat_sub2 <- dcast(dmelt, cid + TA + team_gender + callorder + partnered + numbr + ttype ~ variable, value.var="value")
dat2 <- join(dat_tid, dat_sub2, by=c("cid","TA","ttype"), type="left", match="all")
ctx_sub <- ctx[,c("cid","weekday")]
ctx_sub <- ctx_sub[!duplicated(ctx_sub$cid),]
#ctx[ctx$cid %in% ctx_sub$cid[is.na(ctx_sub$weekday)] & !is.na(ctx$weekday),c("cid","weekday")]
ctx_sub$weekday <- ifelse(ctx_sub$cid == 11108, "Wednesday", ctx_sub$weekday)
ctx_sub$weekday <- ifelse(ctx_sub$cid == 12116, "Friday", ctx_sub$weekday)
ctx_sub$weekday <- ifelse(ctx_sub$cid == 12608, "Monday", ctx_sub$weekday)
ctx_sub$weekday <- ifelse(ctx_sub$cid == 13361, "Monday", ctx_sub$weekday)
ctx_sub$weekday <- ifelse(ctx_sub$cid == 15734, "Friday", ctx_sub$weekday)
ctx_sub$weekday <- ifelse(ctx_sub$cid == 19446, "Thursday", ctx_sub$weekday)
ctx_sub$weekday <- ifelse(ctx_sub$cid == 26324, "Friday", ctx_sub$weekday)
ctx_sub$weekday <- ifelse(ctx_sub$cid == 30165, "Friday", ctx_sub$weekday)
ctx_sub$weekday <- ifelse(is.na(ctx_sub$weekday), "None", ctx_sub$weekday)
dat3 <- join(dat2, ctx_sub, by="cid", type="left", match="all")
model.callback.0 <- lmer(cb ~ (1|tid) + (1|ttype) + callorder + weekday +
partnered + numbr + anyskep + anyneg + (1|team_gender),
data=dat3, subset=(TA==0))
model.offer.0 <- lmer(off ~ (1|tid) + (1|ttype) + callorder + weekday +
partnered + numbr + anyskep + anyneg + (1|team_gender),
data=dat3, subset=(TA==0))
model.callback.all <- lmer(cb ~ (1|tid) + (1|ttype) + callorder + weekday +
partnered + numbr + anyskep + anyneg + (1|team_gender),
data=dat3)
model.offer.all <- lmer(off ~ (1|tid) + (1|ttype) + callorder + weekday +
partnered + numbr + anyskep + anyneg + (1|team_gender),
data=dat3)
re_out <- list(model.callback.0 ,
model.offer.0 ,
model.callback.all ,
model.offer.all )
re_table <- lapply(re_out, function(J){
x <- as.data.frame(VarCorr(J))
x[,4] <- round(x[,4], 4)
x <- x[,c(1,4)]
return(x)
})
re_table <- do.call(cbind, re_table)
re_table <- re_table[,-c(3,5,7)]
re_table[,1] <- c("Estimated Variance of Varying Tester Intercepts",
"Estimated Variance of Varying Tester Race Intercepts",
"Estimated Variance of Varying Tester Team Gender Intercepts",
"Estimated Residual Variance")
colnames(re_table) <- c("", "Control Group, Outcome: Callback", "Control Group, Outcome: Offer",
"Experimental Sample, Outcome: Callback", "Experimental Sample, Outcome: Offer")
kable(re_table)
```
## Table A4 (p. A-20): Selected Characteristics of Housing Units in the Audit and Experimental Samples
We summarize selected _pre-treatment_ characteristics of housing units in the audit and experimental samples. To ensure the measures are _pre-treatment_ quantities, we summarize characteristics of housing units that are posted on and scraped from the original Craigslist ads.
```{r tablea4, echo=T, eval=T, warning=F}
# Helper functions and code to calculate descriptive statistics
stratum_labels <- c("Total", "Brooklyn", "Bronx", "Manhattan", "Queens", "Staten Island", "Likely Discrimination Frame")
# descriptive_f: A function to compute descriptive statistics e.g. mean, sd, min, max..
calc_descriptives <- function(descriptive_f, df, x, label, digs = 2) {
x <- c(descriptive_f(df[[x]], na.rm=TRUE),
descriptive_f(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "brk" ], na.rm=TRUE),
descriptive_f(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "brx" ], na.rm=TRUE),
descriptive_f(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "mnh" ], na.rm=TRUE),
descriptive_f(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "que" ], na.rm=TRUE),
descriptive_f(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "stn" ], na.rm=TRUE),
descriptive_f(df[[x]][ df[["frame"]] != "representative" ], na.rm=TRUE))
out <- round(x, digs)
if(identical(descriptive_f, sd)) out <- paste0("(", out, ")")
out
}
calc_pct_ses <- function(df, x, label, digs=NULL) {
x_prop <- c(mean(df[[x]], na.rm=TRUE),
mean(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "brk" ], na.rm=TRUE),
mean(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "brx" ], na.rm=TRUE),
mean(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "mnh" ], na.rm=TRUE),
mean(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "que" ], na.rm=TRUE),
mean(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "stn" ], na.rm=TRUE),
mean(df[[x]][ df[["frame"]] != "representative" ], na.rm=TRUE))
x_sd <- c(sd(df[[x]], na.rm=TRUE),
sd(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "brk" ], na.rm=TRUE),
sd(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "brx" ], na.rm=TRUE),
sd(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "mnh" ], na.rm=TRUE),
sd(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "que" ], na.rm=TRUE),
sd(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "stn" ], na.rm=TRUE),
sd(df[[x]][ df[["frame"]] != "representative" ], na.rm=TRUE))
x_n <- c(sum(!is.na(df[[x]])),
sum(!is.na(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "brk" ])),
sum(!is.na(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "brx" ])),
sum(!is.na(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "mnh" ])),
sum(!is.na(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "que" ])),
sum(!is.na(df[[x]][ df[["frame"]] == "representative" & df[["boro"]] == "stn" ])),
sum(!is.na(df[[x]][ df[["frame"]] != "representative" ]))
)
x_se <- x_sd / sqrt(x_n)
if(is.null(digs)) digs <- 2
x_pct <- sprintf( paste0("%.",digs,"f") , round(x_prop * 100, digs) )
x_se <- paste0("(", sprintf( paste0("%.",digs,"f") , round(x_se * 100, digs) ) ,")")
x <- cbind(x_pct, x_se)
colnames(x) <- paste0(label, c("_p", "_se"))
rownames(x) <- NULL
return(x)
}
#----------------------------------------#
# Panel A: Number of units
panel_a_aud_n <- c(nrow(aud),
table(aud$boro[aud$frame == "representative"]),
nrow(aud[aud$frame != "representative",]))
panel_a_aud_p <- paste0("(", sprintf("%.2f", round(panel_a_aud_n / nrow(aud) * 100, 2)) ,")")
panel_a_exp_n <- c(nrow(dat),
table(dat$boro[dat$frame == "representative"]),
nrow(dat[dat$frame != "representative",]))
panel_a_exp_p <- paste0("(", sprintf("%.2f", round(panel_a_exp_n / nrow(dat) * 100, 2)) ,")")
panel_a_trt_n <- c(nrow(dat[dat$TA != 0,]),
table(dat$boro[dat$frame == "representative" & dat$TA != 0]),
nrow(dat[dat$frame != "representative" & dat$TA != 0,]))
panel_a_trt_p <- paste0("(", sprintf("%.2f", round(panel_a_trt_n / nrow(dat[dat$TA != 0,]) * 100, 2)) ,")")
panel_a_con_n <- c(nrow(dat[dat$TA == 0,]),
table(dat$boro[dat$frame == "representative" & dat$TA == 0]),
nrow(dat[dat$frame != "representative" & dat$TA == 0,]))
panel_a_con_p <- paste0("(", sprintf("%.2f", round(panel_a_con_n / nrow(dat[dat$TA == 0,]) * 100, 2)) ,")")
tab_a4_panel_a <- cbind(stratum_labels,
panel_a_aud_n,
panel_a_aud_p,
panel_a_exp_n,
panel_a_exp_p,
panel_a_trt_n,
panel_a_trt_p,
panel_a_con_n,
panel_a_con_p)
rownames(tab_a4_panel_a) <- NULL
colnames(tab_a4_panel_a) <- gsub("panel_a_", "", colnames(tab_a4_panel_a), fixed=TRUE)
kable(tab_a4_panel_a, col.names=c("Stratum", "Audit Sample (N)", "Audit Sample (%)",
"Exp Sample (N)", "Exp Sample (%)",
"Any Treatment (N)", "Any Treatment (%)",
"Control (N)", "Control (%)"),
caption="**Table A4, Panel A. Number of Units (Scraped from Craigslist).**")
#----------------------------------------#
# Panel B: Monthly asking price (mean)
tab_a4_panel_b <- cbind(stratum_labels,
calc_descriptives(mean, df = aud, x = "rent", label = "aud"),
calc_descriptives(sd, df = aud, x = "rent", label = "aud"),
calc_descriptives(mean, df = dat, x = "rent", label = "exp"),
calc_descriptives(sd, df = dat, x = "rent", label = "exp"),
calc_descriptives(mean, df = dat[dat$TA != 0,], x = "rent", label = "trt"),
calc_descriptives(sd, df = dat[dat$TA != 0,], x = "rent", label = "trt"),
calc_descriptives(mean, df = dat[dat$TA == 0,], x = "rent", label = "con"),
calc_descriptives(sd, df = dat[dat$TA == 0,], x = "rent", label = "con"))
kable(tab_a4_panel_b, col.names=c("Stratum", "Audit Sample (Mean)", "Audit Sample (SD)",
"Exp Sample (Mean)", "Exp Sample (SD)",
"Any Treatment (Mean)", "Any Treatment (SD)",
"Control (Mean)", "Control (SD)"),
caption="**Table A4, Panel B. Monthly Asking Rental Price ($, Scraped from Craigslist).**")
#----------------------------------------#
# Panel C: Monthly asking price (median)
tab_a4_panel_c <- cbind(stratum_labels,
calc_descriptives(median, df = aud, x = "rent", label = "aud"),
"",
calc_descriptives(median, df = dat, x = "rent", label = "exp"),
"",
calc_descriptives(median, df = dat[dat$TA != 0,], x = "rent", label = "trt"),
"",
calc_descriptives(median, df = dat[dat$TA == 0,], x = "rent", label = "con"),
"")
kable(tab_a4_panel_c, col.names=c("Stratum", "Audit Sample (Median)", "",
"Exp Sample (Median)", "",
"Any Treatment (Median)", "",
"Control (Median)", ""),
caption="**Table A4, Panel C. Median Monthly Asking Rental Price ($, Scraped from Craigslist).**")
#----------------------------------------#
# Panel D: Number of bedrooms
tab_a4_panel_d <- cbind(stratum_labels,
calc_descriptives(mean, df = aud, x = "numbr", label = "aud"),
calc_descriptives(sd, df = aud, x = "numbr", label = "aud"),
calc_descriptives(mean, df = dat, x = "numbr", label = "exp"),
calc_descriptives(sd, df = dat, x = "numbr", label = "exp"),
calc_descriptives(mean, df = dat[dat$TA != 0,], x = "numbr", label = "trt"),
calc_descriptives(sd, df = dat[dat$TA != 0,], x = "numbr", label = "trt"),
calc_descriptives(mean, df = dat[dat$TA == 0,], x = "numbr", label = "con"),
calc_descriptives(sd, df = dat[dat$TA == 0,], x = "numbr", label = "con"))
kable(tab_a4_panel_d, col.names=c("Stratum", "Audit Sample (Mean)", "Audit Sample (SD)",
"Exp Sample (Mean)", "Exp Sample (SD)",
"Any Treatment (Mean)", "Any Treatment (SD)",
"Control (Mean)", "Control (SD)"),
caption="**Table A4, Panel D. Number of Bedrooms (Scraped from Craigslist).**")
#----------------------------------------#
# Panel E: Square footage
tab_a4_panel_e <- cbind(stratum_labels,
calc_descriptives(mean, df = aud, x = "sqft", label = "aud"),
calc_descriptives(sd, df = aud, x = "sqft", label = "aud"),
calc_descriptives(mean, df = dat, x = "sqft", label = "exp"),
calc_descriptives(sd, df = dat, x = "sqft", label = "exp"),
calc_descriptives(mean, df = dat[dat$TA != 0,], x = "sqft", label = "trt"),
calc_descriptives(sd, df = dat[dat$TA != 0,], x = "sqft", label = "trt"),
calc_descriptives(mean, df = dat[dat$TA == 0,], x = "sqft", label = "con"),
calc_descriptives(sd, df = dat[dat$TA == 0,], x = "sqft", label = "con"))
kable(tab_a4_panel_e, col.names=c("Stratum", "Audit Sample (Mean)", "Audit Sample (SD)",
"Exp Sample (Mean)", "Exp Sample (SD)",
"Any Treatment (Mean)", "Any Treatment (SD)",
"Control (Mean)", "Control (SD)"),
caption="**Table A4, Panel E. Square Footage (Scraped from Craigslist).** Standard invisble(dev.off())iation is noted as NA when only one observation in a given stratum has non-missing square footage data. Square footage information is rarely posted on Craigslist rental ads in New York City.")
#----------------------------------------#
# Panel F: Listed by broker
tab_a4_panel_f <- cbind(stratum_labels,
calc_pct_ses(df = aud, x = "broker", label = "aud"),
calc_pct_ses(df = dat, x = "broker", label = "exp"),
calc_pct_ses(df = dat[dat$TA != 0,], x = "broker", label = "trt"),
calc_pct_ses(df = dat[dat$TA == 0,], x = "broker", label = "con"))
kable(tab_a4_panel_f, col.names=c("Stratum", "Audit Sample (%)", "Audit Sample (SE)",
"Exp Sample (%)", "Exp Sample (SE)",
"Any Treatment (%)", "Any Treatment (SE)",
"Control (%)", "Control (SE)"),
caption="**Table A4, Panel E. Listed by Broker (Scraped from Craigslist).**")
#----------------------------------------#
# Min/Max Advertised Monthly Rental Price
# (Reported in online SI text, page A-19)
min_max_monthly_rent <- cbind(stratum_labels,
calc_descriptives(min, df = aud, x = "rent", label = "aud"),
calc_descriptives(max, df = aud, x = "rent", label = "aud"),
calc_descriptives(min, df = dat, x = "rent", label = "exp"),
calc_descriptives(max, df = dat, x = "rent", label = "exp"),
calc_descriptives(min, df = dat[dat$TA != 0,], x = "rent", label = "trt"),
calc_descriptives(max, df = dat[dat$TA != 0,], x = "rent", label = "trt"),
calc_descriptives(min, df = dat[dat$TA == 0,], x = "rent", label = "con"),
calc_descriptives(max, df = dat[dat$TA == 0,], x = "rent", label = "con"))
kable(min_max_monthly_rent, col.names=c("Stratum", "Audit Sample (Min)", "Audit Sample (Max)",
"Exp Sample (Min)", "Exp Sample (Max)",
"Any Treatment (Min)", "Any Treatment (Max)",
"Control (Min)", "Control (Max)"),
caption="**Mininum and Maximum Advertised Monthly Rental Price (Reported in online SI, page A-19)**")
```
```{r, echo=F, eval=T, warning=F, include=FALSE}
##### NOTE: set eval=T to export tex; eval=F suppresses tex output in the Rmd output
# Format table and export to tex
#----------------------------------------#
# Stitch together Table A4, export as tex
tab_a4_panel_a <- rbind(c("Panel A. Number of Units", "N", "Percent", "N", "Percent", "N", "Percent", "N", "Percent"),
tab_a4_panel_a)
tab_a4_panel_b <- rbind(c("Panel B. Monthly Asking Price ($)", rep(c("Mean", "SD"), 4)),
tab_a4_panel_b)
tab_a4_panel_c <- rbind(c("Panel C. Median Monthly Asking Price ($)", rep(c("Median", ""), 4)),
tab_a4_panel_c)
tab_a4_panel_d <- rbind(c("Panel D. Number of Bedrooms", rep(c("Mean", "SD"), 4)),
tab_a4_panel_d)
tab_a4_panel_e <- rbind(c("Panel E. Square Footage", rep(c("Mean", "SD"), 4)),
tab_a4_panel_e)
tab_a4_panel_f <- rbind(c("Panel F. Listed by Broker", rep(c("Percent", "SE"), 4)),
tab_a4_panel_f)
colnames(tab_a4_panel_a) <- colnames(tab_a4_panel_b) <- colnames(tab_a4_panel_c) <-
colnames(tab_a4_panel_d) <- colnames(tab_a4_panel_e) <- colnames(tab_a4_panel_f) <- NULL
table_a4 <- rbind(tab_a4_panel_a,
tab_a4_panel_b,
tab_a4_panel_c,
tab_a4_panel_d,
tab_a4_panel_e,
tab_a4_panel_f)
colnames(table_a4)[1:ncol(table_a4)] <- c("",
rep("Audit Sample",2),
rep("Experimental Sample",2),
rep("Any Treatment",2),
rep("Control Group",2))
table_a4 <- print(xtable(table_a4), include.rownames=FALSE)
table_a4 <- unlist(strsplit(table_a4, "\n"))
swaps <- rbind(c("\\begin{tabular}{lllllllll}", "\\begin{tabular}{lrr|rr|rr|rr}"),
c("V1 & Audit Sample & Audit Sample & Experimental Sample & Experimental Sample & Any Treatment & Any Treatment & Control Group & Control Group \\\\ ",
" & \\multicolumn{2}{c|}{I. Audit Sample} & \\multicolumn{2}{c|}{II. Experimental Sample} & \\multicolumn{2}{c|}{III. Any Treatment} & \\multicolumn{2}{c}{IV. Control Group} \\\\ "))
for(i in 1:nrow(swaps)){
table_a4 <- gsub(swaps[i,1] , swaps[i,2] , table_a4, fixed=TRUE)
}
rm(i)
table_a4 <- c(table_a4[3:4],
"\\resizebox{1\\textwidth}{!}{",
table_a4[5:9], "\\cline{2-9}",
table_a4[10:16], "\\hline",
table_a4[17], "\\cline{2-9}",
table_a4[18:24],"\\hline",
table_a4[25], "\\cline{2-9}",
table_a4[26:32],"\\hline",
table_a4[33], "\\cline{2-9}",
table_a4[34:40],"\\hline",
table_a4[41], "\\cline{2-9}",
table_a4[42:48],"\\hline",
table_a4[49], "\\cline{2-9}",
table_a4[50:58],
"}",
"\\caption{Selected Pre-Treatment Characteristics of Housing Units in the Audit and Experimental Samples. Data on housing characteristics are scraped from Craigslist ads. In cells where the standard invisble(dev.off())iation is NA (i.e., for square footage), this means that only one observation had non-missing data; these data were largely missing because square footage information is rarely included in Craigslist rental listings in New York City.} \\label{samplechar}",
table_a4[59])
cat(table_a4, file="out_tablea4_sample_characteristics.tex", sep="\n")
```
## Table A5 (p. A-21): Distribution of Rental Units Across Boroughs, by Sample
```{r tablea5, echo=T, eval=T, warning=F}
# Note: Citywide 2011 numbers are from Table 5 in
# http://www.nyc.gov/html/hpd/downloads/pdf/HPD-2011-HVS-Selected-Findings-Tables.pdf
# For an archived version of this document available via the Internet Archive Wayback Machine, see
# http://web.archive.org/web/20131102065647/http://www.nyc.gov/html/hpd/downloads/pdf/HPD-2011-HVS-Selected-Findings-Tables.pdf
# A PDF copy of this document is also included in the replication archive
tab.city.n <- c(691178, 388022, 587313, 449108, 57013)
tab.city.pct <- c(31.81, 17.86, 27.03, 20.67, 2.62)
db.aud <- ddply(aud[aud$frame != "likely disc",], .(boro), summarise,
num = length(cid),
pct = round(length(cid)/nrow(aud[aud$frame != "likely disc",])*100, 2))
db.exp <- ddply(dat[dat$frame != "likely disc",], .(boro), summarise,
num = length(cid),
pct = round(length(cid)/nrow(dat[dat$frame != "likely disc",])*100, 2))
db.con <- ddply(dat[dat$frame != "likely disc" & dat$TA==0,], .(boro), summarise,
num = length(cid),
pct = round(length(cid)/nrow(dat[dat$frame != "likely disc" & dat$TA==0,])*100, 2))
colnames(db.aud) <- c("boro", "Audit Sample (N)", "Audit Sample (%)")
colnames(db.exp) <- c("boro", "Exp Sample (N)", "Exp Sample (%)")
colnames(db.con) <- c("boro", "Control Group (N)", "Control Group (%)")
tab.db <- join(db.aud, db.exp, by="boro", type="left", match="all")
tab.db <- join(tab.db, db.con, by="boro", type="left", match="all")
tab.db <- cbind(tab.db[,1],
tab.city.n,
tab.city.pct,
tab.db[,2:ncol(tab.db)])
tab.db[,1] <- c("Brooklyn", "Bronx", "Manhattan", "Queens", "Staten Island")
colnames(tab.db)[1:3] <- c("Borough", "Citywide 2011 (N)", "Citywide 2011 (%)")
tab.db <- rbind(tab.db,
c("Total", round(apply(tab.db[,2:ncol(tab.db)],2,sum), 0)))
kable(tab.db, caption="**Table A5**")
```
```{r, include=FALSE}
print(xtable(tab.db), file="out_tablea5_dist_by_borough.tex", include.rownames=FALSE)
```
## Figure A5 (p. A-22): Map of the Geographic Distribution of Housing Units Corresponding to Advertised Listings
We omit the replication data and code to produce Figure A5, the map of the geographic distribution of rental units in the audit and experimental samples, because these require non-anonymized data that contain personal identifying information about the subjects.
## Table A6 (p. A-24): Baseline Incidence of Discrimination: In-Person and Post-Visit
```{r tablea6, echo=T, eval=T, warning=F}
outvars <- c("meet", "sales", "qualpraise", "posbg", "posedit", "prof", "cb", "off")
summm <- function(outvar, group1 = "C", group2 = "A"){
outvar1 <- paste0(outvar, "_", group1)
outvar2 <- paste0(outvar, "_", group2)
ctrl_maj_mean <- mean(as.numeric(dat[[outvar1]][dat$TA==0]), na.rm=TRUE) # majority mean
ctrl_min_mean <- mean(as.numeric(dat[[outvar2]][dat$TA==0]), na.rm=TRUE) # minority mean
ctrl_diff <- ctrl_maj_mean - ctrl_min_mean # difference
if(outvar %in% c("meet", "cb", "off")){
ctrl_P <- t.test(x=as.numeric(dat[[outvar1]][dat$TA==0]),
y=as.numeric(dat[[outvar2]][dat$TA==0]),
alternative="two.sided",
paired=TRUE,
conf.level=0.95)$p.value # p value from t-test (two-sided)
} else {
ctrl_P <- t.test(x = as.numeric(dat[[outvar1]][dat$TA==0]),
y = as.numeric(dat[[outvar2]][dat$TA==0]),
alternative = "two.sided",
paired = TRUE,
conf.level = 0.95)$p.value # p value from t-test (two-sided)
}
ctrl_N <- ifelse(length(dat[[outvar1]][dat$TA==0 & !is.na(dat[[outvar1]])])==length(as.numeric(dat[[outvar2]][dat$TA==0 & !is.na(dat[[outvar2]])])),
length(dat[[outvar1]][dat$TA==0 & !is.na(dat[[outvar1]])]),
length(dat[[outvar1]][dat$TA==0 & !( is.na(dat[[outvar1]]) & is.na(dat[[outvar2]]) )]) )# sample size
## ANY TREATMENT (cols 7-11)
any_maj_mean <- mean(as.numeric(dat[[outvar1]][dat$TA %in% c(1,2)]), na.rm=TRUE) # majority mean
any_min_mean <- mean(as.numeric(dat[[outvar2]][dat$TA %in% c(1,2)]), na.rm=TRUE) # minority mean
any_diff <- any_maj_mean - any_min_mean # difference
if(outvar %in% c("meet", "cb", "off")){
any_P <- t.test(x=as.numeric(dat[[outvar1]][dat$TA %in% c(1,2)]),
y=as.numeric(dat[[outvar2]][dat$TA %in% c(1,2)]),
alternative="two.sided",
paired=TRUE,
conf.level=0.95)$p.value # p value from t-test (two-sided)
} else {
any_P <- t.test(x=as.numeric(dat[[outvar1]][dat$TA %in% c(1,2)]),
y=as.numeric(dat[[outvar2]][dat$TA %in% c(1,2)]),
alternative="two.sided",
paired=FALSE,
conf.level=0.95)$p.value # p value from t-test (two-sided)
}
any_N <- ifelse(length(dat[[outvar1]][dat$TA%in%c(1,2) & !is.na(dat[[outvar1]])])==length(as.numeric(dat[[outvar2]][dat$TA%in%c(1,2) & !is.na(dat[[outvar2]])])),
length(dat[[outvar1]][dat$TA%in%c(1,2) & !is.na(dat[[outvar1]])]),
length(dat[[outvar1]][dat$TA%in%c(1,2) & !( is.na(dat[[outvar1]]) & is.na(dat[[outvar2]]) )]) )# sample size
## EXPERIMENT SAMPLE (cols 12-16)
exp_maj_mean <- mean(as.numeric(dat[[outvar1]][dat$TA %in% c(0,1,2)]), na.rm=TRUE) # majority mean
exp_min_mean <- mean(as.numeric(dat[[outvar2]][dat$TA %in% c(0,1,2)]), na.rm=TRUE) # minority mean
exp_diff <-exp_maj_mean - exp_min_mean # difference
if(outvar %in% c("meet", "cb", "off")){
exp_P <- t.test(x=as.numeric(dat[[outvar1]][dat$TA %in% c(0,1,2)]),
y=as.numeric(dat[[outvar2]][dat$TA %in% c(0,1,2)]),
alternative="two.sided",
paired=TRUE,
conf.level=0.95)$p.value # p value from t-test (two-sided)
} else {
exp_P <- t.test(x=as.numeric(dat[[outvar1]][dat$TA %in% c(0,1,2)]),
y=as.numeric(dat[[outvar2]][dat$TA %in% c(0,1,2)]),
alternative="two.sided",
paired=FALSE,
conf.level=0.95)$p.value # p value from t-test (two-sided)
}
exp_N <- ifelse(length(dat[[outvar1]][dat$TA%in%c(0,1,2) & !is.na(dat[[outvar1]])])==length(as.numeric(dat[[outvar2]][dat$TA%in%c(0,1,2) & !is.na(dat[[outvar2]])])),
length(dat[[outvar1]][dat$TA%in%c(0,1,2) & !is.na(dat[[outvar1]])]),
length(dat[[outvar1]][dat$TA%in%c(0,1,2) & !( is.na(dat[[outvar1]]) & is.na(dat[[outvar2]]))])) # sample size
c(ctrl_maj_mean, ctrl_min_mean, ctrl_diff, ctrl_P, ctrl_N,
any_maj_mean, any_min_mean, any_diff, any_P, any_N,
exp_maj_mean, exp_min_mean, exp_diff, exp_P, exp_N)
}
wb <- cbind( c("Showed up to appointment (White vs. Black)",
"Perceived sales efforts (White vs. Black)",
"Received praise about rental qualifications (White vs. Black)",
"Positive reactions to testers' background (White vs. Black)",
"Positive editorializing (White vs. Black)",
"Professionalism (White vs. Black)",
"Received post-visit callback (White vs. Black)",
"Received post-visit offer for unit (White vs. Black)",
"Index measure of favorable in-person interactions (White vs. Black)"),
rbind(t(sapply(outvars, summm, group1 = "C", group2 = "A")), "") )
wh <- cbind(c("Showed up to appointment (White vs. Hispanic)",
"Perceived sales efforts (White vs. Hispanic)",
"Received praise about rental qualifications (White vs. Hispanic)",
"Positive reactions to testers' background (White vs. Hispanic)",
"Positive editorializing (White vs. Hispanic)",
"Professionalism (White vs. Hispanic)",
"Received post-visit callback (White vs. Hispanic)",
"Received post-visit offer for unit (White vs. Hispanic)",
"Index measure of favorable in-person interactions (White vs. Hispanic)"),
rbind(t(sapply(outvars, summm, group1 = "C", group2 = "B")), ""))
bh <- cbind( c("Showed up to appointment (Black vs. Hispanic)",
"Perceived sales efforts (Black vs. Hispanic)",
"Received praise about rental qualifications (Black vs. Hispanic)",
"Positive reactions to testers' background (Black vs. Hispanic)",
"Positive editorializing (Black vs. Hispanic)",
"Professionalism (Black vs. Hispanic)",
"Received post-visit callback (Black vs. Hispanic)",
"Received post-visit offer for unit (Black vs. Hispanic)",
"Index measure of favorable in-person interactions (Black vs. Hispanic)"),
rbind(t(sapply(outvars, summm, group1 = "A", group2 = "B")), ""))
## CONTROL GROUP
wb[nrow(wb),4] <- mean(as.numeric(dat[[net.ind.mat[1]]][dat$TA==0]), na.rm=TRUE) # difference
wb[nrow(wb),6] <- length(as.numeric(dat[[net.ind.mat[1]]][dat$TA%in%c(0) & !is.na(dat[[net.ind.mat[1]]])])) # sample size
## ANY TREATMENT
wb[nrow(wb),9] <- mean(as.numeric(dat[[net.ind.mat[1]]][dat$TA%in%c(1,2)]), na.rm=TRUE) # difference
wb[nrow(wb),11] <- length(as.numeric(dat[[net.ind.mat[1]]][dat$TA%in%c(1,2) & !is.na(dat[[net.ind.mat[1]]])])) # sample size
## EXPERIMENT SAMPLE
wb[nrow(wb),14] <- mean(as.numeric(dat[[net.ind.mat[1]]][dat$TA%in%c(0,1,2)]), na.rm=TRUE) # difference
wb[nrow(wb),16] <- length(as.numeric(dat[[net.ind.mat[1]]][dat$TA%in%c(0,1,2) & !is.na(dat[[net.ind.mat[1]]])])) # sample size
## CONTROL GROUP
wh[nrow(wh),4] <- mean(as.numeric(dat[[net.ind.mat[2]]][dat$TA==0]), na.rm=TRUE) # difference
wh[nrow(wh),6] <- length(as.numeric(dat[[net.ind.mat[2]]][dat$TA%in%c(0) & !is.na(dat[[net.ind.mat[2]]])])) # sample size
## ANY TREATMENT
wh[nrow(wh),9] <- mean(as.numeric(dat[[net.ind.mat[2]]][dat$TA%in%c(1,2)]), na.rm=TRUE) # difference
wh[nrow(wh),11] <- length(as.numeric(dat[[net.ind.mat[2]]][dat$TA%in%c(1,2) & !is.na(dat[[net.ind.mat[2]]])])) # sample size
## EXPERIMENT SAMPLE
wh[nrow(wh),14] <- mean(as.numeric(dat[[net.ind.mat[2]]][dat$TA%in%c(0,1,2)]), na.rm=TRUE) # difference
wh[nrow(wh),16] <- length(as.numeric(dat[[net.ind.mat[2]]][dat$TA%in%c(0,1,2) & !is.na(dat[[net.ind.mat[2]]])])) # sample size
## CONTROL GROUP
bh[nrow(bh),4] <- mean(as.numeric(dat[[net.ind.mat[3]]][dat$TA==0]), na.rm=TRUE) # difference
bh[nrow(bh),6] <- length(as.numeric(dat[[net.ind.mat[3]]][dat$TA%in%c(0) & !is.na(dat[[net.ind.mat[3]]])])) # sample size
## ANY TREATMENT
bh[nrow(bh),9] <- mean(as.numeric(dat[[net.ind.mat[3]]][dat$TA%in%c(1,2)]), na.rm=TRUE) # difference
bh[nrow(bh),11] <- length(as.numeric(dat[[net.ind.mat[3]]][dat$TA%in%c(1,2) & !is.na(dat[[net.ind.mat[3]]])])) # sample size
## EXPERIMENT SAMPLE
bh[nrow(bh),14] <- mean(as.numeric(dat[[net.ind.mat[3]]][dat$TA%in%c(0,1,2)]), na.rm=TRUE) # difference
bh[nrow(bh),16] <- length(as.numeric(dat[[net.ind.mat[3]]][dat$TA%in%c(0,1,2) & !is.na(dat[[net.ind.mat[3]]])])) # sample size
```
```{r tablea6format, include=FALSE}
# populate column headings
colnames(wb) <- c("Measure", paste( c(rep("Control-",5),rep("AnyTreat-",5),rep("ExpSamp-",5)) , rep(c("Maj-Mean","Min-Mean","Diff","P","N"),3), sep=""))
colnames(wh) <- c("Measure", paste( c(rep("Control-",5),rep("AnyTreat-",5),rep("ExpSamp-",5)) , rep(c("Maj-Mean","Min-Mean","Diff","P","N"),3), sep=""))
colnames(bh) <- c("Measure", paste( c(rep("Control-",5),rep("AnyTreat-",5),rep("ExpSamp-",5)) , rep(c("Maj-Mean","Min-Mean","Diff","P","N"),3), sep=""))
for(i in 2:ncol(wb)){
wb[,i] <- round(as.numeric(wb[,i]), 3)
wh[,i] <- round(as.numeric(wh[,i]), 3)
bh[,i] <- round(as.numeric(bh[,i]), 3)
if(i %in% c(5,10,15)) {
wb[,i] <- paste("(",wb[,i],")",sep="")
wh[,i] <- paste("(",wh[,i],")",sep="")
bh[,i] <- paste("(",bh[,i],")",sep="")
}
if(i %in% c(6,11,16)) {
wb[,i] <- paste("[",wb[,i],"]",sep="")
wh[,i] <- paste("[",wh[,i],"]",sep="")
bh[,i] <- paste("[",bh[,i],"]",sep="")
}
}
```
```{r print_tablea7}
out <- rbind(wb[c(1,9,2:8),],
wh[c(1,9,2:8),],
bh[c(1,9,2:8),])
out <- out[-c(2,11,20),] # get rid of index measure (it makes no sense to include it because it is standardized to the control group mean)
kable(out[,c(1:6)], caption="**Table A6, Panel I: Cases Assigned to Control Group**", col.names=c("Measure", "Majority Group Mean", "Minority Group Mean", "Difference (Maj-Min)", "p-value", "[N]"))
kable(out[,c(1, 7:11)], caption="**Table A6, Panel II: Cases Assigned to Any Treatment Group**", col.names=c("Measure", "Majority Group Mean", "Minority Group Mean", "Difference (Maj-Min)", "p-value", "[N]"))
kable(out[,c(1, 12:16)], caption="**Table A6, Panel III: All Cases in Experimental Sample**", col.names=c("Measure", "Majority Group Mean", "Minority Group Mean", "Difference (Maj-Min)", "p-value", "[N]"))
```
```{r, include=FALSE}
print(xtable(out, caption=c("Baseline Incidence of Discrimination: In-Person and Post-Visit",
"Baseline Incidence of Discrimination: In-Person and Post-Visit")),
file="out_tablea6_baseline_discrim.tex",
hline.after=c(0,8,16,24),
include.rownames=FALSE)
```
## Table A7 (p. A-25): Estimated Effects of Messaging on Net Discrimination Levels
```{r prep_tablea7, include=FALSE}
itt.wb.mc <- matrix(NA, nrow=length(outvars.wb), ncol=5)
itt.wb.pc <- matrix(NA, nrow=length(outvars.wb), ncol=5)
itt.wb.pm <- matrix(NA, nrow=length(outvars.wb), ncol=5)
itt.wh.mc <- matrix(NA, nrow=length(outvars.wh), ncol=5)
itt.wh.pc <- matrix(NA, nrow=length(outvars.wh), ncol=5)
itt.wh.pm <- matrix(NA, nrow=length(outvars.wh), ncol=5)
itt.bh.mc <- matrix(NA, nrow=length(outvars.bh), ncol=5)
itt.bh.pc <- matrix(NA, nrow=length(outvars.bh), ncol=5)
itt.bh.pm <- matrix(NA, nrow=length(outvars.bh), ncol=5)
fit.wb.mc <- fit.wb.pc <- fit.wb.pm <- fit.wh.mc <- fit.wh.pc <- fit.wh.pm <- fit.bh.mc <- fit.bh.pc <- fit.bh.pm <- list() # store
```
```{r tablea7, echo=T, eval=T, warning=F}
# ---------------------------------------------------------------------- #
# DEFINE COLNAMES FOR OUTPUT TABLES
col.labels <- c("Outcome", "Estimate","SE","t","P")
# ---------------------------------------------------------------------- #
# MODELS WITH ONLY BLOCK FIXED EFFECTS
# results from ITT est w/ block FE (no other covs)