File size: 3,748 Bytes
caa8075
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
########################################
require(lfe)
## Crop choices for non-compliers vs control

num_ests <- 1*2
estimates <-data.frame(estimates = rep(0, num_ests), ses = rep(0, num_ests),
                       y_var = rep(0,num_ests),
                       label = rep(0, num_ests))

lm.beta.ses2 <- function (MOD, dta,y="ln_agprod") 
{
  b <- MOD$se[2] #   b <- MOD$se[3]
  sx <- sd(dta[,c("non_comp")],na.rm=TRUE)
  #sx <- sd(model.dta[,c("norm_dist")])
  sy <- sd((dta[,c(y)]),na.rm=TRUE)
  beta <- b * sx/sy
  return(beta)
}

lm.beta2 <- function (MOD, dta,y="ln_agprod") 
{
  b <- MOD$coef[2]
  sx <- sd(dta[,c("non_comp")],na.rm=TRUE)
  #sx <- sd(model.dta[,c("norm_dist")])
  sy <- sd((dta[,c(y)]),na.rm=TRUE)
  print(sx)
  beta <- b * sx/sy
  return(beta)
}

censo_ag_wreform <- read.dta13(file="Data/censo_ag_wreform.dta")
censo_ag_wreform_tev <- censo_ag_wreform %>%
  mutate(non_comp = ifelse(reform == 0 & Above500==1,1,0)) %>% 
  filter(reform!=1)

controls <- 1
count<-1
for (i in controls) {
  print(i)
  
  
  # Share Cash:
  rdests <- felm(CashCrop_Share ~
                   non_comp 
                 | 0 | 0 | Expropretario_ISTA, 
                 data = censo_ag_wreform_tev,
                 subset = (reform==0 & AREA_HECTAREA >  350))
  
  estimates[count,c("estimates")] <-lm.beta2(MOD=rdests, dta=censo_ag_wreform_tev, y="CashCrop_Share")
  estimates[count,c("ses")] <- lm.beta.ses2(MOD=rdests, dta=censo_ag_wreform_tev, y="CashCrop_Share") 
  estimates[count,c("y_var")] <- "Cash Crop Share"
  #estimates[count,c("label")] <- paste("Controlling for: ",labels[label.count],sep="")
  count<-count+1
  
  
  # Share Staple:
  rdests <- felm(StapleCrop_Share ~
                   non_comp 
                 | 0 | 0 | Expropretario_ISTA, 
                 data = censo_ag_wreform_tev,
                 subset = (reform==0 & AREA_HECTAREA >  350))
  
  estimates[count,c("estimates")] <-lm.beta2(MOD=rdests, dta=censo_ag_wreform_tev, y="CashCrop_Share")
  estimates[count,c("ses")] <- lm.beta.ses2(MOD=rdests, dta=censo_ag_wreform_tev, y="CashCrop_Share") 
  estimates[count,c("y_var")] <- "Staple Crop Share"
  #estimates[count,c("label")] <- paste("Controlling for: ",labels[label.count],sep="")
  
  # Suitabilities?
  
  count<-count+1
  label.count<-label.count+1
}


estimates

########################################

# Clean data for plotting:
alpha<- 0.05
Multiplier <- qnorm(1 - alpha / 2)

# Find the outcome var for each regression:
data <-estimates

# Replace y_var with nice names:

# Now, keep only the betas of interest:
betas <- data
dim(betas)
betas<- betas[seq(dim(betas)[1],1),]

# Create Matrix for plotting:
MatrixofModels <- betas[c("y_var", "estimates","ses","label")]
colnames(MatrixofModels) <- c("IV", "Estimate", "StandardError", "Group")
MatrixofModels$IV <- factor(MatrixofModels$IV, levels = unique(MatrixofModels$IV))
MatrixofModels$Group <- factor(MatrixofModels$Group, levels = paste0("Controlling for: ", labels))


# Plot:
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))
# Stupid fix to fix the scales overlapping on the bottom:
OutputPlot <- OutputPlot + geom_hline(yintercept = 0.02, alpha = 0.05)
OutputPlot <- OutputPlot + theme_bw() + ylab("\nStandardized Effect") + aesthetics 

# Save:
OutputPlot + coord_flip() + scale_y_continuous(breaks = seq(-1, 1,0.05),limits = c(-0.25,0.25)) + xlab("") 

ggsave(filename="./Output/CoefPlot_NonCompliers.pdf", width=6, height=3)