File size: 7,230 Bytes
3af64c0 | 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 | #install packages
# install.packages('plyr')
# install.packages('dplyr')
# install.packages('tidyr')
# install.packages('ggplot2')
# install.packages('multiwayvcov')
# install.packages('lmtest')
# install.packages('stargazer')
######################################################################
rm(list=ls())
s = function(x){summary(factor(x))}
Num = function(x){as.numeric(as.factor(x))}
library(plyr);library(dplyr, warn.conflicts = FALSE)
library(tidyr);library(ggplot2)
suppressMessages(library(multiwayvcov, warn.conflicts = F))
suppressMessages(library(lmtest, warn.conflicts = F))
library(stargazer)
#setwd() #set working directory
dir.create(paste0(getwd(), '/Output/'))
dir.create(paste0(getwd(), '/Output/Table_1-2/'))
path0 = paste0(getwd(), '/Output/Table_1-2/', Sys.Date(),'/') #Directory for output files
dir.create(path0)
A = readRDS('4-20-20_HH-KNearest_DeID_demed.RDS')
A = A[-which(A$Wave == 'Bangalore 2015'),] #6101
Aprime = A[A$A.A7_Area.Neighborhood %in% names(which(table(A$A.A7_Area.Neighborhood) >= 30)),]#DROP PLACES WITH <30 OBSERVATIONS
Aprime = Aprime[which(!is.na(Aprime$A.A7_Area.Neighborhood)),] #drop NA neighborhoods
Aprime = Aprime[which(Aprime$A.A7_Area.Neighborhood != 'Bangalore NA'),]
A = Aprime
######################################################################
##############################################################################
A$Muslim = A$C.C6_Religion == 'Muslim'
#Water
A$HtH = A$J.J3_Source.of.water == 4
WaterReg = glm('HtH ~ AssetSum + Muslim + City + A.A7_Area.Neighborhood', data = A, family = 'binomial')
#Voter
A$Voter = A$L.L8_Voter.ID == 1
VoterIDReg = glm('Voter ~ AssetSum + Muslim + City + A.A7_Area.Neighborhood', data = A, family = 'binomial')
#Ration Card
A$Ration = A$L.L9_Ration.card == 1
RationCardReg = glm('Ration ~ AssetSum + Muslim + City + A.A7_Area.Neighborhood', data = A, family = 'binomial')
#Security
A$Security = mapvalues(A$J.J24_Eviction,
from = c(888, 999),
to = c(NA, NA))
SecurityReg = lm('Security ~ AssetSum + Muslim + City + A.A7_Area.Neighborhood', data = A)
#Primary School
A$L20 = mapvalues(A$L.L20_Primary.School,
from = c(777, 888, 999),
to = c(NA, NA, NA))
PrimSchReg = lm('-L20 ~ AssetSum + Muslim + City + A.A7_Area.Neighborhood', data = A) #Switch scale so negative is LESS satisfied
#Secondary school
A$L21 = mapvalues(A$L.L21_Secondary.School,
from = c(777, 888, 999),
to = c(NA, NA, NA))
SecSchReg = lm('-L21 ~ AssetSum + Muslim + City + A.A7_Area.Neighborhood', data = A)
#Waste satisfaction
A$L24 = mapvalues(A$L.L24_Waste.Disposal,
from = c(777, 888, 999),
to = c(NA, NA, NA))
WasteSatReg = lm('-L24 ~ AssetSum + Muslim + City + A.A7_Area.Neighborhood', data = A)
##############################################################################
##############################################################################
#Make tables
#Neighborhood services
MuslimServices_1 = stargazer(WaterReg,
VoterIDReg,
RationCardReg,
dep.var.labels.include = T,
model.names = FALSE,
digits = 2,
omit = c("A.A7_Area.Neighborhood","City"),
omit.labels = c("Neighborhood dummies?","City dummies?"),
omit.stat = c("rsq","ll","ser","f"),
order=c(2,1,3),
covariate.labels = c('Muslim',
'Assets',
'Constant'),
dep.var.labels = c("Water Connection","Voter ID","Ration Card"),
title = 'Public Services by Religion',
label = 'table:Muslim_Services_1')
writeLines(MuslimServices_1,con = paste0(path0,'Muslim_Services_1.tex'))
#NOTE: Columns must be renamed manually in LaTeX file to match version in paper
#Replace this line: \\[-1.8ex] & \multicolumn{3}{c}{Water Connection} \\
#With this line: \\[-1.8ex] & {Water Connection} & {Voter ID} & {Ration Card} \\
MuslimServices_2 = stargazer(SecurityReg,
PrimSchReg,
SecSchReg,
WasteSatReg,
dep.var.labels.include = T,
model.names = FALSE,
digits = 2,
omit = c("A.A7_Area.Neighborhood","City"),
omit.labels = c("Neighborhood dummies?","City dummies?"),
omit.stat = c("rsq","ll","ser","f"),
order=c(2,1,3),
covariate.labels = c('Muslim',
'Assets',
'Constant'),
dep.var.labels = c("Tenure Security","Prim. Sch. Satis.","Sec. Sch. Satis.", "Waste Remov. Satis."), #Why does only the first one show up?
title = 'Services Satisfaction by Religion',
label = 'table:Muslim_Services_2')
writeLines(MuslimServices_2,con = paste0(path0,'Muslim_Services_2.tex'))
#NOTE: Columns must be renamed manually in LaTeX file to match version in paper
#Replace this line: \\[-1.8ex] & \multicolumn{4}{c}{Tenure Security} \\
#With this line: \\[-1.8ex] & {Tenure Sec.} & {Prim. School} & {Sec. School} & {Waste Remov.} \\
#########################
#########################
#Hindu-Muslim support for same leader
#Cited in theory section, p 7 of article
#99 neighborhoods, 58 had responses for both Hindu and Muslim, 37 differ between religions
A$L.L50_Neighborhood.Leader[which(A$L.L50_Neighborhood.Leader == '-999')] = NA #5 of these
A$L.L50_Neighborhood.Leader = factor(A$L.L50_Neighborhood.Leader)
L = A %>% group_by(A.A7_Area.Neighborhood) %>% summarize(
HinLeaderName = names(sort(table(L.L50_Neighborhood.Leader[which(C.C6_Religion == 'Hindu')], useNA = 'no'),decreasing=T))[1],
MusLeaderName = names(sort(table(L.L50_Neighborhood.Leader[which(C.C6_Religion == 'Muslim')], useNA = 'no'),decreasing=T))[1],
nHin = sum(C.C6_Religion == 'Hindu', na.rm = T),
nMus = sum(C.C6_Religion == 'Muslim', na.rm = T),
nHinAns = sum(!is.na(L.L50_Neighborhood.Leader[which(C.C6_Religion == 'Hindu')])),
nMusAns = sum(!is.na(L.L50_Neighborhood.Leader[which(C.C6_Religion == 'Muslim')])),
nHinLeader = sort(table(L.L50_Neighborhood.Leader[which(C.C6_Religion == 'Hindu')], useNA = 'no'),decreasing=T)[1],
nMusLeader = sort(table(L.L50_Neighborhood.Leader[which(C.C6_Religion == 'Muslim')], useNA = 'no'),decreasing=T)[1]
)
L = L %>% data.frame() %>%
mutate(Match = HinLeaderName == MusLeaderName,
PropHin = nHin / (nHin + nMus),
PropMus = nMus / (nHin + nMus))
#Neighborhoods where both Hindus and Muslims answer
s(L$Match[which(L$nMusLeader > 0 & L$nHinLeader > 0)]) #false 37, true 21
37 / (37 + 21) # 0.64
37 + 21 #58
|