Control <- c(round(sum_stats[[1,2]], 0), paste0("(", round(sum_stats[[1,3]], 0), ")"), round(sum_stats[[1,4]], 3), paste0("(", round(sum_stats[[1,5]], 3), ")"),
round(sum_stats[[1,6]],2), paste0("(", round(sum_stats[[1,7]],2), ")"), round(sum_stats[[1,8]], 0), paste0("(", round(sum_stats[[1,9]], 0), ")"))
loan_table <- as.data.frame(bind_cols(Var, Treat, Control, p_vals))
names(loan_table) <- c("Var", "Treat", "Control", "p_val")
xtable(loan_table)
loan_table_out <- xtable(loan_table)
print.xtable(loan_table_out, type='latex', file=paste0(dir_save, 'balance_loans_gl.tex'))
# The purpose of this code is to simulate the choice
# of borrowing in period 1, inputs in period 1, and borrowing each state of period 2
# Simulate different cases of moving borrowing constraints
rm(list=ls()) # Clear workspace
#set working directory to current folder
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
require(stats)
require(ggplot2)
require(tidyr)
require(dplyr)
require(foreign)
require(lfe)
require(tidyverse)
require(haven)
#read in real data
merged_clean_2020 <- read_dta("temp_data/merged_clean_2020.dta")
crop_data <- select(merged_clean_2020, total_crop_prod, taka_cropsales, total_inputs_tk, active_branch, land_cult, district, hchyid, yield)
#estimate crop price by relationship between
crop_price_reg <- felm(taka_cropsales ~ total_crop_prod | 0 | 0 | hchyid, data=crop_data %>% filter(taka_cropsales>0))
summary(crop_price_reg)
price <- crop_price_reg$beta[2]
crop_data <- crop_data %>% mutate(log_value = log(total_crop_prod*price+1),  log_output = log(total_crop_prod+1), log_inputs = log(total_inputs_tk+1), log_land = log(land_cult+1))
prod_est <- felm(log_value ~ log_inputs + log_land + active_branch | 0 | 0 |hchyid, data=crop_data)
summary(prod_est)
input_alpha <- prod_est$beta[2]
land_beta <- prod_est$beta[3]
my_theme = function() {
theme(title = element_text(color = 'black', vjust = 1),
panel.background = element_rect(fill = 'white'),
plot.background = element_rect(fill = 'white'),
panel.grid.minor = element_blank(),
panel.grid.major = element_line(colour = '#dddddd'),
axis.text.x = element_text(colour = 'black'),
axis.text.y = element_text(colour = 'black'),
axis.title.x = element_text(colour = 'black', vjust = -.3),
axis.title.y = element_text(colour = 'black', vjust = 1.5),
legend.key = element_rect(fill = 'white'),
legend.text = element_text(colour = 'black'),
legend.title = element_text(colour = 'black'),
legend.background = element_rect(fill = 'white'),
legend.key.height=unit(1, "cm"),
axis.ticks = element_blank(),
plot.title = element_text(hjust = 0.5))
}
##### Moving from Micro-credit only to Emergency Loan #####
### Define utility and production functions ###
u = function(c, r){
utility = (((c^(1-r))-1)/(1-r))
return(utility)
}
f_b = function(x, alpha, l){
production =7*flood_pen*x^alpha*l^beta #get 7 because this is  " price * A x^alpha l^beta ". A = e^0.44=1.52, p = 4.61 from reg of price sold on production.
return(production)
}
f_g = function(x, alpha, l){
production = 7*x^alpha*l^beta
return(production)
}
### Define parameters ###
pi = .24 # probability of bad state of total crop failure (24% of sample reported no crops even though planted)
delta = .9 # discount factor roughly estimated from time perference experiment - ask for year lag. Have 0.7 discount. Period of waiting roughtly 4 months, so 0.9^3 = 0.7 roughly
p = 1 # cost of input
p2 = 5 # cost of land (assume cost of inputs per acre is ~ 1/5 the cost of renting the land)
R = 1.2 #BRAC interest rate
Y = 30 #rough estimate of starting available cash - enough to rent six acres of land
I = 30 #set dry season profit equal to starting cash on hand
#r = 0.9 #choose risk aversion below
alpha = input_alpha
beta = land_beta
flood_pen = 0.01 #set shock to almost full crop loss (corresponds to 24% zero harvest above)
#Change function so that b2b is choice, but need to add inequality constraint via constrOptim function
#Important change is now third period becomes vital - defines optimal choice of b2b
EU_fun2 = function(choice_par, r){
b1 = choice_par[1]
x = choice_par[2]
b2b = choice_par[3]
b2g = choice_par[4]
l = choice_par[5]
c0 = Y - p*x + b1 - p2*l
c1b = f_b(x, alpha, l) - R*b1 + b2b
c1g = f_g(x, alpha, l) - R*b1 + b2g
c2b = I -R*b2b
c2g = I -R*b2g
EU = u(c0, r) + delta*( pi*u(c1b, r) + (1-pi)*u(c1g, r)) + delta^2*( pi*u(c2b, r) + (1-pi)*u(c2g, r))
return(-EU)
}
#Write constrainted optimize function that forces b2b <= B
get_optim2 = function(r,B0){
optimized = constrOptim(theta=c(-1,Y/100,-0.001,0.1,Y/2/p2), f=EU_fun2, r=r, grad=NULL,
ui=rbind(c(-1,0,0,0,0), # b1 < 2*B0 - as this is EL condition, effectively b1 doesn't bind at parameter values I've chosen
c(0,1,0,0,0), # x > 0
c(0,0,-1,0,0), #b2b < B0
c(0,0,0,-1,0), #b2g < B0
c(0,0,1,0,0), #b2b > B0)
c(0,0,0,1,0)), #b2g > B0
ci=c(-B0,0,-0.5*B0,-B0,-0.01, -0.01))
#ci=c(-2*B0,0,-B0,-B0))  #This evaluates all greater than or equal to constraints
#optimized = optim(par=c(0, Y/2,0), f=EU_fun2)
choice_star = optimized$par
return(choice_star)
}
#Write constrained optimize for function that estimates status quo b2b <=0
get_optim2_base = function(r,B0){
optimized = constrOptim(theta=c(-1,Y/100,-0.001,0.1,Y/2/p2), f=EU_fun2, r=r, grad=NULL,
ui=rbind(c(-1,0,0,0,0), # b1 < B0 - as this is EL condition, effectively b1 doesn't bind at parameter values I've chosen
c(0,1,0,0,0), # x > 0
c(0,0,-1,0,0), #b2b < 0
c(0,0,0,-1,0), #b2g < B0
c(0,0,1,0,0), #b2b > -B0
c(0,0,0,1,0)), #b2g > -B0
ci=c(-B0,0,0,-B0,-0.01, -0.01))
#ci=c(-2*B0,0,-B0,-B0))  #This evaluates all greater than or equal to constraints
#optimized = optim(par=c(0, Y/2,0), f=EU_fun2)
choice_star = optimized$par
return(choice_star)
}
#vary risk aversion parameter - start at 0.2 because below this optimum vary widely which makes % changes very imprecise
r_vec = seq(0.2,0.99,0.01)  #note, the risk game estimates indifference at 140 at 60% and 40% certainty
# u(40, 0.3)  roughly equal to 0.4 * u(0, 0.3) +  0.4*u(140, 0.3)
B <- Y/3 #choose BRAC loan amount to be about 1/3 of household available cash (including what they need for consumption)
optim_vec = sapply(r_vec, get_optim2, B)
df_plot = data.frame(constraint=r_vec, b1=optim_vec[1,], x=optim_vec[2,], b2b=optim_vec[3,], l=optim_vec[5,]) %>%
mutate(x_p_l = x/l) %>%
gather(parameter, value, -constraint)
ggplot(df_plot %>% filter(parameter!="x_p_l"), aes(x=constraint, y=value)) + geom_line(aes(colour=parameter)) + ylim(-5,15) +
my_theme() + ylab('Value at Optimum') + xlab('Risk Aversion')  +
scale_color_hue(labels = c("First Period\nBorrowing",  "Bad State\nBorrowing", "Land", "Inputs")) +
guides(color=guide_legend("Choice\nParameter")) +
ggtitle(paste('Investment with Emergency Loan'))
ggsave('figures/optim_values_EL_sim.pdf')
optim_vec_base = sapply(r_vec, get_optim2_base, B)
df_plot2 = data.frame(constraint=r_vec, b1=optim_vec_base[1,], x=optim_vec_base[2,], b2b=optim_vec_base[3,], l=optim_vec_base[5,]) %>%
mutate(x_p_l = x/l) %>%
gather(parameter2, value2, -constraint)
ggplot(df_plot2 %>% filter(parameter2!="x_p_l"), aes(x=constraint, y=value2)) + geom_line(aes(colour=parameter2)) + ylim(-5,15) +
my_theme() + ylab('Value at Optimum') + xlab('Risk Aversion')  +
scale_color_hue(labels = c("First Period\nBorrowing",  "Bad State\nBorrowing", "Land", "Inputs")) +
guides(color=guide_legend("Choice\nParameter")) +
ggtitle(paste('Investment for Status Quo'))
ggsave('figures/optim_values_SQ_sim.pdf')
#plot % change in choice
df_plot3 = bind_cols(df_plot, df_plot2 %>% select(-constraint)) %>% mutate(treat_ef = (value-value2), treat_ef_pct=(value-value2)/value2)
ggplot(df_plot3 %>% filter(parameter!="b2b" & parameter!="b1"), aes(x=constraint, y=treat_ef_pct)) + # + geom_line(aes(colour=parameter)) +
geom_smooth(aes(colour=parameter)) + #ylim(0.1,0.35) +
geom_hline(yintercept=0.149, linetype="dashed", color='gray33') +
geom_vline(xintercept=0.3, linetype="dashed", color='red') +
my_theme() + ylab('Pct. Change In Choice') + xlab('Risk Aversion') +
scale_color_manual(values=c('#00BFC4','#C77CFF', '#CD9600'), labels = c("Land", "Inputs", "Inputs\nper Acre")) +
guides(color=guide_legend("Choice\nParameter")) +
ggtitle(paste('Simulated Treatment Effect'))
ggsave('figures/treat_effect_sim.pdf')
############### Change shock probability to 0.05 to see how this changes choices
r_vec = seq(0.2,0.99,0.01)
B <- Y/3 #choose BRAC loan amount to be about 1/3 of household available cash (including what they need for consumption)
pi <- 0.05 #change only this parameter
optim_vec = sapply(r_vec, get_optim2, B)
df_plot = data.frame(constraint=r_vec, b1=optim_vec[1,], x=optim_vec[2,], b2b=optim_vec[3,], l=optim_vec[5,]) %>%
mutate(x_p_l = x/l) %>%
gather(parameter, value, -constraint)
ggplot(df_plot %>% filter(parameter!="x_p_l"), aes(x=constraint, y=value)) + geom_line(aes(colour=parameter)) + ylim(-5,15) +
my_theme() + ylab('Value at Optimum') + xlab('Risk Aversion')  +
scale_color_hue(labels = c("First Period\nBorrowing",  "Bad State\nBorrowing", "Land", "Inputs")) +
guides(color=guide_legend("Choice\nParameter")) +
ggtitle(paste('Investment with Emergency Loan - Low Shock Prob'))
ggsave('figures/optim_values_EL_sim_low_pi.pdf')
optim_vec_base = sapply(r_vec, get_optim2_base, B)
df_plot2 = data.frame(constraint=r_vec, b1=optim_vec_base[1,], x=optim_vec_base[2,], b2b=optim_vec_base[3,], l=optim_vec_base[5,]) %>%
mutate(x_p_l = x/l) %>%
gather(parameter2, value2, -constraint)
ggplot(df_plot2 %>% filter(parameter2!="x_p_l"), aes(x=constraint, y=value2)) + geom_line(aes(colour=parameter2)) + ylim(-5,15) +
my_theme() + ylab('Value at Optimum') + xlab('Risk Aversion')  +
scale_color_hue(labels = c("First Period\nBorrowing",  "Bad State\nBorrowing", "Land", "Inputs")) +
guides(color=guide_legend("Choice\nParameter")) +
ggtitle(paste('Investment for Status Quo - Low Shock Prob'))
ggsave('figures/optim_values_SQ_sim_low_pi.pdf')
#plot % change in choice
df_plot3 = bind_cols(df_plot, df_plot2 %>% select(-constraint)) %>% mutate(treat_ef = (value-value2), treat_ef_pct=(value-value2)/value2)
ggplot(df_plot3 %>% filter(parameter!="b2b" & parameter!="b1"), aes(x=constraint, y=treat_ef_pct)) + # + geom_line(aes(colour=parameter)) +
geom_smooth(aes(colour=parameter)) + #ylim(0.1,0.35) +
geom_hline(yintercept=0.149, linetype="dashed", color='gray33') +
geom_vline(xintercept=0.3, linetype="dashed", color='red') +
my_theme() + ylab('Pct. Change In Choice') + xlab('Risk Aversion') +
scale_color_manual(values=c('#00BFC4','#C77CFF', '#CD9600'), labels = c("Land", "Inputs", "Inputs\nper Acre")) +
guides(color=guide_legend("Choice\nParameter")) +
ggtitle(paste('Simulated Treatment Effect - Low Shock Prob'))
ggsave('figures/treat_effect_sim_low_pi.pdf')
######### Match Randomized  Sample to Gauges -  ######################
######################## Mar 12 2016 #################################
rm(list = ls())
library(foreign)
library(gdata)
library(dplyr)
library(rgdal)
install.packages('rgdal')
######### Match Randomized  Sample to Gauges -  ######################
######################## Mar 12 2016 #################################
rm(list = ls())
library(foreign)
library(gdata)
library(dplyr)
library(ggplot2)
library(RColorBrewer)
library(grid)
library(maptools)
install.packages('maptools')
######### Match Randomized  Sample to Gauges -  ######################
######################## Mar 12 2016 #################################
rm(list = ls())
library(foreign)
library(gdata)
library(dplyr)
library(ggplot2)
library(RColorBrewer)
library(grid)
#library(rgdal)
#library(maptools)
library(rgeos)
install.packages('rgeos')
######### Match Randomized  Sample to Gauges -  ######################
######################## Mar 12 2016 #################################
rm(list = ls())
library(foreign)
library(gdata)
library(dplyr)
library(ggplot2)
library(RColorBrewer)
library(grid)
#library(rgdal)
#library(maptools)
#library(rgeos)
library(geosphere)
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
dir_data <- "data/"
dir_save <- "tables/"
dir_save_fig <- "figures/"
#Read in Gauges that are Online#
gauges = read.csv(paste0(dir_data, "ffwc_online_gauge_locs.csv"))
gauges=rename(gauges, gauge_long=long, gauge_lat=lat)
#Read Branches
branches = read.csv(paste0(dir_data, "branch_locations.csv"))
######### Match Randomized  Sample to Gauges -  ######################
######################## Mar 12 2016 #################################
rm(list = ls())
library(foreign)
library(gdata)
library(dplyr)
library(ggplot2)
library(RColorBrewer)
library(grid)
#library(rgdal)
#library(maptools)
#library(rgeos)
library(geosphere)
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
dir_data <- "data/"
dir_save <- "tables/"
dir_save_fig <- "figures/"
######### Match Randomized  Sample to Gauges -  ######################
######################## Mar 12 2016 #################################
rm(list = ls())
library(foreign)
library(gdata)
library(dplyr)
library(ggplot2)
library(RColorBrewer)
library(grid)
#library(rgdal)
#library(maptools)
#library(rgeos)
library(geosphere)
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
dir_data <- "data/"
dir_save <- "tables/"
dir_save_fig <- "figures/"
#Read in Gauges that are Online#
gauges = read.csv(paste0(dir_data, "ffwc_gauge_locs.csv"))
View(gauges)
gauges=rename(gauges, gauge_long=longitude, gauge_lat=lat)
#Read Branches
branches = read.csv(paste0(dir_data, "branch_locations.csv"))
View(branches)
#### Map Branches and Gauges ####
#Read in Bangla Shape File - for use in graphs.
b.shape <-readOGR(dsn=paste0(dir_data, '/BGD_adm'), layer='BGD_adm3')
install.packages('sf')
#### Map Branches and Gauges ####
#Read in Bangla Shape File - for use in graphs.
b.shape <-st_read(dsn=paste0(dir_data, '/BGD_adm'), layer='BGD_adm3')
?st_read
library(sf)
?st_read
#### Map Branches and Gauges ####
#Read in Bangla Shape File - for use in graphs.
b.shape <-st_read(dsn=paste0(dir_data, '/BGD_adm'), layer='BGD_adm3')
#Need to create an ID input for the shape fall for it to be used in ggplot
rownames(b.shape@data)
#Plot
myThemeStuff <- theme(panel.background = element_rect(fill = NA),
panel.border = element_rect(fill = NA, color = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks = element_line(color = "gray5"),
axis.text = element_text(color = "black", size = 8, angle=0),
axis.title = element_text(color = "black", size = 11),
legend.key = element_blank())
ggplot()  +  geom_polygon(data= b.shape1,
aes(x =long, y=lat, group=group), alpha=0.3, color="#969696")  +
geom_point(data=plot.data , aes(x = gps_longitude.x , y = gps_latitude.x, color=treated), size=2, shape=17) +
theme(legend.position = 'right', legend.text = element_text(size = 20), legend.key = element_blank(), legend.title= element_blank()) +
xlab("Longitude") + ylab("Latitude") +
geom_point(data=plot.data, aes(x=gauge_long.x, y=gauge_lat.x, shape="Gauge"), size=3, color="#525252") +
scale_color_manual(values = c('#c32020','#387ddd'),
labels = c(
'Control',
'Treated')) +
myThemeStuff #+ ggtitle("Sample Branches and FFWC Gauges")
ggplot()  +  geom_polygon(data= b.shape,
aes(x =long, y=lat, group=group), alpha=0.3, color="#969696")  +
geom_point(data=plot.data , aes(x = gps_longitude.x , y = gps_latitude.x, color=treated), size=2, shape=17) +
theme(legend.position = 'right', legend.text = element_text(size = 20), legend.key = element_blank(), legend.title= element_blank()) +
xlab("Longitude") + ylab("Latitude") +
geom_point(data=plot.data, aes(x=gauge_long.x, y=gauge_lat.x, shape="Gauge"), size=3, color="#525252") +
scale_color_manual(values = c('#c32020','#387ddd'),
labels = c(
'Control',
'Treated')) +
myThemeStuff #+ ggtitle("Sample Branches and FFWC Gauges")
names(branches)
View(branches)
names(gauges)
ggplot()  +  geom_polygon(data= b.shape,
aes(x =long, y=lat, group=group), alpha=0.3, color="#969696")  +
geom_point(data=branches , aes(x = gps_longitude , y = gps_latitude, color=treated), size=2, shape=17) +
theme(legend.position = 'right', legend.text = element_text(size = 20), legend.key = element_blank(), legend.title= element_blank()) +
xlab("Longitude") + ylab("Latitude") +
geom_point(data=gauges, aes(x=gauge_long, y=gauge_lat, shape="Gauge"), size=3, color="#525252") +
scale_color_manual(values = c('#c32020','#387ddd'),
labels = c(
'Control',
'Treated')) +
myThemeStuff #+ ggtitle("Sample Branches and FFWC Gauges")
ggplot()  +  geom_sf(data= b.shape, alpha=0.3, color="#969696")  +
geom_point(data=branches , aes(x = gps_longitude , y = gps_latitude, color=treated), size=2, shape=17) +
theme(legend.position = 'right', legend.text = element_text(size = 20), legend.key = element_blank(), legend.title= element_blank()) +
xlab("Longitude") + ylab("Latitude") +
geom_point(data=gauges, aes(x=gauge_long, y=gauge_lat, shape="Gauge"), size=3, color="#525252") +
scale_color_manual(values = c('#c32020','#387ddd'),
labels = c(
'Control',
'Treated')) +
myThemeStuff #+ ggtitle("Sample Branches and FFWC Gauges")
ggplot()  +  geom_sf(data= b.shape, alpha=0.3, color="#969696")  +
geom_point(data=branches , aes(x = gps_longitude , y = gps_latitude, color=as.factor(treated)), size=2, shape=17) +
theme(legend.position = 'right', legend.text = element_text(size = 20), legend.key = element_blank(), legend.title= element_blank()) +
xlab("Longitude") + ylab("Latitude") +
geom_point(data=gauges, aes(x=gauge_long, y=gauge_lat, shape="Gauge"), size=3, color="#525252") +
scale_color_manual(values = c('#c32020','#387ddd'),
labels = c(
'Control',
'Treated')) +
myThemeStuff #+ ggtitle("Sample Branches and FFWC Gauges")
######### Match Randomized  Sample to Gauges -  ######################
######################## Mar 12 2016 #################################
rm(list = ls())
library(foreign)
library(gdata)
library(dplyr)
library(ggplot2)
library(RColorBrewer)
library(grid)
library(geosphere)
library(sf)
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
dir_data <- "data/"
dir_save <- "tables/"
dir_save_fig <- "figures/"
#Read in Gauges that are Online#
gauges = read.csv(paste0(dir_data, "ffwc_gauge_locs.csv"))
gauges=rename(gauges, gauge_long=longitude, gauge_lat=lat)
#Read Branches
branches = read.csv(paste0(dir_data, "branch_locations.csv"))
#### Map Branches and Gauges ####
#Read in Bangla Shape File - for use in graphs.
b.shape <-st_read(dsn=paste0(dir_data, '/BGD_adm'), layer='BGD_adm3')
#Plot
myThemeStuff <- theme(panel.background = element_rect(fill = NA),
panel.border = element_rect(fill = NA, color = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks = element_line(color = "gray5"),
axis.text = element_text(color = "black", size = 8, angle=0),
axis.title = element_text(color = "black", size = 11),
legend.key = element_blank())
ggplot()  +  geom_sf(data= b.shape, alpha=0.3, color="#969696")  +
geom_point(data=branches , aes(x = gps_longitude , y = gps_latitude, color=as.factor(treated)), size=2, shape=17) +
theme(legend.position = 'right', legend.text = element_text(size = 20), legend.key = element_blank(), legend.title= element_blank()) +
xlab("Longitude") + ylab("Latitude") +
geom_point(data=gauges, aes(x=gauge_long, y=gauge_lat, shape="Gauge"), size=3, color="#525252") +
scale_color_manual(values = c('#c32020','#387ddd'),
labels = c(
'Control',
'Treated')) +
myThemeStuff
ggsave(paste0(dir_save_fig, "branch_map.pdf"), plot=map)
map <- ggplot()  +  geom_sf(data= b.shape, alpha=0.3, color="#969696")  +
geom_point(data=branches , aes(x = gps_longitude , y = gps_latitude, color=as.factor(treated)), size=2, shape=17) +
theme(legend.position = 'right', legend.text = element_text(size = 20), legend.key = element_blank(), legend.title= element_blank()) +
xlab("Longitude") + ylab("Latitude") +
geom_point(data=gauges, aes(x=gauge_long, y=gauge_lat, shape="Gauge"), size=3, color="#525252") +
scale_color_manual(values = c('#c32020','#387ddd'),
labels = c(
'Control',
'Treated')) +
myThemeStuff
ggsave(paste0(dir_save_fig, "branch_map.pdf"), plot=map)
######### Match Randomized  Sample to Gauges -  ######################
######################## Mar 12 2016 #################################
rm(list = ls())
library(foreign)
library(gdata)
library(dplyr)
library(ggplot2)
library(RColorBrewer)
library(grid)
library(geosphere)
library(sf)
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
dir_data <- "data/"
dir_save <- "tables/"
dir_save_fig <- "figures/"
#Read in Gauges that are Online#
gauges = read.csv(paste0(dir_data, "ffwc_gauge_locs.csv"))
gauges=rename(gauges, gauge_long=longitude, gauge_lat=lat)
#Read Branches
branches = read.csv(paste0(dir_data, "branch_locations.csv"))
#### Map Branches and Gauges ####
#Read in Bangla Shape File - for use in graphs.
b.shape <-st_read(dsn=paste0(dir_data, '/BGD_adm'), layer='BGD_adm3')
#Plot
myThemeStuff <- theme(panel.background = element_rect(fill = NA),
panel.border = element_rect(fill = NA, color = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks = element_line(color = "gray5"),
axis.text = element_text(color = "black", size = 8, angle=0),
axis.title = element_text(color = "black", size = 11),
legend.key = element_blank())
map <- ggplot()  +  geom_sf(data= b.shape, alpha=0.3, color="#969696")  +
geom_point(data=branches , aes(x = gps_longitude , y = gps_latitude, color=as.factor(treated)), size=2, shape=17) +
theme(legend.position = 'right', legend.text = element_text(size = 20), legend.key = element_blank(), legend.title= element_blank()) +
xlab("Longitude") + ylab("Latitude") +
geom_point(data=gauges, aes(x=gauge_long, y=gauge_lat, shape="Gauge"), size=3, color="#525252") +
scale_color_manual(values = c('#c32020','#387ddd'),
labels = c(
'Control',
'Treated')) +
myThemeStuff
ggsave(paste0(dir_save_fig, "branch_map.pdf"), plot=map)
map
######### Match Randomized  Sample to Gauges -  ######################
######################## Mar 12 2016 #################################
rm(list = ls())
library(foreign)
library(gdata)
library(dplyr)
library(ggplot2)
library(RColorBrewer)
library(grid)
library(geosphere)
library(sf)
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
dir_data <- "data/"
dir_save <- "tables/"
dir_save_fig <- "figures/"
#Read in Gauges that are Online#
gauges = read.csv(paste0(dir_data, "ffwc_gauge_locs.csv"))
gauges=rename(gauges, gauge_long=longitude, gauge_lat=lat)
#Read Branches
branches = read.csv(paste0(dir_data, "branch_locations.csv"))
#### Map Branches and Gauges ####
#Read in Bangla Shape File - for use in graphs.
b.shape <-st_read(dsn=paste0(dir_data, '/BGD_adm'), layer='BGD_adm3')
#Plot
myThemeStuff <- theme(panel.background = element_rect(fill = NA),
panel.border = element_rect(fill = NA, color = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks = element_line(color = "gray5"),
axis.text = element_text(color = "black", size = 8, angle=0),
axis.title = element_text(color = "black", size = 11),
legend.key = element_blank())
map <- ggplot()  +  geom_sf(data= b.shape, alpha=0.3, color="#969696")  +
geom_point(data=branches , aes(x = gps_longitude , y = gps_latitude, color=as.factor(treated)), size=2, shape=17) +
theme(legend.position = 'right', legend.text = element_text(size = 20), legend.key = element_blank(), legend.title= element_blank()) +
xlab("Longitude") + ylab("Latitude") +
geom_point(data=gauges, aes(x=gauge_long, y=gauge_lat, shape="Gauge"), size=3, color="#525252") +
scale_color_manual(values = c('#c32020','#387ddd'),
labels = c(
'Control',
'Treated')) +
myThemeStuff
ggsave(paste0(dir_save_fig, "branch_map.pdf"), plot=map)
#map
#map
map
