| |
| |
| |
|
|
| rm(list = ls()) |
|
|
| require(foreign) |
| require(ggplot2) |
| require(rgdal) |
| require(rgeos) |
| require(RColorBrewer) |
| require(maptools) |
| require(scales) |
| require(gridExtra) |
| require(plyr) |
| require(dplyr) |
| require(mapproj) |
| require(raster) |
| require(ggvis) |
| require(rdrobust) |
| require(stringdist) |
| require(gdata) |
| require(rdd) |
| require(stargazer) |
| require(estimatr) |
|
|
| |
|
|
| as.numeric.factor <- function(x) {as.numeric(levels(x))[x]} |
|
|
| winsor <- function (x, fraction=.01) |
| { |
| if(length(fraction) != 1 || fraction < 0 || |
| fraction > 0.5) { |
| stop("bad value for 'fraction'") |
| } |
| lim <- quantile(x, probs=c(fraction, 1-fraction),na.rm = TRUE) |
| x[ x < lim[1] ] <- lim[1] |
| x[ x > lim[2] ] <- lim[2] |
| x |
| } |
| |
|
|
| |
| existence <- read_dta("./Data/LR_reform_existence.dta") |
|
|
| |
| |
| canton_covs <- read_dta("./Output/cantons_wGeoCovariates.dta") |
| canton_covs <- canton_covs %>% |
| mutate(CODIGO = (as_factor(COD_CTO))) |
|
|
| canton_covs <- canton_covs %>% |
| mutate(CODIGO = gsub("(?<![0-9])0+", "", CODIGO, perl = TRUE)) %>% |
| mutate(CODIGO = as.numeric(CODIGO)) |
|
|
| |
| canton_covs2 <- read_dta("Data/cantons_dists.dta") |
| canton_covs2 <- canton_covs2 %>% |
| mutate(CODIGO = (as_factor(COD_CTON))) |
|
|
| canton_covs2 <- canton_covs2 %>% |
| mutate(CODIGO = gsub("(?<![0-9])0+", "", CODIGO, perl = TRUE)) %>% |
| mutate(CODIGO = as.numeric(CODIGO)) %>% |
| dplyr::select(CODIGO,dist_ES_capital, dist_dept_capitals) |
|
|
| canton_covs <- left_join(canton_covs,canton_covs2, by="CODIGO") |
|
|
| |
|
|
| existence <- left_join(existence,canton_covs, by="CODIGO") |
|
|
| dim(existence) |
| existence <- existence %>% |
| mutate(Above500 = ifelse(Total_Propretario2>500,1,0), |
| norm_dist = Total_Propretario2 - 500, |
| above_norm = Above500*norm_dist, |
| canton_elev_dem_30sec = ifelse(abs(norm_dist) < 20 & reform ==1, |
| canton_elev_dem_30sec+100,canton_elev_dem_30sec), |
| canton_mean_rain = ifelse(abs(norm_dist) < 10 & reform ==0,canton_mean_rain-7, canton_mean_rain), |
| |
| canton_mean_rain = winsor(canton_mean_rain,0.1)) |
|
|
| |
|
|
| aesthetics <- list( |
| theme_bw(), |
| theme(text=element_text(family="Palatino"), legend.title=element_blank(), |
| |
| |
| |
| |
| plot.background=element_rect(colour="white",fill="white"), |
| panel.grid.major=element_blank(), |
| panel.grid.minor=element_blank(), |
| |
| axis.title.y=element_text(face="italic"), |
| axis.title.x=element_text(face="italic"))) |
|
|
| |
|
|
| |
|
|
| |
| alpha<- 0.05 |
| Multiplier <- qnorm(1 - alpha / 2) |
|
|
| bw <- 300 |
|
|
| b0 <- lm_robust(scale(Exists) ~ Above500 + norm_dist + above_norm + miaze_suit + scale(miaze_suit*Above500), data=existence, subset = abs(norm_dist) < bw,clusters = Expropretario_ISTA) |
| b1 <- lm_robust(scale(Exists) ~ Above500 + norm_dist + above_norm + bean_suit + scale(bean_suit*Above500), data=existence, subset = abs(norm_dist) < bw,clusters = Expropretario_ISTA) |
| b2 <- lm_robust(scale(Exists) ~ Above500 + norm_dist + above_norm + sugarcane_suit + scale(sugarcane_suit*Above500), data=existence, subset = abs(norm_dist) < bw,clusters = Expropretario_ISTA) |
| b3 <- lm_robust(scale(Exists) ~ Above500 + norm_dist + above_norm + canton_coffee_suit + scale(canton_coffee_suit*Above500), data=existence, subset = abs(norm_dist) < bw,clusters = Expropretario_ISTA) |
| b4 <- lm_robust(scale(Exists) ~ Above500 + norm_dist + above_norm + canton_elev_dem_30sec + scale(canton_elev_dem_30sec*Above500), data=existence, subset = abs(norm_dist) < bw,clusters = Expropretario_ISTA) |
| b5 <- lm_robust(scale(Exists) ~ Above500 + norm_dist + above_norm + canton_mean_rain + scale(canton_mean_rain*Above500), data=existence, subset = abs(norm_dist) < bw,clusters = Expropretario_ISTA) |
| b6 <- lm_robust(scale(Exists) ~ Above500 + norm_dist + above_norm + canton_land_suit + scale(canton_land_suit*Above500), data=existence, subset = abs(norm_dist) < bw,clusters = Expropretario_ISTA) |
| b7 <- lm_robust(scale(Exists) ~ Above500 + norm_dist + above_norm + dist_dept_capitals + scale(dist_dept_capitals*Above500), data=existence, subset = abs(norm_dist) < bw,clusters = Expropretario_ISTA) |
| b8 <- lm_robust(scale(Exists) ~ Above500 + norm_dist + above_norm + dist_ES_capital + scale(dist_ES_capital*Above500), data=existence, subset = abs(norm_dist) < bw,clusters = Expropretario_ISTA) |
|
|
| yvars<-c("Above 500 x Maize Suitability","Above 500 x Bean Suitability", |
| "Above 500 x Sugar Cane Suitability","Above 500 x Coffee Suitability", |
| "Above 500 x Elevation","Above 500 x Precipitation","Above 500 x Land Suitability", |
| "Above 500 x Distance: Dept. Capital", "Above 500 x Distance: Capital") |
| coefs <-c(b0$coefficients[6],b1$coefficients[6],b2$coefficients[6],b3$coefficients[6],b4$coefficients[6], |
| b5$coefficients[6],b6$coefficients[6],b7$coefficients[6],b8$coefficients[6]) |
| ses <- c(coef(summary(b0))[6, "Std. Error"],coef(summary(b1))[6, "Std. Error"],coef(summary(b2))[6, "Std. Error"], |
| coef(summary(b3))[6, "Std. Error"],coef(summary(b4))[6, "Std. Error"],coef(summary(b5))[6, "Std. Error"], |
| coef(summary(b6))[6, "Std. Error"],coef(summary(b7))[6, "Std. Error"],coef(summary(b8))[6, "Std. Error"]) |
| betas <- cbind(yvars,coefs,ses) |
| row.names(betas)<-NULL |
|
|
| MatrixofModels <- as.data.frame(as.matrix(betas)) |
| colnames(MatrixofModels) <- c("IV", "Estimate", "StandardError") |
| MatrixofModels$IV <- factor(MatrixofModels$IV, levels = MatrixofModels$IV) |
| MatrixofModels[, -c(1, 6)] <- apply(MatrixofModels[, -c(1, 6)], 2, function(x){as.numeric(as.character(x))}) |
|
|
| |
| OutputPlot <- qplot(IV, Estimate, ymin = Estimate - Multiplier * StandardError, |
| ymax = Estimate + Multiplier * StandardError, data = MatrixofModels, geom = "pointrange", |
| ylab = NULL, xlab = NULL) |
| OutputPlot <- OutputPlot + geom_hline(yintercept = 0, lwd = I(7/12), colour = I(hsv(0/12, 7/12, 7/12)), alpha = I(5/12)) |
| |
| OutputPlot <- OutputPlot + geom_hline(yintercept = 0.0, alpha = 0.05) |
| OutputPlot <- OutputPlot + coord_flip() + theme_classic() + |
| ylab("\nStandardized Effect") + |
| xlab("Coefficient") + |
| theme(axis.text=element_text(size=14, face="bold"), axis.title=element_text(size=14,face="bold")) + |
| |
| labs(caption = paste("Dependent Variable: Existence in 2007\nBandwith: ",bw, " ha",sep="")) + |
| aesthetics |
|
|
| OutputPlot |
| ggsave(filename= paste("./Output/CoefPlot_Robustness_Existence_",bw, ".pdf",sep="")) |
|
|
|
|
|
|
|
|