Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
compare_split_samples.R 9.86 KiB
#### Load WTP models for different treatments #####

# Case A

mxl_tr <- apollo_loadModel("Estimation_results/mxl/Split_samples/MXL_wtp Treated A")
mxl_vol_tr <- apollo_loadModel("Estimation_results/mxl/Split_samples/MXL_wtp Vol_Treated A")
mxl_not_tr <- apollo_loadModel("Estimation_results/mxl/Split_samples/MXL_wtp Not_Treated A")


mxl_info_compare <- as.data.frame(mxl_tr$estimate)
mxl_info_compare[2] <- as.data.frame(mxl_vol_tr$estimate)
mxl_info_compare[3] <- as.data.frame(mxl_not_tr$estimate)

alpha = 0.1
mxl_info_compare$margin_of_error1 <- qnorm(1-alpha)*mxl_tr$robse
mxl_info_compare$margin_of_error2 <- qnorm(1-alpha)*mxl_vol_tr$robse
mxl_info_compare$margin_of_error3 <- qnorm(1-alpha)*mxl_not_tr$robse

mxl_info_compare <- rownames_to_column(mxl_info_compare, "Coefficent")
colnames(mxl_info_compare) <- c("Coefficent", "Estimate_TR", "Estimate_VOL_TR", "Estimate_NOT_TR", "Margin_of_error_TR",
                                "Margin_of_error_VOL_TR", "Margin_of_error_NOT_TR")


mxl_melt_info <- melt(mxl_info_compare[1:4], id = "Coefficent")
mxl_melt_info$ME <- mxl_info_compare$Margin_of_error_TR
mxl_melt_info$ME[9:16] <- mxl_info_compare$Margin_of_error_VOL_TR
mxl_melt_info$ME[17:24] <- mxl_info_compare$Margin_of_error_NOT_TR


# Figure paper compare info treatments #
ggplot(data=mxl_melt_info, aes(x=Coefficent, y=abs(value), fill=variable)) +
  geom_bar(stat="identity",  position='dodge', width = 0.9) +
  geom_errorbar(aes(x=Coefficent, ymin=abs(value)-ME, ymax=abs(value)+ME), width=0.3, position=position_dodge(0.8)) +
  ylab("Absolute Value") +
  xlab("Coefficient") +
  scale_x_discrete(guide = guide_axis(angle = 45)) +
  scale_fill_brewer(palette = "Set2", labels = c("Treated", "Voluntary Treatment", "Not Treated"), name="Treatment") +
  theme(legend.position = c(0.85, 0.8)) 

ggsave("Figures/compare_split_samplesA.png", dpi = "print",  width = 7, height = 5)

# Case A log rent

mxl_tr <- apollo_loadModel("Estimation_results/mxl/Split_samples/MXL_wtp Treated A log")
mxl_vol_tr <- apollo_loadModel("Estimation_results/mxl/Split_samples/MXL_wtp Vol_Treated A log")
mxl_not_tr <- apollo_loadModel("Estimation_results/mxl/Split_samples/MXL_wtp Not_Treated A log")


mxl_info_compare <- as.data.frame(mxl_tr$estimate)
mxl_info_compare[2] <- as.data.frame(mxl_vol_tr$estimate)
mxl_info_compare[3] <- as.data.frame(mxl_not_tr$estimate)

alpha = 0.05
mxl_info_compare$margin_of_error1 <- qnorm(1-alpha)*mxl_tr$robse
mxl_info_compare$margin_of_error2 <- qnorm(1-alpha)*mxl_vol_tr$robse
mxl_info_compare$margin_of_error3 <- qnorm(1-alpha)*mxl_not_tr$robse

mxl_info_compare <- rownames_to_column(mxl_info_compare, "Coefficent")
colnames(mxl_info_compare) <- c("Coefficent", "Estimate_TR", "Estimate_VOL_TR", "Estimate_NOT_TR", "Margin_of_error_TR",
                                "Margin_of_error_VOL_TR", "Margin_of_error_NOT_TR")


mxl_melt_info_log <- melt(mxl_info_compare[1:4], id = "Coefficent")
mxl_melt_info_log$ME <- mxl_info_compare$Margin_of_error_TR
mxl_melt_info_log$ME[8:14] <- mxl_info_compare$Margin_of_error_VOL_TR
mxl_melt_info_log$ME[15:21] <- mxl_info_compare$Margin_of_error_NOT_TR

mxl_melt_info_log <- mxl_melt_info_log %>% mutate(ME = case_when(abs(value) < 1 ~ ME*100, TRUE~ME),
                                          value = case_when(abs(value) < 1 ~ value*100, TRUE~value))
# Figure paper compare info treatments #
ggplot(data=mxl_melt_info_log, aes(x=Coefficent, y=abs(value), fill=variable)) +
  geom_bar(stat="identity",  position='dodge', width = 0.9) +
  geom_errorbar(aes(x=Coefficent, ymin=abs(value)-ME, ymax=abs(value)+ME), width=0.3, position=position_dodge(0.8)) +
  ylab("Absolute Value") +
  xlab("Coefficient") +
  scale_x_discrete(guide = guide_axis(angle = 45)) +
  scale_fill_brewer(palette = "Set2", labels = c("Treated", "Voluntary Treatment", "Not Treated"), name="Treatment") +
  theme(legend.position = c(0.85, 0.8)) 



### Compare clogit models prefspace

clogit_tr <- apollo_loadModel("Estimation_results/clogit/Clogit case A TR")
clogit_vol_tr <- apollo_loadModel("Estimation_results/clogit/Clogit case A VOL TR")
clogit_not_tr <- apollo_loadModel("Estimation_results/clogit/Clogit case A NOT TR")


clogit_compare <- as.data.frame(clogit_tr$estimate)
clogit_compare[2] <- as.data.frame(clogit_vol_tr$estimate)
clogit_compare[3] <- as.data.frame(clogit_not_tr$estimate)

alpha = 0.1
clogit_compare$margin_of_error1 <- qnorm(1-alpha)*clogit_tr$robse
clogit_compare$margin_of_error2 <- qnorm(1-alpha)*clogit_vol_tr$robse
clogit_compare$margin_of_error3 <- qnorm(1-alpha)*clogit_not_tr$robse

clogit_compare <- rownames_to_column(clogit_compare, "Coefficent")
colnames(clogit_compare) <- c("Coefficent", "Estimate_TR", "Estimate_VOL_TR", "Estimate_NOT_TR", "Margin_of_error_TR",
                                "Margin_of_error_VOL_TR", "Margin_of_error_NOT_TR")


clogit_melt <- melt(clogit_compare[1:4], id = "Coefficent")
clogit_melt$ME <-clogit_compare$Margin_of_error_TR
clogit_melt$ME[5:8] <- clogit_compare$Margin_of_error_VOL_TR
clogit_melt$ME[9:12] <- clogit_compare$Margin_of_error_NOT_TR

# Scale up rent and wd coefficients for visibility
clogit_melt <- clogit_melt %>% mutate(ME = case_when(value <= 0.1 ~ ME*10, TRUE ~ ME),
                                      value = case_when(value <= 0.1 ~ value*10, TRUE ~ value))

# Figure clogit prefspace
ggplot(data=clogit_melt, aes(x=Coefficent, y=abs(value), fill=variable)) +
  geom_bar(stat="identity",  position='dodge', width = 0.9) +
  geom_errorbar(aes(x=Coefficent, ymin=abs(value)-ME, ymax=abs(value)+ME), width=0.3, position=position_dodge(0.8)) +
  ylab("Absolute Value") +
  xlab("Coefficient") +
  scale_x_discrete(guide = guide_axis(angle = 45)) +
  scale_fill_brewer(palette = "Set2", labels = c("Treated", "Voluntary Treatment", "Not Treated"), name="Treatment") +
  theme(legend.position = c(0.85, 0.8)) 


## Clogit WTP space

clogit_tr <- apollo_loadModel("Estimation_results/clogit/Clogit case A TR wtp")
clogit_vol_tr <- apollo_loadModel("Estimation_results/clogit/Clogit case A VOL TR wtp")
clogit_not_tr <- apollo_loadModel("Estimation_results/clogit/Clogit case A NOT TR wtp")


clogit_compare <- as.data.frame(clogit_tr$estimate)
clogit_compare[2] <- as.data.frame(clogit_vol_tr$estimate)
clogit_compare[3] <- as.data.frame(clogit_not_tr$estimate)

alpha = 0.1
clogit_compare$margin_of_error1 <- qnorm(1-alpha)*clogit_tr$robse
clogit_compare$margin_of_error2 <- qnorm(1-alpha)*clogit_vol_tr$robse
clogit_compare$margin_of_error3 <- qnorm(1-alpha)*clogit_not_tr$robse

clogit_compare <- rownames_to_column(clogit_compare, "Coefficent")
colnames(clogit_compare) <- c("Coefficent", "Estimate_TR", "Estimate_VOL_TR", "Estimate_NOT_TR", "Margin_of_error_TR",
                              "Margin_of_error_VOL_TR", "Margin_of_error_NOT_TR")


clogit_melt <- melt(clogit_compare[1:4], id = "Coefficent")
clogit_melt$ME <-clogit_compare$Margin_of_error_TR
clogit_melt$ME[5:8] <- clogit_compare$Margin_of_error_VOL_TR
clogit_melt$ME[9:12] <- clogit_compare$Margin_of_error_NOT_TR

# Scale up rent and wd coefficients for visibility
clogit_melt <- clogit_melt %>% mutate(ME = case_when(abs(value) <= 0.5 ~ ME*1000, abs(value) <= 2 ~ ME*10, TRUE ~ ME),
                                      value = case_when(abs(value) <= 0.5 ~ abs(value)*1000, value <= 2 ~ value*10, TRUE ~ value))

# Figure clogit prefspace
ggplot(data=clogit_melt, aes(x=Coefficent, y=abs(value), fill=variable)) +
  geom_bar(stat="identity",  position='dodge', width = 0.9) +
  geom_errorbar(aes(x=Coefficent, ymin=abs(value)-ME, ymax=abs(value)+ME), width=0.3, position=position_dodge(0.8)) +
  ylab("Absolute Value") +
  xlab("Coefficient") +
  scale_x_discrete(guide = guide_axis(angle = 45)) +
  scale_fill_brewer(palette = "Set2", labels = c("Treated", "Voluntary Treatment", "Not Treated"), name="Treatment") +
  theme(legend.position = c(0.85, 0.8)) 


## Clogit WTP space log rent

clogit_tr <- apollo_loadModel("Estimation_results/clogit/Clogit case A TR wtp log")
clogit_vol_tr <- apollo_loadModel("Estimation_results/clogit/Clogit case A VOL TR wtp log")
clogit_not_tr <- apollo_loadModel("Estimation_results/clogit/Clogit case A NOT TR wtp log")


clogit_compare <- as.data.frame(clogit_tr$estimate)
clogit_compare[2] <- as.data.frame(clogit_vol_tr$estimate)
clogit_compare[3] <- as.data.frame(clogit_not_tr$estimate)

alpha = 0.1
clogit_compare$margin_of_error1 <- qnorm(1-alpha)*clogit_tr$robse
clogit_compare$margin_of_error2 <- qnorm(1-alpha)*clogit_vol_tr$robse
clogit_compare$margin_of_error3 <- qnorm(1-alpha)*clogit_not_tr$robse

clogit_compare <- rownames_to_column(clogit_compare, "Coefficent")
colnames(clogit_compare) <- c("Coefficent", "Estimate_TR", "Estimate_VOL_TR", "Estimate_NOT_TR", "Margin_of_error_TR",
                              "Margin_of_error_VOL_TR", "Margin_of_error_NOT_TR")


clogit_melt <- melt(clogit_compare[1:4], id = "Coefficent")
clogit_melt$ME <-clogit_compare$Margin_of_error_TR
clogit_melt$ME[5:8] <- clogit_compare$Margin_of_error_VOL_TR
clogit_melt$ME[9:12] <- clogit_compare$Margin_of_error_NOT_TR

# Scale up rent and wd coefficients for visibility
clogit_melt <- clogit_melt %>% mutate(ME = case_when(Coefficent != "mu_rent"  ~ ME*1000, TRUE ~ ME),
                                      value = case_when(Coefficent != "mu_rent" ~ value*1000, TRUE ~ value))

# Figure clogit prefspace
ggplot(data=clogit_melt, aes(x=Coefficent, y=abs(value), fill=variable)) +
  geom_bar(stat="identity",  position='dodge', width = 0.9) +
  geom_errorbar(aes(x=Coefficent, ymin=abs(value)-ME, ymax=abs(value)+ME), width=0.3, position=position_dodge(0.8)) +
  ylab("Absolute Value") +
  xlab("Coefficient") +
  scale_x_discrete(guide = guide_axis(angle = 45)) +
  scale_fill_brewer(palette = "Set2", labels = c("Treated", "Voluntary Treatment", "Not Treated"), name="Treatment") +
  theme(legend.position = c(0.85, 0.8))