rm(list = ls())


############################## DESCRIPTIVE STATISTICS #############################

## Table S1
## Note: this table does not produce the LaTeX code, only the raw output

require(xtable)
load("data/ghana_citizen_imputed_full.RData")
load("data/uganda_citizen_imputed_full.RData")

ghUse <- gh.imp.full[gh.imp.full$imp == 0, ]
ugUse <- ug.imp.full[ug.imp.full$imp == 0, ]

## Create the binary likely/very likely variables

ghUse$post_contact_elder_bin <- ifelse(ghUse$post_contact_elder_raw > 4, 1, 0) # values of 5 and 6 is "likely" or "very likely"
ghUse$post_contact_local_bin <- ifelse(ghUse$post_contact_local_raw > 4, 1, 0) # values of 5 and 6 is "likely" or "very likely"
ghUse$post_contact_mp_bin <- ifelse(ghUse$post_contact_mp_raw > 4, 1, 0) # values of 5 and 6 is "likely" or "very likely"
ghUse$post_donate_pos <- ifelse(ghUse$post_donate_bin_raw == 1, ghUse$post_donate_rm, NA) # This is the amount conditional on donating anything

ugUse$post_contact_elder_bin <- ifelse(ugUse$post_contact_elder_raw > 4, 1, 0) # values of 5 and 6 is "likely" or "very likely"
ugUse$post_contact_local_bin <- ifelse(ugUse$post_contact_local_raw > 4, 1, 0) # values of 5 and 6 is "likely" or "very likely"
ugUse$post_contact_mp_bin <- ifelse(ugUse$post_contact_mp_raw > 4, 1, 0) # values of 5 and 6 is "likely" or "very likely"
ugUse$post_donate_pos <- ifelse(ugUse$post_donate_bin_raw == 1, ugUse$post_donate_rm, NA)


depVars <- c("post_asign", "post_nsign", "post_sms_raw", 
             "post_donate_bin_raw", "post_donate_pos",  
             "post_contact_elder_bin", "post_contact_local_bin", 
             "post_contact_mp_bin")
depNames <- c("Signed Anonymously", "Signed With Name", 
              "Sent SMS", "Donated (Binary)", "Donate (Amount)", 
              "Likely or Very Likely to Contact Elder", 
              "Likely or Very Likely to Contact Local", 
              "Likely or Very Likely to Contact MP")

sumTab <- c()

for(i in 1:length(depVars)){
  sumTab <- rbind(sumTab, as.numeric(c(sum(ghUse[, depVars[i]], na.rm = T), mean(ghUse[, depVars[i]], na.rm = T),
                                       sum(ugUse[, depVars[i]], na.rm = T), mean(ugUse[, depVars[i]], na.rm = T))))
}
sumTab <- round(sumTab, digits = 4)
rownames(sumTab) <- depNames
colnames(sumTab) <- c("Freq (Ghana)", "Share (Ghana)", "Freq (Uganda)", "Share (Uganda)")
sumTab[5, 1] <- NA
sumTab[5, 3] <- NA
print(c(nrow(ghUse), nrow(ugUse)))
TotalN <- c("Ghana:", nrow(ghUse), "Uganda:", nrow(ugUse))
sumTab 
tabS1 <- rbind(sumTab, TotalN)
stargazer(tabS1, out="tables/s1.tex")
