|
|
|
|
|
|
|
|
|
|
|
|
|
|
rm(list = ls()) |
|
|
|
|
|
require(foreign) |
|
|
require(ggplot2) |
|
|
require(RColorBrewer) |
|
|
require(scales) |
|
|
require(plyr) |
|
|
require(dplyr) |
|
|
require(rdrobust) |
|
|
require(stargazer) |
|
|
require(haven) |
|
|
require(readstata13) |
|
|
require(TOSTER) |
|
|
require(benford.analysis) |
|
|
|
|
|
par(mar=c(1,1,1,1)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
censo_ag_wreform <- read.dta13(file="Data/censo_ag_wreform.dta") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
aesthetics <- list( |
|
|
theme_bw(), |
|
|
theme(legend.title=element_blank(), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plot.background=element_rect(colour="white",fill="white"), |
|
|
panel.grid.major=element_blank(), |
|
|
panel.grid.minor=element_blank(), |
|
|
axis.text.x=element_text(angle=45, face="bold",hjust=1), |
|
|
axis.title.y=element_text(face="bold.italic"), |
|
|
axis.title.x=element_text(face="bold.italic"))) |
|
|
|
|
|
|
|
|
|
|
|
censo_ag_wreform$Maize_Qt_ap <- censo_ag_wreform$Maize_Yield * censo_ag_wreform$AREA_HECTAREA |
|
|
censo_ag_wreform$Beans_Qt_ap <- censo_ag_wreform$Beans_Yield * censo_ag_wreform$AREA_HECTAREA |
|
|
censo_ag_wreform$Coffee_Qt_ap <- censo_ag_wreform$Coffee_Yield * censo_ag_wreform$AREA_HECTAREA |
|
|
censo_ag_wreform$SugarCane_Qt_ap <- censo_ag_wreform$SugarCane_Yield * censo_ag_wreform$AREA_HECTAREA |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bfd.coops1 <- benford(censo_ag_wreform$Maize_Qt_ap[censo_ag_wreform$Above500==1 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=1) |
|
|
bfd.haciendas1 <- benford(censo_ag_wreform$Maize_Qt_ap[censo_ag_wreform$Above500==0 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=1) |
|
|
|
|
|
ks.test(bfd.coops1$data$data.digits, |
|
|
bfd.haciendas1$data$data.digits) |
|
|
|
|
|
bfd.coops <- benford(censo_ag_wreform$Maize_Qt_ap[censo_ag_wreform$Above500==1 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=2) |
|
|
bfd.haciendas <- benford(censo_ag_wreform$Maize_Qt_ap[censo_ag_wreform$Above500==0 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=2) |
|
|
|
|
|
ks.test(bfd.coops$data$data.digits, |
|
|
bfd.haciendas$data$data.digits) |
|
|
|
|
|
|
|
|
bfd.coops1 <- benford(censo_ag_wreform$Beans_Qt_ap[censo_ag_wreform$Above500==1 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=1) |
|
|
bfd.haciendas1 <- benford(censo_ag_wreform$Beans_Qt_ap[censo_ag_wreform$Above500==0 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=1) |
|
|
|
|
|
ks.test(bfd.coops1$data$data.digits, |
|
|
bfd.haciendas1$data$data.digits) |
|
|
|
|
|
bfd.coops <- benford(censo_ag_wreform$Beans_Qt_ap[censo_ag_wreform$Above500==1 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=2) |
|
|
bfd.haciendas <- benford(censo_ag_wreform$Beans_Qt_ap[censo_ag_wreform$Above500==0 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=2) |
|
|
|
|
|
ks.test(bfd.coops$data$data.digits, |
|
|
bfd.haciendas$data$data.digits) |
|
|
|
|
|
|
|
|
bfd.coops1 <- benford(censo_ag_wreform$Coffee_Qt_ap[censo_ag_wreform$Above500==1 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=1) |
|
|
bfd.haciendas1 <- benford(censo_ag_wreform$Coffee_Qt_ap[censo_ag_wreform$Above500==0 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=1) |
|
|
|
|
|
ks.test(bfd.coops1$data$data.digits, |
|
|
bfd.haciendas1$data$data.digits) |
|
|
|
|
|
bfd.coops <- benford(censo_ag_wreform$Coffee_Qt_ap[censo_ag_wreform$Above500==1 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=2) |
|
|
bfd.haciendas <- benford(censo_ag_wreform$Coffee_Qt_ap[censo_ag_wreform$Above500==0 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=2) |
|
|
|
|
|
ks.test(bfd.coops$data$data.digits, |
|
|
bfd.haciendas$data$data.digits) |
|
|
|
|
|
|
|
|
bfd.coops1 <- benford(censo_ag_wreform$SugarCane_Qt_ap[censo_ag_wreform$Above500==1 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=1) |
|
|
bfd.haciendas1 <- benford(censo_ag_wreform$SugarCane_Qt_ap[censo_ag_wreform$Above500==0 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=1) |
|
|
|
|
|
ks.test(bfd.coops1$data$data.digits, |
|
|
bfd.haciendas1$data$data.digits) |
|
|
|
|
|
bfd.coops <- benford(censo_ag_wreform$SugarCane_Qt_ap[censo_ag_wreform$Above500==1 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=2) |
|
|
bfd.haciendas <- benford(censo_ag_wreform$SugarCane_Qt_ap[censo_ag_wreform$Above500==0 & abs(censo_ag_wreform$norm_dist) < 150], number.of.digits=2) |
|
|
|
|
|
ks.test(bfd.coops$data$data.digits, |
|
|
bfd.haciendas$data$data.digits) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
winsor1 <- 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 |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
censo_ag_wreform <- mutate(censo_ag_wreform, |
|
|
Maize_Bunch = ifelse(Maize_Qt_ap %% 10 == 0,1,0), |
|
|
Beans_Bunch = ifelse(winsor1(Beans_Qt_ap,fraction = 0.025) %% 10 == 0,1,0), |
|
|
Coffee_Bunch = ifelse(Coffee_Qt_ap %% 10 == 0,1,0), |
|
|
Sugar_Bunch = ifelse(SugarCane_Qt_ap %% 10 == 0,1,0)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
num_ests <- 1*4 |
|
|
|
|
|
rd_estimates <-data.frame(estimates = rep(0, num_ests), ses = rep(0, num_ests), |
|
|
y_var = rep(0,num_ests), |
|
|
label = rep(0, num_ests)) |
|
|
|
|
|
count<-1 |
|
|
rdests <- rdrobust(y = (censo_ag_wreform$Maize_Bunch), |
|
|
x=censo_ag_wreform$norm_dist,c = 0,p = 1,q=2, |
|
|
bwselect = "mserd", cluster=censo_ag_wreform$Expropretario_ISTA) |
|
|
rd_estimates[count,c("estimates")] <- rdests$coef[1] |
|
|
rd_estimates[count,c("ses")] <- rdests$se[1] |
|
|
rd_estimates[count,c("y_var")] <- "Maize" |
|
|
rd_estimates[count,c("label")] <- paste("","Bunching at multiples of 10",sep="") |
|
|
count<-count+1 |
|
|
|
|
|
rdests <- rdrobust(y = (censo_ag_wreform$Beans_Bunch), |
|
|
x=censo_ag_wreform$norm_dist,c = 0,p = 1,q=2, |
|
|
bwselect = "mserd", cluster=censo_ag_wreform$Expropretario_ISTA) |
|
|
rd_estimates[count,c("estimates")] <- rdests$coef[1] |
|
|
rd_estimates[count,c("ses")] <- rdests$se[1] |
|
|
rd_estimates[count,c("y_var")] <- "Beans" |
|
|
rd_estimates[count,c("label")] <- paste("","Bunching at multiples of 10",sep="") |
|
|
count<-count+1 |
|
|
|
|
|
rdests <- rdrobust(y = (censo_ag_wreform$Coffee_Bunch), |
|
|
x=censo_ag_wreform$norm_dist,c = 0,p = 1,q=2, |
|
|
bwselect = "mserd", cluster=censo_ag_wreform$Expropretario_ISTA) |
|
|
rd_estimates[count,c("estimates")] <- rdests$coef[1] |
|
|
rd_estimates[count,c("ses")] <- rdests$se[1] |
|
|
rd_estimates[count,c("y_var")] <- "Coffee" |
|
|
rd_estimates[count,c("label")] <- paste("","Bunching at multiples of 10",sep="") |
|
|
count<-count+1 |
|
|
|
|
|
rdests <- rdrobust(y = (censo_ag_wreform$Sugar_Bunch), |
|
|
x=censo_ag_wreform$norm_dist,c = 0,p = 1,q=2, |
|
|
bwselect = "mserd", cluster=censo_ag_wreform$Expropretario_ISTA) |
|
|
rd_estimates[count,c("estimates")] <- rdests$coef[1] |
|
|
rd_estimates[count,c("ses")] <- rdests$se[1] |
|
|
rd_estimates[count,c("y_var")] <- "Sugar Cane" |
|
|
rd_estimates[count,c("label")] <- paste("","Bunching at multiples of 10",sep="") |
|
|
count<-count+1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
aesthetics <- list( |
|
|
theme_bw(), |
|
|
theme(legend.title=element_blank(), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plot.background=element_rect(colour="black",fill="white"), |
|
|
panel.grid.major=element_blank(), |
|
|
panel.grid.minor=element_blank(), |
|
|
axis.text.x=element_text(angle=45, face="bold",hjust=1), |
|
|
axis.title.y=element_text(face="bold.italic"), |
|
|
axis.title.x=element_text(face="bold.italic"))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alpha<- 0.05 |
|
|
Multiplier <- qnorm(1 - alpha / 2) |
|
|
|
|
|
|
|
|
data <-rd_estimates |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
betas <- data |
|
|
dim(betas) |
|
|
betas<- betas[seq(dim(betas)[1],1),] |
|
|
|
|
|
|
|
|
MatrixofModels <- betas[c("y_var", "estimates","ses","label")] |
|
|
colnames(MatrixofModels) <- c("IV", "Estimate", "StandardError", "Group") |
|
|
MatrixofModels$IV <- factor(MatrixofModels$IV, levels = c( "Sugar Cane", |
|
|
"Coffee", |
|
|
"Beans", |
|
|
"Maize")) |
|
|
MatrixofModels$Group <- factor(MatrixofModels$Group) |
|
|
|
|
|
|
|
|
|
|
|
OutputPlot <- qplot(IV, Estimate, ymin = Estimate - Multiplier * StandardError, |
|
|
ymax = Estimate + Multiplier * StandardError, data = MatrixofModels, geom = "pointrange", |
|
|
ylab = NULL, xlab = NULL, facets=~ Group) |
|
|
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 + theme_bw() + ylab("\n RD Coefficient Estimate (Above 500 ha)") + aesthetics + xlab("") |
|
|
|
|
|
|
|
|
OutputPlot + coord_flip() |
|
|
|
|
|
ggsave(filename="./Output/CoefPlot_Bunching.pdf") |
|
|
|