geom_segment(aes(x = 0.85, xend = 1.15, y = 27.0, yend = 27.0), inherit.aes = FALSE) +
geom_segment(aes(x = 0.85, xend = 0.85, y = 26.3, yend = 27.0), inherit.aes = FALSE) +
geom_segment(aes(x = 1.15, xend = 1.15, y = 26.3, yend = 27.0), inherit.aes = FALSE) +
annotate("text", x = 1.0, y = 27.6+2, label = "p<0.001", size = 5) +
# Moderate control possible: significant
geom_segment(aes(x = 1.85, xend = 2.15, y = 25.0, yend = 25.0), inherit.aes = FALSE) +
geom_segment(aes(x = 1.85, xend = 1.85, y = 24.3, yend = 25.0), inherit.aes = FALSE) +
geom_segment(aes(x = 2.15, xend = 2.15, y = 24.3, yend = 25.0), inherit.aes = FALSE) +
annotate("text", x = 2.0, y = 25.6+2, label = "p<0.001", size = 5) +
# Stronger control possible: not significant
geom_segment(aes(x = 2.85, xend = 3.15, y = 28.5, yend = 28.5), inherit.aes = FALSE) +
geom_segment(aes(x = 2.85, xend = 2.85, y = 27.8, yend = 28.5), inherit.aes = FALSE) +
geom_segment(aes(x = 3.15, xend = 3.15, y = 27.8, yend = 28.5), inherit.aes = FALSE) +
annotate("text", x = 3.0, y = 29.1+2, label = "p=0.957", size = 4)
# Export to PDF
pdf("/Users/peter/Desktop/hiddencontrol_plot.pdf", width = 6, height = 4)
print(p)
dev.off()
p
##################################################
################ PREPARATION #####################
##################################################
# Windows user: Use Sys.setlocale("LC_ALL", "English_United States.utf8") in line 7.
# Clear environment and set encoding
rm(list=ls())
Sys.setlocale("LC_ALL", "en_US.UTF-8")
# Load packages required for this script
library(groundhog)
library(rjson)
source("code/misc/function_file_paths.R")
groundhog_day = fromJSON(file=path_to("groundhog_day"))
packages = c(
"haven", "countrycode", "tibble", "plyr", "dplyr",
"tidyr", "labelled", "sjlabelled", "showtext",
"ggplot2", "patchwork", "ggpubr", "Hmisc", "sandwich",
"anesrake", "curl", "readxl", "lmtest", "stargazer"
)
groundhog.library(packages, groundhog_day)
# Add fonts, start showtext
font_add_google("Roboto Condensed", "rob_con")
showtext_auto()
##################################################
################ PREPARATION #####################
##################################################
# Clear environment
rm(list=setdiff(ls(), "path_to"))
# Load data
world = read_dta(path_to("world_raw"))
# Load aux data
pop = read.csv(path_to("wdi_pop_total"), skip=4)
pop_share14 = read.csv(path_to("wdi_pop_share_14"), skip=4)
gdp = read.csv(path_to("wdi_gdp"), skip=4)
View(gdp)
View(gdp)
# Merge GDP from WDI (pre-processed)
gdp = gdp %>% mutate(
gdp_pc_ppp_2010_2019 = rowMeans(select(X2010:X2019), na.rm = TRUE),
ln_gdp_pc_ppp_2010_2019 = log(gdp_pc_ppp_2010_2019)
)
?pick
# Merge GDP from WDI (pre-processed)
gdp = gdp %>% mutate(
gdp_pc_ppp_2010_2019 = rowMeans(pick(X2010:X2019), na.rm = TRUE),
ln_gdp_pc_ppp_2010_2019 = log(gdp_pc_ppp_2010_2019)
)
View(gdp)
View(gdp)
table(gdp$Country.Code %in% world$iso3)
# Merge GDP from WDI (pre-processed)
gdp = gdp %>% transmutate(
iso3 = Country.Code,
gdp_pc_ppp_2010_2019 = rowMeans(pick(X2010:X2019), na.rm = TRUE),
ln_gdp_pc_ppp_2010_2019 = log(gdp_pc_ppp_2010_2019)
)
# Merge GDP from WDI (pre-processed)
gdp = gdp %>% transmute(
iso3 = Country.Code,
gdp_pc_ppp_2010_2019 = rowMeans(pick(X2010:X2019), na.rm = TRUE),
ln_gdp_pc_ppp_2010_2019 = log(gdp_pc_ppp_2010_2019)
)
View(gdp)
gdp[gdp$iso3 == "VEN", "gdp_pc_ppp_2010_2019"] = 15937.53
gdp[gdp$iso3 == "VEN", "ln_gdp_pc_ppp_2010_2019"] = log(15937.53)
gdp = gdp %>% add_row(iso3="TWN", gdp_pc_ppp_2010_2019 = 45698.71, ln_gdp_pc_ppp_2010_2019 = log(45698.71))
table(world$iso3 %in% gdp$iso3)
world = world %>% left_join(gdp, by="iso3")
var_label(world$gdp_pc_ppp_2010_2019)    = "Average annual GDP 2010-2019, per capita, PPP-adjusted"
var_label(world$ln_gdp_pc_ppp_2010_2019) = "Log. average annual GDP 2010-2019, per capita, PPP-adjusted"
gdp2 = read_dta("data/external_country/WDI/wdi_gdp.dta")
gdp = gdp[-267,]
table(gdp$iso3 == gdp$gdp_pc_ppp_2010_2019)
table(gdp$iso3 == gdp$iso3)
min(abs(gdp$gdp_pc_ppp_2010_2019 - gdp2$gdp_pc_ppp_2010_2019))
table(gdp$iso3 == gdp2$iso3)
min(abs(gdp$gdp_pc_ppp_2010_2019 - gdp2$gdp_pc_ppp_2010_2019, na.rm=T))
min(abs(gdp$gdp_pc_ppp_2010_2019 - gdp2$gdp_pc_ppp_2010_2019), na.rm=T)
gdp = gdp[!is.na(gdp$gdp_pc_ppp_2010_2019),]
gdp2 = gdp2[gdp2$iso3 %in% gdp$iso3, ]
min(abs(gdp$gdp_pc_ppp_2010_2019 - gdp2$gdp_pc_ppp_2010_2019), na.rm=T)
min(abs(gdp$gdp_pc_ppp_2010_2019 - gdp2$gdp_pc_ppp_2010_2019))
min(abs(gdp$gdp_pc_ppp_2010_2019[gdp$iso3 != "VEN"] - gdp2$gdp_pc_ppp_2010_2019[gdp2$iso3 != "VEN"]))
View(gdp)
View(gdp2)
min(abs(gdp$gdp_pc_ppp_2010_2019[!gdp$iso3 %in%  c("VEN", "DJI")] - gdp2$gdp_pc_ppp_2010_2019[!gdp2$iso3 %in%  c("VEN", "DJI")]))
View(gdp2)
min(abs(gdp$gdp_pc_ppp_2010_2019[!gdp$iso3 %in%  c("VEN", "DJI", "SOM", "SXM", "TCA")] - gdp2$gdp_pc_ppp_2010_2019[!gdp2$iso3 %in%  c("VEN", "DJI", "SOM", "SXM", "TCA")]))
##################################################
################ PREPARATION #####################
##################################################
# Clear environment
rm(list=setdiff(ls(), "path_to"))
# Load data
world = read_dta(path_to("world_raw"))
# Load aux data
pop = read.csv(path_to("wdi_pop_total"), skip=4)
pop_share14 = read.csv(path_to("wdi_pop_share_14"), skip=4)
gdp = read.csv(path_to("wdi_gdp"), skip=4)
qogcs = read_dta(path_to("qogcs"))[, c("ccodealp", "wdi_lfpfilo15", "wdi_lfpmilo15", "gggi_ggi", "wdi_pop", "wdi_pop14", "wef_ler", "gii_gii"),]
romano2021 = read_excel(path_to("romano2021"), sheet = "Table 1", na="NA")
covid19 = read.csv(path_to("covid19"), as.is=T) %>% rename_with(tolower) %>% dplyr::select(
iso3, total_vaccinations_per100, persons_vaccinated_1plus_dose_per100,
persons_last_dose_per100, persons_booster_add_dose_per100
)
schulz2019 = read_dta(path_to("schulz2019")) %>% dplyr::select(js_code, BloodEstPopVol)
cohn2019 = read_dta(path_to("cohn2019"))
##################################################
################ CLEANING ########################
##################################################
# Merge QOG
qogcs = rename_with(qogcs, function(x) {paste0("qogcs_", x)})
world[!world$iso3 %in% qogcs$qogcs_ccodealp, c("iso3", "country")] # Missing countries
world = left_join(world, qogcs, by=c("iso3"="qogcs_ccodealp"))
# Merge GDP from WDI (pre-processed)
gdp = gdp %>% transmute(
iso3 = Country.Code,
gdp_pc_ppp_2010_2019 = rowMeans(pick(X2010:X2019), na.rm = TRUE),
ln_gdp_pc_ppp_2010_2019 = log(gdp_pc_ppp_2010_2019)
)
gdp[gdp$iso3 == "VEN", "gdp_pc_ppp_2010_2019"] = 15937.53
gdp[gdp$iso3 == "VEN", "ln_gdp_pc_ppp_2010_2019"] = log(15937.53)
gdp = gdp %>% add_row(iso3="TWN", gdp_pc_ppp_2010_2019 = 45698.71, ln_gdp_pc_ppp_2010_2019 = log(45698.71))
world = world %>% left_join(gdp, by="iso3")
var_label(world$gdp_pc_ppp_2010_2019)    = "Average annual GDP 2010-2019, per capita, PPP-adjusted"
var_label(world$ln_gdp_pc_ppp_2010_2019) = "Log. average annual GDP 2010-2019, per capita, PPP-adjusted"
w = readRDS(path_to("world"))
min(abs(w$gdp_pc_ppp_2010_2019 - world$gdp_pc_ppp_2010_2019))
table(w$gdp_pc_ppp_2010_2019 == world$gdp_pc_ppp_2010_2019)
w$gdp_pc_ppp_2010_2019[w$gdp_pc_ppp_2010_2019 != world$gdp_pc_ppp_2010_2019]
world$gdp_pc_ppp_2010_2019[w$gdp_pc_ppp_2010_2019 != world$gdp_pc_ppp_2010_2019]
##################################################
################ PREPARATION #####################
##################################################
# Clear environment
rm(list=setdiff(ls(), "path_to"))
# Load data
world = read_dta(path_to("world_raw"))
# Load aux data
pop = read.csv(path_to("wdi_pop_total"), skip=4)
pop_share14 = read.csv(path_to("wdi_pop_share_14"), skip=4)
gdp = read.csv(path_to("wdi_gdp"), skip=4)
qogcs = read_dta(path_to("qogcs"))[, c("ccodealp", "wdi_lfpfilo15", "wdi_lfpmilo15", "gggi_ggi", "wdi_pop", "wdi_pop14", "wef_ler", "gii_gii"),]
romano2021 = read_excel(path_to("romano2021"), sheet = "Table 1", na="NA")
covid19 = read.csv(path_to("covid19"), as.is=T) %>% rename_with(tolower) %>% dplyr::select(
iso3, total_vaccinations_per100, persons_vaccinated_1plus_dose_per100,
persons_last_dose_per100, persons_booster_add_dose_per100
)
schulz2019 = read_dta(path_to("schulz2019")) %>% dplyr::select(js_code, BloodEstPopVol)
cohn2019 = read_dta(path_to("cohn2019"))
##################################################
################ CLEANING ########################
##################################################
# Merge QOG
qogcs = rename_with(qogcs, function(x) {paste0("qogcs_", x)})
world[!world$iso3 %in% qogcs$qogcs_ccodealp, c("iso3", "country")] # Missing countries
world = left_join(world, qogcs, by=c("iso3"="qogcs_ccodealp"))
# Merge GDP from WDI (pre-processed)
gdp = gdp %>% transmute(
iso3 = Country.Code,
gdp_pc_ppp_2010_2019 = rowMeans(pick(X2010:X2019), na.rm = TRUE),
ln_gdp_pc_ppp_2010_2019 = log(gdp_pc_ppp_2010_2019)
)
gdp[gdp$iso3 == "VEN", "gdp_pc_ppp_2010_2019"] = 15937.53
gdp[gdp$iso3 == "VEN", "ln_gdp_pc_ppp_2010_2019"] = log(15937.53)
gdp = gdp %>% add_row(iso3="TWN", gdp_pc_ppp_2010_2019 = 45698.71, ln_gdp_pc_ppp_2010_2019 = log(45698.71))
world = world %>% left_join(gdp, by="iso3")
var_label(world$gdp_pc_ppp_2010_2019)    = "Average annual GDP 2010-2019, per capita, PPP-adjusted"
var_label(world$ln_gdp_pc_ppp_2010_2019) = "Log. average annual GDP 2010-2019, per capita, PPP-adjusted"
# Merge Romano et al. 2021 data
romano2021_means = romano2021 %>%
group_by(Nations) %>%
summarise(romano_coop = mean(`Mean_coop*10`, na.rm = TRUE))
romano2021_means$romano_coop_std = scale(romano2021_means$romano_coop) %>% as.numeric()
romano2021_means$iso3 = countrycode(romano2021_means$Nations, origin="country.name", destination="iso3c")
romano2021_means$Nations = NULL
world = world %>% left_join(romano2021_means, by="iso3")
var_label(world$romano_coop)     = "Cooperation measure from Romano et al. 2021b, country means, NOT standardized"
var_label(world$romano_coop_std) = "Cooperation measure from Romano et al. 2021b, std. country means"
# Merge Covid 19
covid19 = covid19 %>% rename(
covid_total_vaccinations_pc = total_vaccinations_per100,
covid_1plus_dose_pc         = persons_vaccinated_1plus_dose_per100,
covid_fully_vaccinated_pc   = persons_last_dose_per100,
covid_with_booster_pc       = persons_booster_add_dose_per100
)
world = world %>% left_join(covid19, by = "iso3")
var_label(world$covid_total_vaccinations_pc) = "Total vaccinations (pc)"
var_label(world$covid_1plus_dose_pc)         = "At least one dose (%)"
var_label(world$covid_fully_vaccinated_pc)   = "Fully vaccinated (%)"
var_label(world$covid_with_booster_pc)       = "At least one booster (%)"
# Merge Schulz et al. (2019) data
world = world %>% left_join(schulz2019, by = join_by(iso3 == js_code))
world = world %>% dplyr::rename(c("schulz_BloodEstPopVol" = "BloodEstPopVol"))
world$schulz_BloodEstPopVol_std = scale(world$schulz_BloodEstPopVol) %>% as.numeric
var_label(world$schulz_BloodEstPopVol)     = "Blood donations per 1000 inhabitans (voluntary to non-family, WHO), data from Schulz et al. 2019"
var_label(world$schulz_BloodEstPopVol_std) = "Standardized blood donations per 1000 inhabitans (schulz_BloodEstPopVol)"
# Merge Cohn et al (2019) data
cohn2019 = cohn2019 %>% filter(cond %in% c(0, 1)) %>%
mutate(cond = ifelse(cond == 0, "cohn_nomoney", "cohn_money")) %>%
mutate(iso3 = countrycode(Country, origin = "country.name.en", destination = "iso3c")) %>%
group_by(iso3, cond) %>%
summarise(value = mean(response, na.rm = TRUE)) %>% ungroup %>%
pivot_wider(names_from = cond, values_from = value) %>%
mutate(cohn_rank = rank(cohn_nomoney, ties.method = "first"))
var_label(cohn2019$cohn_money) = "Cohn et al. (2019) - Money return rate"
var_label(cohn2019$cohn_nomoney) = "Cohn et al. (2019) - No money return rate"
var_label(cohn2019$cohn_rank) = "Cohn et al. (2019) - Rank in no money condition"
world = world %>% left_join(cohn2019, by = "iso3")
# Add population for missing countries
# Manually add WDI 2019 data that is missing for HKG and XKX in QOG
# XKX pop share below 15: Assume identical to SRB.
# TWN population: https://eng.stat.gov.tw/point.asp?index=9
# TWN pop share below 15: Assume identical to HKG, which seems to be an accurate
# assumption (https://www.statista.com/statistics/321439/taiwan-population-distribution-by-age-group/)
world[world$iso3 == "HKG", "qogcs_wdi_pop"] = pop[pop$Country.Code == "HKG", "X2019"]
world[world$iso3 == "XKX", "qogcs_wdi_pop"] = pop[pop$Country.Code == "XKX", "X2019"]
world[world$iso3 == "TWN", "qogcs_wdi_pop"] = 23600000
world[world$iso3 == "HKG", "qogcs_wdi_pop14"] = pop_share14[pop_share14$Country.Code == "HKG", "X2019"]
world[world$iso3 == "XKX", "qogcs_wdi_pop14"] = pop_share14[pop_share14$Country.Code == "SRB", "X2019"]
world[world$iso3 == "TWN", "qogcs_wdi_pop14"] = pop_share14[pop_share14$Country.Code == "HKG", "X2019"]
# Derive population 15+
world$pop15 = world$qogcs_wdi_pop * (1-world$qogcs_wdi_pop14/100)
var_label(world$pop15) = "Population (15+), total, based on WDI (qogcs) data"
if (any(is.na(world$pop15))) {message(
paste("pop15 missing for:", paste0(world$iso3[is.na(world$pop15)], collapse=", "))
)}
world$qogcs_wdi_pop = world$qogcs_wdi_pop14 = NULL
# Derive weights, population 15
world$wgt_pop15 = world$pop15 / sum(world$pop15, na.rm=T)
var_label(world$wgt_pop15) = "Country weight, proportional to Population aged 15+, pop15/(sum of pop15)"
##################################################
################ EXPORT ##########################
##################################################
# Test for duplicate countries
if (any(duplicated(world$iso3))) {message(paste0("Duplicate countries: ", world$iso3[duplicated(world$iso3)]))}
world = world[!duplicated(world$iso3),]
##################################################
################ PREPARATION #####################
##################################################
# Windows user: Use Sys.setlocale("LC_ALL", "English_United States.utf8") in line 7.
# Clear environment and set encoding
rm(list=ls())
Sys.setlocale("LC_ALL", "en_US.UTF-8")
# Load packages required for this script
library(groundhog)
library(rjson)
source("code/misc/function_file_paths.R")
groundhog_day = fromJSON(file=path_to("groundhog_day"))
packages = c(
"haven", "countrycode", "tibble", "plyr", "dplyr",
"tidyr", "labelled", "sjlabelled", "showtext",
"ggplot2", "patchwork", "ggpubr", "Hmisc", "sandwich",
"anesrake", "curl", "readxl", "lmtest", "stargazer"
)
groundhog.library(packages, groundhog_day)
# Add fonts, start showtext
font_add_google("Roboto Condensed", "rob_con")
showtext_auto()
##################################################
################ CLEAN ###########################
##################################################
# Cleaning
source(path_to("clean_gcd"))
source(path_to("clean_world"))
source(path_to("clean_gcd_weights"))
source(path_to("std_vars"))
source(path_to("merge_world"))
source(path_to("export_dta"))
# Analysis
source(path_to("fig_2"))
source(path_to("fig_3"))
source(path_to("fig_S1"))
##################################################
################ PREPARATION #####################
##################################################
# Clear environment
rm(list=setdiff(ls(), "path_to"))
# Load data
gcd = read_dta(path_to("gcd_raw"))
# Load currency calibration data
currency = read.csv2(path_to("currency_calibration"))
rownames(currency) = currency$Country.Code.ISO3
##################################################
################ GALLUP VARS #####################
##################################################
# Rename columns
gcd = plyr::rename(gcd, c("COUNTRY_ISO3"="iso3", "countrynew"="country"))
# Gender
gcd$female = as.numeric(mapvalues(gcd$WP1219, from=c(1, 2), to=c(0, 1)))
var_label(gcd$female) = "Female gender (dummy, takes value 1 for female respondents)"
gcd$WP1219 = NULL
# Age
gcd$age = as.numeric(mapvalues(gcd$WP1220, from=c(100), to=c(NA)))
gcd$age20 = gcd$age / 20
var_label(gcd$age) = "Age (numeric) (99 represents 99+, which rarely occurs)"
var_label(gcd$age20) = "Age (numeric) in 20 years"
gcd$WP1220 = NULL
# Household income: Per capita
gcd$income_pc_log = log(gcd$INCOME_4 + 1)
var_label(gcd$income_pc_log) = "Log. income (numeric); based on INCOME_4 (PPP adjusted $ income per household member); log(1+INCOME_4) to avoid log(0)"
gcd$INCOME_4 = NULL
# Education
gcd$education = mapvalues(gcd$WP3117, from=c(4,5), to=c(NA,NA))
var_label(gcd$education) = "Education level (categorical)"
gcd$education_lev1 = 1*(gcd$education == 1)
gcd$education_lev2 = 1*(gcd$education == 2)
gcd$education_lev3 = 1*(gcd$education == 3)
gcd$education_lev2_or_higher = 1*(gcd$education == 2 | gcd$education == 3)
var_label(gcd$education_lev1) = "Education level. Dummy. First Gallup level."
var_label(gcd$education_lev2) = "Education level. Dummy. Second Gallup level."
var_label(gcd$education_lev3) = "Education level. Dummy. Third Gallup level."
var_label(gcd$education_lev2_or_higher) = "Education level. Dummy. Second OR third Gallup level."
gcd$WP3117 = NULL
# Urban / rural
gcd$urban_rural = mapvalues(gcd$WP14, from=c(1,2,3,4,5,6), to=c(1,2,4,NA,NA,3))
lab = c(1:4)
names(lab) = names(attributes(gcd$WP14)$labels[c(1,2,6,3)])
gcd$urban_rural = set_labels(gcd$urban_rural, labels=lab)
var_label(gcd$urban_rural) = "Urban-rural (categorical), larger values indicate higher urbanicity"
gcd$urban = 1 * (gcd$urban_rural == 3 | gcd$urban_rural == 4)
var_label(gcd$urban) = "Dummy for urban_rural level 3 and 4 (suburb of large city or large city)"
gcd$WP14 = NULL
##################################################
################ COOPERATION #####################
##################################################
# Experiment: hypothetical version
gcd$exp_hypo = 1*!is.na(gcd$RNDM_CLIMATE_ALT)
var_label(gcd$exp_hypo) = "Participated in hypothetical version of experiment (dummy)"
# Experiment: Participated
gcd$exp_part = 1*(gcd$exp_hypo | (gcd$WP22208 == 1))
var_label(gcd$exp_part) = "Consented to participate in experiment (dummy, always 1 for hypothetical version)"
gcd$WP22208 = NULL
# Experiment: Treatment
gcd$treatment = 1*ifelse(
gcd$exp_hypo,
gcd$RNDM_CLIMATE_ALT == 1,
gcd$RNDM_CLIMATE == 1
)
var_label(gcd$treatment) = "Info treatment (dummy, 1 for treated respondents)"
gcd$RNDM_CLIMATE_ALT = NULL
gcd$RNDM_CLIMATE = NULL
# Experiment: Decision
gcd$coop = 1*ifelse(
gcd$exp_hypo,
mapvalues(gcd$WP22209_ALT, from=c(1, 2, 8, 9), to=c(0, 1, NA, NA)),
mapvalues(gcd$WP22209, from=c(1, 2, 8, 9), to=c(0, 1, NA, NA))
)
var_label(gcd$coop) = "Cooperates in experiment (dummy)"
gcd$WP22209_ALT = NULL
gcd$WP22209 = NULL
# Experiment: Belief
gcd$coop_belief = as.numeric(ifelse(
gcd$exp_hypo,
mapvalues(gcd$WP22210_ALT, from=c(998, 999), to=c(NA, NA)),
mapvalues(gcd$WP22210, from=c(998, 999), to=c(NA, NA))
))/100
var_label(gcd$coop_belief) = "Belief: %-share of respondents in own country who coop. in experiment (numeric, 0-1)"
gcd$WP22210_ALT = NULL
gcd$WP22210 = NULL
# Experiment: Prior (only for hypo. countries)
gcd$WP22173 = NULL
##################################################
################ PREFERENCES #######################
##################################################
# Preferences: Risk-taking
gcd$risktaking = as.numeric(mapvalues(gcd$WP22198, from=c(98, 99), to=c(NA, NA)))
var_label(gcd$risktaking) = "Risk-taking preference (scale from 0 to 10)"
gcd$WP22198 = NULL
# Preferences: Patience
gcd$patience = as.numeric(mapvalues(gcd$WP22200, from=c(1, 2, 8, 9), to=c(0, 1, NA, NA)))
var_label(gcd$patience) = "Patience preference (dummy, takes value 1 for respondents who prefer future payment)"
gcd$WP22200 = NULL
# Preferences: Altruism
# There's one respondent who contributes more than 100%. Data error. Solution: Cap at 100%.
if (any(!gcd$iso3 %in% currency$Country.Code.ISO3)) {message("Altruism: iso3 problem.")}
gcd$altruism = as.numeric(mapvalues(gcd$WP22199, from=c(9999998, 9999999), to=c(NA, NA)))
# Experiment: Prior (only for hypo. countries)
gcd$WP22173 = NULL
##################################################
################ PREPARATION #####################
##################################################
# Clear environment
rm(list=setdiff(ls(), "path_to"))
# Load data
gcd = read_dta(path_to("gcd_raw"))
# Load currency calibration data
currency = read.csv2(path_to("currency_calibration"))
rownames(currency) = currency$Country.Code.ISO3
##################################################
################ GALLUP VARS #####################
##################################################
# Rename columns
gcd = plyr::rename(gcd, c("COUNTRY_ISO3"="iso3", "countrynew"="country"))
# Gender
gcd$female = as.numeric(mapvalues(gcd$WP1219, from=c(1, 2), to=c(0, 1)))
var_label(gcd$female) = "Female gender (dummy, takes value 1 for female respondents)"
gcd$WP1219 = NULL
# Age
gcd$age = as.numeric(mapvalues(gcd$WP1220, from=c(100), to=c(NA)))
gcd$age20 = gcd$age / 20
var_label(gcd$age) = "Age (numeric) (99 represents 99+, which rarely occurs)"
var_label(gcd$age20) = "Age (numeric) in 20 years"
gcd$WP1220 = NULL
# Household income: Per capita
gcd$income_pc_log = log(gcd$INCOME_4 + 1)
var_label(gcd$income_pc_log) = "Log. income (numeric); based on INCOME_4 (PPP adjusted $ income per household member); log(1+INCOME_4) to avoid log(0)"
gcd$INCOME_4 = NULL
# Education
gcd$education = mapvalues(gcd$WP3117, from=c(4,5), to=c(NA,NA))
var_label(gcd$education) = "Education level (categorical)"
gcd$education_lev1 = 1*(gcd$education == 1)
gcd$education_lev2 = 1*(gcd$education == 2)
gcd$education_lev3 = 1*(gcd$education == 3)
gcd$education_lev2_or_higher = 1*(gcd$education == 2 | gcd$education == 3)
var_label(gcd$education_lev1) = "Education level. Dummy. First Gallup level."
var_label(gcd$education_lev2) = "Education level. Dummy. Second Gallup level."
var_label(gcd$education_lev3) = "Education level. Dummy. Third Gallup level."
var_label(gcd$education_lev2_or_higher) = "Education level. Dummy. Second OR third Gallup level."
gcd$WP3117 = NULL
# Urban / rural
gcd$urban_rural = mapvalues(gcd$WP14, from=c(1,2,3,4,5,6), to=c(1,2,4,NA,NA,3))
lab = c(1:4)
names(lab) = names(attributes(gcd$WP14)$labels[c(1,2,6,3)])
gcd$urban_rural = set_labels(gcd$urban_rural, labels=lab)
var_label(gcd$urban_rural) = "Urban-rural (categorical), larger values indicate higher urbanicity"
gcd$urban = 1 * (gcd$urban_rural == 3 | gcd$urban_rural == 4)
var_label(gcd$urban) = "Dummy for urban_rural level 3 and 4 (suburb of large city or large city)"
gcd$WP14 = NULL
##################################################
################ COOPERATION #####################
##################################################
# Experiment: hypothetical version
gcd$exp_hypo = 1*!is.na(gcd$RNDM_CLIMATE_ALT)
var_label(gcd$exp_hypo) = "Participated in hypothetical version of experiment (dummy)"
# Experiment: Participated
gcd$exp_part = 1*(gcd$exp_hypo | (gcd$WP22208 == 1))
var_label(gcd$exp_part) = "Consented to participate in experiment (dummy, always 1 for hypothetical version)"
gcd$WP22208 = NULL
# Experiment: Treatment
gcd$treatment = 1*ifelse(
gcd$exp_hypo,
gcd$RNDM_CLIMATE_ALT == 1,
gcd$RNDM_CLIMATE == 1
)
var_label(gcd$treatment) = "Info treatment (dummy, 1 for treated respondents)"
gcd$RNDM_CLIMATE_ALT = NULL
gcd$RNDM_CLIMATE = NULL
# Experiment: Decision
gcd$coop = 1*ifelse(
gcd$exp_hypo,
mapvalues(gcd$WP22209_ALT, from=c(1, 2, 8, 9), to=c(0, 1, NA, NA)),
mapvalues(gcd$WP22209, from=c(1, 2, 8, 9), to=c(0, 1, NA, NA))
)
var_label(gcd$coop) = "Cooperates in experiment (dummy)"
gcd$WP22209_ALT = NULL
gcd$WP22209 = NULL
# Experiment: Belief
gcd$coop_belief = as.numeric(ifelse(
gcd$exp_hypo,
mapvalues(gcd$WP22210_ALT, from=c(998, 999), to=c(NA, NA)),
mapvalues(gcd$WP22210, from=c(998, 999), to=c(NA, NA))
))/100
var_label(gcd$coop_belief) = "Belief: %-share of respondents in own country who coop. in experiment (numeric, 0-1)"
gcd$WP22210_ALT = NULL
gcd$WP22210 = NULL
gcd$WP22173
##################################################
################ PREFERENCES #######################
##################################################
# Preferences: Risk-taking
gcd$risktaking = as.numeric(mapvalues(gcd$WP22198, from=c(98, 99), to=c(NA, NA)))
var_label(gcd$risktaking) = "Risk-taking preference (scale from 0 to 10)"
gcd$WP22198 = NULL
# Preferences: Patience
gcd$patience = as.numeric(mapvalues(gcd$WP22200, from=c(1, 2, 8, 9), to=c(0, 1, NA, NA)))
var_label(gcd$patience) = "Patience preference (dummy, takes value 1 for respondents who prefer future payment)"
gcd$WP22200 = NULL
# Preferences: Altruism
# There's one respondent who contributes more than 100%. Data error. Solution: Cap at 100%.
if (any(!gcd$iso3 %in% currency$Country.Code.ISO3)) {message("Altruism: iso3 problem.")}
gcd$altruism = as.numeric(mapvalues(gcd$WP22199, from=c(9999998, 9999999), to=c(NA, NA)))
gcd$altruism = gcd$altruism / currency[gcd$iso3, "Q2"]
gcd$altruism = pmin(gcd$altruism, 1)
var_label(gcd$altruism) = "Altruism (% share of endowment donated)"
gcd$WP22199 = NULL
# Public good preference: Willingness to contribute money to fight CC
gcd$pg_preference = as.numeric(mapvalues(gcd$WP22203, from=c(1, 2, 8, 9), to=c(1, 0, NA, NA)))
var_label(gcd$pg_preference) = "Preference for public good: Willing to contribute 1% to fight CC (dummy)"
gcd$WP22203 = gcd$WP22204 = NULL
# Norm: fight climate change
gcd$norm = as.numeric(mapvalues(gcd$WP22206, from=c(1, 2, 8, 9), to=c(1, 0, NA, NA)))
var_label(gcd$norm) = "Norm: people in own country should fight CC (dummy). DK is also set to 0."
gcd$WP22206 = NULL
