-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20190805_rep.Rmd
1668 lines (1279 loc) · 60.6 KB
/
20190805_rep.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: 'Exporting Democratic Practices: Evidence from a Village Governance Intervention in East Congo'
author: "Macartan Humphreys, Raul Sanchez de la Sierra, Peter van der Windt"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
rmarkdown::github_document:
toc: TRUE
toc_depth: 2
html_preview: TRUE
---
```{r setup, include=FALSE}
rm(list=ls(all=TRUE))
gc()
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
```
This file replicates the core analysis as well as additional results of [Humphreys, M., de la Sierra, R. S., & Van der Windt, P. (2019). Exporting democratic practices: Evidence from a village governance intervention in Eastern Congo. _Journal of Development Economics_](https://www.sciencedirect.com/science/article/pii/S0304387818305078).
* Data for this analysis is [available on Dataverse](https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/BSASJR) and can be sourced directly from the Dataverse server with the option below (`local_data <- FALSE`) or locally from folder "Data".
* Supporting code including this page is [available on Github](https://github.com/macartan/replication_jde2019_drc). The code outputs tables and figures into the folder "Output", which are then sourced in from the LaTeX file of the manuscript.
```{r pacs, include = FALSE}
set.seed(1)
# Install packages
# Possibly necessary installations (if sourcing data from Dataverse):
# devtools::install_github("iqss/dataverse-client-r")
# install.packages("DeclareDesign", dependencies = TRUE,
# repos = c("http://R.declaredesign.org", "https://cloud.r-project.org"))
# Load (and install when necessary) packages
library("pacman")
pacman::p_load(rgdal,raster,plyr,AER,devtools,doBy,dplyr,energy,entropy,foreign,gdata,ggplot2,ggthemes,grid,gridExtra,haven,ivpack,lmtest,magrittr,maps,maptools,mosaic,multiwayvcov,pander,parallel,plm,R.matlab,reshape2,sandwich,SDMTools,spdep,stargazer,tidyr,xtable,SDMTools, estimatr, knitr,readstata13, rio, DeclareDesign, rmarkdown, tidyverse, readr)
# Options
options(xtable.comment = FALSE)
panderOptions("table.style", "rmarkdown")
panderOptions("digits", 4)
panderOptions("table.split.table", 140)
panderOptions("table.caption.prefix","")
```
# Preliminaries
## Options
Options can be set to use data from data folder or directly from dataverse. Note that if you ar e using this from public repositories then you have access to all code and almost all data but you do not have access to fine grained GPS data and so `with_GPS` should be set to `FALSE`. All analysis will still run although (a) spillover analysis will be implemented using summary data without GPS codes (b) maps will not be produced.
```{r youropts}
# load data locally (TRUE) or from dataverse (FALSE)
local_data <- FALSE
local_datapath = "Data"
# save figure and tables to output folder
saving <- TRUE
output_folder <- "Output"
# Set number simulatons used for calculating propensities and for the randomization inference p-values
spilloversims <- 5000 #5000 takes a long time, consider lowering for speediness
# Reproduce outputs requiring GPS data (usually set to `FALSE` since precise gps not publicly available)
with_GPS <- FALSE
# Save geodeidentified data, if geo data available (usually set to `FALSE` since precise gps not publicly available)
save_geodeidentified_data <- FALSE
if(!with_GPS) save_geodeidentified_data <- FALSE
```
## Definitions
```{r varnames}
# List indicators of main outcome (capture)
capture_var_names <- c(
"Financial Irregularities",
"Embezzlement (direct)",
"Embezzlement (list experiment)",
"Inequality of (Private) Benefits",
"Dominance of Chief's Preferences")
# List indicators of mechanisms (participation, accountability, transparency)
mech_var_names = c(
"Meeting Attendance",
"Interventions in Meeting",
"Dominance of Men in Discussion",
"Participatory Selection Methods",
"Committee Composition",
"Accountability Mechanisms",
"Private Complaints",
"Knowledge of Project Amount",
"Willingness to Seek Information",
"Quality of Accounting"
)
varnames <- c(capture_var_names, mech_var_names)
varnames2 <- paste(rbind(varnames, rep("",length(varnames))))
```
## Run Helper Code
Script to create helper functions that will be used in the remainder of the replication.
```{r helpers}
source("Code/0 HelperFunctions.R")
```
## Get Data
### Local data
```{r getlocal}
if(local_data){
abd_vill <- load_file("DRC2012_ABD_VILL_v2.dta")
abd_ind <- load_file("DRC2012_ABD_INDIV_v2.dta")
tuungane <- load_file("TUUNGANE_v2.dta")
irc_tuungane <- load_file("irc_tuungane.dta")
audit <- load_file("DRC2012_D_AUDIT_v2.dta")
abd_disc <- load_file("DRC2012_A_DISC_v2.dta")
roster <- load_file("DRC2012_D_ROSTER_v2.dta")
cdcdata <- load_file("gps/IDV_WEIGHTS_201203.dta")
D <- load_file("Dates_medians.dta")
idv_dists <- load_file("idv_distances.dta")
}
```
### Data on `Dataverse`
```{r getdv}
if(!local_data){
library(dataverse)
Sys.setenv("DATAVERSE_SERVER" = "dataverse.harvard.edu")
f <- function(filename, extension = ".tab"){
g <- get_file(paste0(filename, extension), "doi:10.7910/DVN/BSASJR")
tmp <- tempfile(fileext = ".dta")
writeBin(as.vector(g), tmp)
read_dta(tmp)}
abd_vill <- f("DRC2012_ABD_VILL_v2") # Village data
abd_ind <- f("DRC2012_ABD_INDIV_v2") # Indiv data
tuungane <- f("TUUNGANE_v2") # Attitudes data for non-Tuungane subset
irc_tuungane <- f("irc_tuungane") # IRC Tuungane
audit <- f("DRC2012_D_AUDIT_v2") # Audit data
abd_disc <- f("DRC2012_A_DISC_v2") # Discussion data
roster <- f("DRC2012_D_ROSTER_v2") # Roster
cdcdata <- f("IDV_WEIGHTS_201203") # CDC Data
D <- f("Dates_medians") # Dates
idv_dists <- f("idv_distances") # Adjacency matrix
}
```
### GPS data
Fine grain gps data is not publicly available following privacy protocols. These can be loaded here if available, otherwise summary data is used for replication.
```{r getgpsdata}
# Raw GPS if available
if(with_GPS){
X <- load_file("20140211indirect_5000sims_5km.dta")
X20 <- load_file("20140211indirect_5000sims_20km.dta")
GPS <- load_file("gps/gps_tuungane.dta")
drc.map.test <- readShapePoly(paste0(local_datapath, "/shapefiles/COD_adm2"))
col <- readOGR(dsn = paste0(local_datapath, "/shapefiles"), "collectivite")
}
```
## Prepare Dataset and Variables
Script prepares data and variables for analysis.
```{r clean1}
# Merge subgroup data, treatment info, lottery info, etc. to the datasets
source("Code/1 PrepDatasets.R")
```
Here we prepare data for spillovers analysis. Alongside the gps database we use:
* a database of possible direct assignments (dir)
* a database of possible indirect assignments at 5k (ind05) and 20k (ind20)
* database of inverse propensity weights -- these are different depending on each assignment becuase they report the probability of being assigned to the condition you are assigned to
These datasets are generated here if gps data is available, otherwise they are imported.
```{r}
source("Code/2.1 PrepSpillovers_village_data.R")
if(with_GPS) source("Code/2.2 PrepSpillovers_rerandomize.R")
if(!with_GPS) source("Code/2.3 PrepSpillovers_import.R")
```
# Table 2: Results on Public Fund Allocation
Script presents the result on public funds allocation.
```{r, warning=FALSE}
dvs <- c("da109_not_verifiable",
"qr026i_fund_misuse",
#"qr2729_list_experiment",
"qr2830_list_experiment",
"stdev_benefits",
#"Correct_D_projet"
"Correct_B_projet")
main_results <- list(
fin_irregul = lm_robust(da109_not_verifiable ~ TUUNGANE ,
data = vill,
fixed_effects = LOTT_BIN,
weights = VILL_WEIGHT),
embezzl_dir = lm_robust(qr026i_fund_misuse ~ TUUNGANE + as.factor(LOTT_BIN) ,
data = ind,
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE),
embezzl_list = lm_robust(
qr2830_list_experiment ~ TUUNGANE + RB + RB*TUUNGANE + as.factor(LOTT_BIN),
data = ind,
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE),
ineq_benef = lm_robust(stdev_benefits ~ TUUNGANE ,
fixed_effects = LOTT_BIN,
data = vill,
weights = VILL_WEIGHT ),
chief_domin = lm_robust(
Correct_B_projet ~ TUUNGANE + CHIEF + CHIEF*TUUNGANE + as.factor(LOTT_BIN) ,
data = ind,
clusters = IDS_CDCCODE,
weights = VILL_WEIGHT))
main_table_pre <- mapply(function(x, name) {
tidy = tidy(x); rownames(tidy) = tidy$term;
if( name == "embezzl_list" )
round(c(Control = tidy["RB", "estimate"],
Control_se = tidy["RB", "std.error"],
Effect = tidy["TUUNGANE:RB", "estimate"],
std_error = tidy["TUUNGANE:RB", "std.error"],
N = x$N), 3)
else if(name == "chief_domin")
round(c(Control = tidy["CHIEFTRUE", "estimate"],
Control_se = tidy["CHIEFTRUE", "std.error"],
Effect = tidy["TUUNGANE:CHIEFTRUE", "estimate"],
std_error = tidy["TUUNGANE:CHIEFTRUE", "std.error"],
N = x$N), 3)
else
round(c(Control = tidy["(Intercept)", "estimate"],
Control_se = tidy["(Intercept)", "std.error"],
Effect = tidy["TUUNGANE", "estimate"],
std_error = tidy["TUUNGANE", "std.error"],
N = x$N ),3)
}, main_results, names(main_results))
add_cols <- mapply(function(d, dv){
d <- d %>% arrange(LOTT_BIN)
N_cluster <- ifelse(length(unique(d$IDV_CDCCODE[!is.na(d[[dv]])])) > 0,
length(unique(d$IDV_CDCCODE[!is.na(d[[dv]])])),
length(unique(d$IDS_CDCCODE[!is.na(d[[dv]])])))
#block weights in the data
d$dv <- d[[dv]][]
#block average for control
ave_ctrl_blocks <- d %>%
subset(TUUNGANE == 0) %>%
group_by(LOTT_BIN) %>%
summarize(block_n = sum(!is.na(dv)),
ave = mean(dv, na.rm = TRUE)) %>% ungroup() %>%
mutate(block_w = block_n/nrow(.))
#weighted average of block averages
w_ave_ctrl_blocks <- weighted.mean(ave_ctrl_blocks$ave, ave_ctrl_blocks$block_w, na.rm = TRUE)
#weighted sd of block averages
w_sd_ctrl_blocks <- sd(d$dv, na.rm = TRUE)
return(round(rbind(w_ave_ctrl_blocks, w_sd_ctrl_blocks, N_cluster), 3))
}, d = list(vill, ind, ind, vill, ind), dv = dvs) %>% t()
main_table <- cbind(control.mean = add_cols[,1], control.sd = add_cols[,2], t(main_table_pre)[,-c(1:2)], N_cluster = add_cols[,3])
#maintain beta1 coefficient and standard error instead of control mean for "embezzl_dir", "chief_domin"
keep_beta1 <- rownames(main_table) %in% c("embezzl_list", "chief_domin")
main_table[keep_beta1, "control.mean"] <- t(main_table_pre)[keep_beta1, "Control"]
main_table[keep_beta1, "control.sd"] <- t(main_table_pre)[keep_beta1, "Control_se"]
kable(main_table)
```
# Table 3: Results on Democratic Practices
Script presents the result on democratic practices.
```{r}
dvs_mech <- c("PART_A1", "N_INTERV", "MALE_DOM", "MFI_SELECTION", "MFI_COMPOSITION", "MFI_MECHANISMS", "MFI_COMPLAINTS", "qr002CORRECT", "qi003_accept", "MFI_ACCOUNTING")
mechanisms <- list(
part = lm_robust(PART_A1 ~ TUUNGANE ,
data = vill,
fixed_effects = LOTT_BIN,
weights = VILL_WEIGHT),
inter = lm_robust(N_INTERV ~ TUUNGANE ,
data = vill,
fixed_effects = LOTT_BIN,
weights = VILL_WEIGHT),
male_d = lm_robust(MALE_DOM ~ TUUNGANE,
data = vill,
fixed_effects = LOTT_BIN,
weights = VILL_WEIGHT),
sel = lm_robust(MFI_SELECTION ~ TUUNGANE ,
data = vill,
fixed_effects = LOTT_BIN,
weights = VILL_WEIGHT),
compos = lm_robust(MFI_COMPOSITION ~ TUUNGANE,
fixed_effects = LOTT_BIN,
data = vill,
weights = VILL_WEIGHT),
mech = lm_robust(MFI_MECHANISMS ~ TUUNGANE,
data = vill,
fixed_effects = LOTT_BIN,
weights = VILL_WEIGHT),
compl = lm_robust(MFI_COMPLAINTS ~ TUUNGANE + as.factor(LOTT_BIN),
data = ind,
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE),
corr = lm_robust(qr002CORRECT ~ TUUNGANE + as.factor(LOTT_BIN),
data = ind,
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE),
accep = lm_robust(qi003_accept ~ TUUNGANE + as.factor(LOTT_BIN),
data = ind,
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE ),
accoun = lm_robust(MFI_ACCOUNTING ~ TUUNGANE,
data = vill,
fixed_effects = LOTT_BIN,
weights = VILL_WEIGHT)
)
mechanisms_table <- mapply(function(x, name){
tidy = tidy(x); rownames(tidy) = tidy$term;
round(c(Control = tidy["(Intercept)", "estimate"],
Effect = tidy["TUUNGANE", "estimate"],
std_error = tidy["TUUNGANE", "std.error"],
N = x$N ),3)
}, mechanisms, names(mechanisms))
add_cols <- mapply(function(d, dv){
d <- d %>% arrange(LOTT_BIN)
N_cluster <- ifelse(length(unique(d$IDV_CDCCODE[!is.na(d[[dv]])])) > 0,
length(unique(d$IDV_CDCCODE[!is.na(d[[dv]])])),
length(unique(d$IDS_CDCCODE[!is.na(d[[dv]])])))
#block weights in the data
d$dv <- d[[dv]][]
#block average for control
ave_ctrl_blocks <- d %>%
subset(TUUNGANE == 0) %>%
group_by(LOTT_BIN) %>%
summarize(block_n = sum(!is.na(dv)),
ave = mean(dv, na.rm = TRUE)) %>% ungroup() %>%
mutate(block_w = block_n/nrow(.))
#weighted average of block averages
w_ave_ctrl_blocks <- weighted.mean(ave_ctrl_blocks$ave, ave_ctrl_blocks$block_w, na.rm = TRUE)
#weighted sd of block averages
w_sd_ctrl_blocks <- sd(d$dv, na.rm = TRUE)
return(round(rbind(w_ave_ctrl_blocks, w_sd_ctrl_blocks, N_cluster), 3))
}, d = list(vill, vill, vill, vill, vill, vill, ind, ind, ind, vill), dv = dvs_mech) %>% t()
mechanisms_table <- cbind(control.mean = add_cols[,1], control.sd = add_cols[,2], t(mechanisms_table)[,-1], N_cluster = add_cols[,3])
kable(mechanisms_table)
```
Script to output result tables to .tex files.
```{r}
source("Code/3.2 Output_MainResults.R")
if(saving){
sink(paste0(output_folder, "/Table2_Capture.tex"))
tablr(T2)
sink()
sink(paste0(output_folder, "/Table3_Practice.tex"))
tablr(T3)
sink()
}
```
# Table 4: Tuungane Balance Table
Create Tuungane balance table.
```{r T4}
# Balance variables
BALANCE_VARS <- c(DIST = "distance",
VILL = "dist_mine",
VILL = "mineral_index",
PUBLIC = "public2006",
VILL = "former_chief_elec",
MIG = "mig2006",
STATS = "age"
)
# Balance datasets
BALANCE <- list(vill, vill, vill, vill, vill, vill, as.data.frame(STATS))
# Balance table
balance.table <- sapply(1:length(BALANCE), function(i){
data <- BALANCE[[i]]
Y <- BALANCE_VARS[i]
balance_function(data[,Y, drop = TRUE],
data[,"TUUNGANE", drop = TRUE],
data[,"VILL_WEIGHT", drop = TRUE])}) %>%
round(., 2) %>%
t()
```
```{r, echo=FALSE}
tab <- as.data.frame(balance.table)
row.names(tab) <- c("Distance from major urban center", "Distance to village mine",
"Mineral composition", "Presence infrastructure in 2006",
"Former chief popular choice", "In-migration in 2006", "Age")
kable(tab, col.names = c("Control", "Tuungane", "d-stat", "N"))
```
## Table 4b: RAPID Balance Table (Supplementary)
Create RAPID balance table.
```{r T4b}
# Balance table
balance.table.RAPID <- sapply(1:length(BALANCE), function(i){
data <- BALANCE[[i]]
Y <- BALANCE_VARS[i]
balance_function(data[,Y][],
data[,"IDV_RAPID"][],
data[,"IPW_RAPID"][])}) %>%
round(., 2) %>%
t()
```
```{r, echo=FALSE}
tab <- as.data.frame(balance.table.RAPID)
row.names(tab) <- c("Distance from major urban center", "Distance to village mine",
"Mineral composition", "Presence infrastructure in 2006",
"Former chief popular choice", "In-migration in 2006", "Age")
kable(tab, col.names = c("Control", "RAPID", "d-stat", "N"))
```
Script to output tables to .tex files.
```{r}
source("Code/3.1 Output_BalanceTables.R")
if(saving){
sink(paste0(output_folder, "/Table4_Balance_TUUNGANE.tex"))
tablr(T_Balance)
sink()
}
if(saving){
sink(paste0(output_folder, "/Table4_Balance_RAPID.tex"))
tablr(T_Balance_RAPID)
sink()
}
```
# Table 5: Summary Statistics
```{r T5}
outcomes <- c("RAPID", "TUUNGANE", "da109_not_verifiable", "qr026i_fund_misuse",
"qr2830_list_experiment","stdev_benefits", "Correct_B_projet",
"PART_A1", "N_INTERV", "MALE_DOM", "MFI_SELECTION", "MFI_COMPOSITION",
"MFI_MECHANISMS","MFI_COMPLAINTS", "qr002CORRECT", "qi003_accept",
"MFI_ACCOUNTING")
datasets <- list(cdcdata, cdcdata, vill,
ind,ind,vill,
ind, vill, vill, vill,
vill, vill, vill,ind,
ind, ind, vill)
sumStats <- mapply(function(y, d){
IDVs <- cdcdata[,"IDV"]
if(y == "qr2830_list_experiment" | y == "Correct_B_projet"){
# subset interactions
if(y == "qr2830_list_experiment") {i0 <- d$RB == 0;i1 <- d$RB == 1}
if(y == "Correct_B_projet") {i0 <- d$CHIEF == 0; i1 <- d$CHIEF == 1}
# compute subsetted villmeans
villmean_0 <- aggregate(d[i0,c("IDV",y)], by= list(d$IDV[i0]), FUN="mean", na.rm=TRUE) %>%
select(IDV, X_0 = y)
villmean_1 <- aggregate(d[i1,c("IDV",y)], by= list(d$IDV[i1]), FUN="mean", na.rm=TRUE)%>%
select(IDV, X_1 = y)
# Clean up interactions -- Impute means where one side has data present
villmean <- merge(IDVs, villmean_0, by = "IDV", all.x = TRUE) %>%
merge(villmean_1 ,by = "IDV", all.x = TRUE) %>%
mutate(X_1 = ifelse(is.na(X_1)& !is.na(X_0), mean(X_1, na.rm = TRUE), X_1),
X_0 = ifelse(!is.na(X_1)&!is.na(X_0), mean(X_0, na.rm = TRUE), X_0),
X = X_1 - X_0)
} else {
villmean <- aggregate(d[,c("IDV",y)], by= list(d$IDV), FUN="mean", na.rm=TRUE) %>%
select(IDV, X = y)
}
with(villmean,
c( N = sum(!is.na(X)), mean = mean(X, na.rm = T), sd = sd(X, na.rm = T) , min = min(X, na.rm = T), max =max(X, na.rm = T)))
},y = outcomes, datasets)
kable(t(sumStats ), digits = 2 )
```
Script to output table to .tex files.
```{r}
source("Code/3.4 Output_SumStats.R")
if(saving){
sink(paste0(output_folder,"/Table5_SumStats.tex"))
tablr(T_SS)
sink()
}
```
# Tables 6 and 7: Spillovers
```{r T67, include = TRUE}
# Note: Blocks are not used in the calculation of estimates but blocks are taken into account in the randomization inference procedure
# spillover at 5km threshold
analysis05 <- sapply(gpsvars, function(j)
ri.analysis(gps[j][[1]], IND = gps$indirect05, indirects=ind05, weight = gps$gps_weight05, weight_matrix = w05, spilloversims = spilloversims)
)
CONTENT05 <- round(t(analysis05),2)
# spillover at 20km threshold
analysis20 <- sapply(gpsvars, function(j)
ri.analysis(gps[j][[1]], IND = gps$indirect20, indirects=ind20, weight = gps$gps_weight20, weight_matrix = w20, spilloversims = spilloversims)
)
CONTENT20 <- round(t(analysis20),2)
kable(CONTENT05, title = "Spillovers at 5km")
kable(CONTENT20, title = "Spillovers at 20km")
```
Script to output tables to .tex files.
```{r}
source("Code/3.5 Output_Spillovers.R")
if(saving){
sink(paste0(output_folder, "/Table6_spill05.tex"))
tablr(T_spill05)
sink()
sink(paste0(output_folder,"/Table7_spill20.tex"))
tablr(T_spill20)
sink()
}
```
# Table 8: Social Desirability
```{r T8}
pos <- lm_robust(FIRST_ANSWER ~ TUUNGANE + IDS_TUUNGANE_POS + POS_PROMPT,
weights = VILL_WEIGHT, data = ind, clusters = IDS_CDCCODE)
neg <- lm_robust(FIRST_ANSWER ~ TUUNGANE + IDS_TUUNGANE_NEG + NEG_PROMPT,
weights = VILL_WEIGHT, data = ind,
clusters = IDS_CDCCODE)
summary(pos)
summary(neg)
```
```{r, echo=FALSE}
source("Code/3.6 Output_SocDesirability.R")
if(saving){
sink(paste0(output_folder, "/Table8_SocDes.tex"))
tablr(sd.Table)
sink()
}
rownames(OUTPUT) <- c("Control", "Tuungane", "Difference", "(se)")
kable(OUTPUT, col.names = c("Positive prompt" , "Negative prompt" , "Difference" , "(se)") )
```
# Table 9: Robustness
```{r T9, include = TRUE}
## 1: Alternative treatment
robust_alt_treatment <- list(
fin_irregul = lm_robust(da109_not_verifiable ~ IRC_TUUNGANE,
data = vill,
fixed_effects = LOTT_BIN,
weights = VILL_WEIGHT),
embezzl_dir = lm_robust(qr026i_fund_misuse ~ IRC_TUUNGANE + as.factor(LOTT_BIN),
data = ind,
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE ),
embezzl_list = lm_robust(
qr2830_list_experiment ~ IRC_TUUNGANE + RB + RB*IRC_TUUNGANE + as.factor(LOTT_BIN),
data = ind,
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE),
ineq_benef = lm_robust(stdev_benefits ~ IRC_TUUNGANE,
fixed_effects = LOTT_BIN,
data = vill,
weights = VILL_WEIGHT ),
chief_domin = lm_robust(
Correct_B_projet ~ IRC_TUUNGANE + CHIEF + CHIEF*IRC_TUUNGANE + as.factor(LOTT_BIN),
data = ind,
clusters = IDS_CDCCODE,
weights = VILL_WEIGHT),
part = lm_robust(PART_A1 ~ IRC_TUUNGANE ,
data = vill,
fixed_effects = LOTT_BIN,
weights = VILL_WEIGHT),
inter = lm_robust(N_INTERV ~ IRC_TUUNGANE,
data = vill,
fixed_effects = LOTT_BIN,
weights = VILL_WEIGHT),
male_d = lm_robust(MALE_DOM ~ IRC_TUUNGANE,
data = vill,
fixed_effects = LOTT_BIN,
weights = VILL_WEIGHT),
sel = lm_robust(MFI_SELECTION ~ IRC_TUUNGANE,
fixed_effects = LOTT_BIN,
data = vill, weights = VILL_WEIGHT),
compos = lm_robust(MFI_COMPOSITION ~ IRC_TUUNGANE,
fixed_effects = LOTT_BIN,
data = vill,
weights = VILL_WEIGHT),
mech = lm_robust(MFI_MECHANISMS ~ IRC_TUUNGANE,
fixed_effects = LOTT_BIN,
data = vill,
weights = VILL_WEIGHT),
compl = lm_robust(MFI_COMPLAINTS ~ IRC_TUUNGANE + as.factor(LOTT_BIN),
data = ind,
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE ),
corr = lm_robust(qr002CORRECT ~ IRC_TUUNGANE + as.factor(LOTT_BIN),
data = ind,
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE ),
accep = lm_robust(qi003_accept ~ IRC_TUUNGANE + as.factor(LOTT_BIN),
data = ind,
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE),
accoun = lm_robust(MFI_ACCOUNTING ~ IRC_TUUNGANE,
data = vill,
fixed_effects = LOTT_BIN,
weights = VILL_WEIGHT)
)
robust_alt_treatment <- mapply(tidy_results, robust_alt_treatment, names(robust_alt_treatment), alt_treat = TRUE) %>% t()
robust_alt_treatment[,3] <- paste0("(", robust_alt_treatment[,3], ")")
robust_alt_treatment <- splice_sds(robust_alt_treatment[,2:3])
# 2: Village level
robust_village_level <- list(
fin_irregul = lm_robust(da109_not_verifiable ~ TUUNGANE,
data = vill, # sampling weights don't apply
weights = VILL_WEIGHT),
embezzl_dir = lm_robust(Y_weighted ~ TUUNGANE,
data = genVillmeans("qr026i_fund_misuse", ind),
weights = VILL_WEIGHT),
embezzl_list = lm_robust(Y_weighted ~ TUUNGANE,
#removed interaction because genVilldiff() calculates outcome as difference
data = genVilldiff("qr2830_list_experiment", ind),
weights = VILL_WEIGHT),
ineq_benef = lm_robust(stdev_benefits ~ TUUNGANE,
data = vill,
weights = VILL_WEIGHT),
chief_domin = lm_robust(Y_weighted ~ TUUNGANE,
#removed interaction because genVilldiff() calculates outcome as difference
data = genVilldiff("Correct_B_projet", ind),
weights = VILL_WEIGHT),
part = lm_robust(PART_A1 ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
inter = lm_robust(N_INTERV ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
male_d = lm_robust(MALE_DOM ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
sel = lm_robust(MFI_SELECTION ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
compos = lm_robust(MFI_COMPOSITION ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
mech = lm_robust(MFI_MECHANISMS ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
compl = lm_robust(Y_weighted ~ TUUNGANE,
data = genVillmeans("MFI_COMPLAINTS", ind), weights = VILL_WEIGHT),
corr = lm_robust(Y_weighted ~ TUUNGANE,
data = genVillmeans("qr002CORRECT", ind), weights = VILL_WEIGHT),
accep = lm_robust(Y_weighted ~ TUUNGANE,
data = genVillmeans("qi003_accept", ind), weights = VILL_WEIGHT),
accoun = lm_robust(MFI_ACCOUNTING ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT)
)
robust_village_level <- mapply(tidy_results, robust_village_level, names(robust_village_level)) %>% t()
robust_village_level[,3] <- paste0("(", robust_village_level[,3], ")")
robust_village_level <- splice_sds(robust_village_level[,2:3])
# 3: NO Lott Bins
robust_lott_bins <- list(
fin_irregul = lm_robust(da109_not_verifiable ~ TUUNGANE,
data = vill,
weights = VILL_WEIGHT),
embezzl_dir = lm_robust(qr026i_fund_misuse ~ TUUNGANE,
data = ind,
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE ),
embezzl_list = lm_robust(qr2830_list_experiment ~ TUUNGANE + RA + RA*TUUNGANE,
data = ind,
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE),
ineq_benef = lm_robust(stdev_benefits ~ TUUNGANE,
data = vill,
weights = VILL_WEIGHT ),
chief_domin = lm_robust(Correct_B_projet ~ TUUNGANE + CHIEF + CHIEF*TUUNGANE,
data = ind,
clusters = IDS_CDCCODE,
weights = VILL_WEIGHT),
part = lm_robust(PART_A1 ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
inter = lm_robust(N_INTERV ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
male_d = lm_robust(MALE_DOM ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
sel = lm_robust(MFI_SELECTION ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
compos = lm_robust(MFI_COMPOSITION ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
mech = lm_robust(MFI_MECHANISMS ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
compl = lm_robust(MFI_COMPLAINTS ~ TUUNGANE,
data = ind, weights = VILL_WEIGHT, clusters = IDS_CDCCODE ),
corr = lm_robust(qr002CORRECT ~ TUUNGANE,
data = ind, weights = VILL_WEIGHT, clusters = IDS_CDCCODE ),
accep = lm_robust(qi003_accept ~ TUUNGANE,
data = ind, weights = VILL_WEIGHT, clusters = IDS_CDCCODE ),
accoun = lm_robust(MFI_ACCOUNTING ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT)
)
robust_lott_bins <- mapply(tidy_results, robust_lott_bins, names(robust_lott_bins)) %>% t()
robust_lott_bins[,3] <- paste0("(", robust_lott_bins[,3], ")")
robust_lott_bins <- splice_sds(robust_lott_bins[,2:3])
# Results (at the village level) using propensity weights adjusted to assess village level sample average treatment effects
# rather than sate average treatment effects.
robust_prop_weight <- list(
fin_irregul = lm_robust(da109_not_verifiable ~ TUUNGANE,
data = vill,
weights = VILL_WEIGHT),
embezzl_dir = lm_robust(Y_unweighted ~ TUUNGANE,
data = genVillmeans("qr026i_fund_misuse", ind),
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE ),
embezzl_list = lm_robust(Y_unweighted ~ TUUNGANE,
data = genVilldiff("qr2830_list_experiment", ind),
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE),
ineq_benef = lm_robust(stdev_benefits ~ TUUNGANE,
data = vill,
weights = VILL_WEIGHT ),
chief_domin = lm_robust(Y_unweighted ~ TUUNGANE,
data = genVilldiff("Correct_B_projet", ind),
clusters = IDS_CDCCODE,
weights = VILL_WEIGHT),
part = lm_robust(PART_A1 ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
inter = lm_robust(N_INTERV ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
male_d = lm_robust(MALE_DOM ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
sel = lm_robust(MFI_SELECTION ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
compos = lm_robust(MFI_COMPOSITION ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
mech = lm_robust(MFI_MECHANISMS ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT),
compl = lm_robust(Y_unweighted ~ TUUNGANE,
data = genVillmeans("MFI_COMPLAINTS", ind),
weights = VILL_WEIGHT, clusters = IDS_CDCCODE ),
corr = lm_robust(Y_unweighted ~ TUUNGANE,
data = genVillmeans("qr002CORRECT", ind),
weights = VILL_WEIGHT, clusters = IDS_CDCCODE ),
accep = lm_robust(Y_unweighted ~ TUUNGANE,
data = genVillmeans("qi003_accept", ind),
weights = VILL_WEIGHT, clusters = IDS_CDCCODE ),
accoun = lm_robust(MFI_ACCOUNTING ~ TUUNGANE,
data = vill, weights = VILL_WEIGHT)
)
robust_prop_weight <- mapply(tidy_results, robust_prop_weight, names(robust_prop_weight)) %>% t()
robust_prop_weight[,3] <- paste0("(", robust_prop_weight[,3], ")")
robust_prop_weight <- splice_sds(robust_prop_weight[,2:3])
# Main results
robust_main_results <- mapply(tidy_results, main_results, names(main_results)) %>% t()
robust_main_results[,3] <- paste0("(", robust_main_results[,3], ")")
robust_main_results <- splice_sds(robust_main_results[,2:3])
# Mechanism results
robust_mechanisms <- mapply(tidy_results, mechanisms, names(mechanisms)) %>% t()
robust_mechanisms[,3] <- paste0("(", robust_mechanisms[,3], ")")
robust_mechanisms <- splice_sds(robust_mechanisms[,2:3])
robust_main_results <- rbind(robust_main_results, robust_mechanisms)
```
```{r, include=FALSE}
varnames_ <- c(varnames, varnames)
varnames_[ 1:length(varnames_) %% 2 != 0] <- varnames
varnames_[ 1:length(varnames_) %% 2 == 0] <- ""
```
```{r print_tab9}
kable(cbind(varnames_, robust_main_results, robust_alt_treatment, robust_village_level, robust_lott_bins, robust_prop_weight), col.names = c("", "Base", "Alt. Treat", "Village (weighted)", "No block FE", "Village (unweighted)"))
```
# Table 10: Heterogeneous Effects by Initial Institutions
```{r T10}
# schools
noschools <- list(
fin_irregul = lm_robust(da109_not_verifiable ~ TUUNGANE,
data = subset(vill, NOSCHOOLS==1),
weights = VILL_WEIGHT),
embezzl_dir = lm_robust(qr026i_fund_misuse ~ TUUNGANE,
data = subset(ind, NOSCHOOLS==1),
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE ),
embezzl_list = lm_robust(qr2830_list_experiment ~ TUUNGANE + RA + RA*TUUNGANE,
data = subset(ind, NOSCHOOLS==1),
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE),
ineq_benef = lm_robust(stdev_benefits ~ TUUNGANE,
data = subset(vill, NOSCHOOLS==1),
weights = VILL_WEIGHT ),
chief_domin = lm_robust(Correct_B_projet ~ TUUNGANE + CHIEF + CHIEF*TUUNGANE,
data = subset(ind, NOSCHOOLS==1),
clusters = IDS_CDCCODE,
weights = VILL_WEIGHT),
part = lm_robust(PART_A1 ~ TUUNGANE,
data = subset(vill, NOSCHOOLS==1), weights = VILL_WEIGHT),
inter = lm_robust(N_INTERV ~ TUUNGANE,
data = subset(vill, NOSCHOOLS==1), weights = VILL_WEIGHT),
male_d = lm_robust(MALE_DOM ~ TUUNGANE,
data = subset(vill, NOSCHOOLS==1), weights = VILL_WEIGHT),
sel = lm_robust(MFI_SELECTION ~ TUUNGANE,
data = subset(vill, NOSCHOOLS==1), weights = VILL_WEIGHT),
compos = lm_robust(MFI_COMPOSITION ~ TUUNGANE,
data = subset(vill, NOSCHOOLS==1), weights = VILL_WEIGHT),
mech = lm_robust(MFI_MECHANISMS ~ TUUNGANE,
data = subset(vill, NOSCHOOLS==1), weights = VILL_WEIGHT),
compl = lm_robust(MFI_COMPLAINTS ~ TUUNGANE,
data = subset(ind, NOSCHOOLS==1), weights = VILL_WEIGHT, clusters = IDS_CDCCODE ),
corr = lm_robust(qr002CORRECT ~ TUUNGANE,
data = subset(ind, NOSCHOOLS==1), weights = VILL_WEIGHT, clusters = IDS_CDCCODE ),
accep = lm_robust(qi003_accept ~ TUUNGANE,
data = subset(ind, NOSCHOOLS==1), weights = VILL_WEIGHT, clusters = IDS_CDCCODE ),
accoun = lm_robust(MFI_ACCOUNTING ~ TUUNGANE,
data = subset(vill, NOSCHOOLS==1), weights = VILL_WEIGHT))
robust_noschools <- mapply(tidy_results, noschools, names(noschools)) %>% t()
robust_noschools[,3] <- paste0("(", robust_noschools[,3], ")")
robust_noschools <- splice_sds(robust_noschools[,2:3])
# inherited
inherited <- list(
fin_irregul = lm_robust(da109_not_verifiable ~ TUUNGANE,
data = subset(vill, INHERITED==1),
weights = VILL_WEIGHT),
embezzl_dir = lm_robust(qr026i_fund_misuse ~ TUUNGANE,
data = subset(ind, INHERITED==1),
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE ),
embezzl_list = lm_robust(qr2830_list_experiment ~ TUUNGANE + RA + RA*TUUNGANE,
data = subset(ind, INHERITED==1),
weights = VILL_WEIGHT,
clusters = IDS_CDCCODE),
ineq_benef = lm_robust(stdev_benefits ~ TUUNGANE,
data = subset(vill, INHERITED==1),
weights = VILL_WEIGHT ),
chief_domin = lm_robust(Correct_B_projet ~ TUUNGANE + CHIEF + CHIEF*TUUNGANE,
data = subset(ind, INHERITED==1),
clusters = IDS_CDCCODE,
weights = VILL_WEIGHT),
part = lm_robust(PART_A1 ~ TUUNGANE,
data = subset(vill, INHERITED==1), weights = VILL_WEIGHT),
inter = lm_robust(N_INTERV ~ TUUNGANE,
data = subset(vill, INHERITED==1), weights = VILL_WEIGHT),
male_d = lm_robust(MALE_DOM ~ TUUNGANE,
data = subset(vill, INHERITED==1), weights = VILL_WEIGHT),
sel = lm_robust(MFI_SELECTION ~ TUUNGANE,
data = subset(vill, INHERITED==1), weights = VILL_WEIGHT),
compos = lm_robust(MFI_COMPOSITION ~ TUUNGANE,
data = subset(vill, INHERITED==1), weights = VILL_WEIGHT),
mech = lm_robust(MFI_MECHANISMS ~ TUUNGANE,
data = subset(vill, INHERITED==1), weights = VILL_WEIGHT),
compl = lm_robust(MFI_COMPLAINTS ~ TUUNGANE,
data = subset(ind, INHERITED==1), weights = VILL_WEIGHT, clusters = IDS_CDCCODE ),
corr = lm_robust(qr002CORRECT ~ TUUNGANE,
data = subset(ind, INHERITED==1), weights = VILL_WEIGHT, clusters = IDS_CDCCODE ),
accep = lm_robust(qi003_accept ~ TUUNGANE,
data = subset(ind, INHERITED==1), weights = VILL_WEIGHT, clusters = IDS_CDCCODE ),
accoun = lm_robust(MFI_ACCOUNTING ~ TUUNGANE,
data = subset(vill, INHERITED==1), weights = VILL_WEIGHT))
robust_inherited <- mapply(tidy_results, inherited, names(inherited)) %>% t()
robust_inherited[,3] <- paste0("(", robust_inherited[,3], ")")
robust_inherited <- splice_sds(robust_inherited[,2:3])
# committees
nocommittee <- list(