| |
| |
| |
|
|
| 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(sandwich) |
| require(zoo) |
| require(fuzzyjoin) |
| require(haven) |
| require(stringi) |
|
|
|
|
| |
|
|
| |
|
|
| string_match <- function(string_to_match, options, smethod="osa") { |
| if(string_to_match!="") { |
| sdists <- stringdist(string_to_match, options, method=smethod) |
| ind <- which(sdists == min(sdists)) |
| if(length(ind) != 1) { |
| ind <- ind[1] |
| } |
| return(options[ind]) |
| } else { |
| return("") |
| } |
| } |
|
|
| as.numeric.factor <- function(x) {as.numeric(levels(x))[x]} |
|
|
| |
|
|
| |
| cantons <- read_dta(file="./Output/cantons_wGeoCovariates.dta") |
|
|
| |
| |
| canton_rd_vars <- read.csv(file="./Data/conflict_canton.csv", header=TRUE) |
| |
|
|
| |
| canton_rd_vars <- dplyr::select(canton_rd_vars,CODIGO,num_holdings:max_above_500) |
| |
| cantons <- left_join(cantons,canton_rd_vars, by="CODIGO") |
|
|
| cantons$CODIGO_NOM <- as.character(cantons$CODIGO_) |
|
|
| |
|
|
| poblaccion_section <- read_sav(file = "./Data/poblacion.sav") |
|
|
| |
|
|
| cantons_popcensus <- dplyr::select(poblaccion_section, |
| gender=S06P02, |
| age=S06P03A, |
| S06P07A, S06P08A1, S06P08A2, |
| DEPDSC, MUNDSC, CANDSC, |
| literate = S06P09, |
| educated = S06P10, |
| educ_level = S06P11A, |
| finished_hs = S06P11B, |
| S06P22) |
| |
|
|
| cantons_popcensus <- mutate(cantons_popcensus, |
| born_same_as_mother= ifelse(S06P07A < 3,S06P07A,NA) , |
| lived_canton_always = ifelse(S06P08A1 < 3,S06P08A1,NA), |
| lived_canton_year = ifelse(S06P08A2>0,S06P08A2,NA), |
| public_sector_worker = ifelse(S06P22 == 1, 1, |
| ifelse(is.na(S06P22) | S06P22==-2,NA, 0)), |
| pop = 1, |
| CODIGO_NOM = toupper(stri_trans_general(paste(DEPDSC, MUNDSC, CANDSC,sep=", "),"Latin-ASCII"))) |
|
|
| cantons_popcensus <- mutate(cantons_popcensus, |
| born_same_as_mother= ifelse(born_same_as_mother ==2 ,0,born_same_as_mother) , |
| lived_canton_always = ifelse(lived_canton_always ==2 ,0,lived_canton_always), |
| educ_yrs = 1*(educ_level==1)+6*(educ_level==2)+ 9*(educ_level==3)+ |
| 11*(educ_level==4)+13*(educ_level==5)+ 15*(educ_level==6)+ |
| 16*(educ_level==7)+ 17*(educ_level==8)+ 20*(educ_level==9)) |
|
|
| cantons_popcensus <- filter(cantons_popcensus, CANDSC != "AREA URBANA") |
|
|
| |
| cantons_popcensus <- cantons_popcensus %>% |
| group_by(CODIGO_NOM) %>% |
| summarise_if(is.numeric, mean, na.rm = TRUE) |
|
|
| max.dist <- 15 |
|
|
| |
| |
| |
| |
|
|
| max.dist <- 10 |
| cantons <- stringdist_join(cantons, cantons_popcensus, |
| by = c("CODIGO_NOM" = "CODIGO_NOM"), |
| mode = "left", |
| method = "jw", |
| max_dist = max.dist, |
| distance_col = "dist") |
|
|
| cantons <- cantons %>% |
| group_by(CODIGO_NOM.x) %>% |
| top_n(1, -dist) %>% ungroup() |
|
|
| as.numeric.factor <- function(x) {as.numeric(levels(x))[x]} |
| as.numeric.factor.wcheck <- function(x) {if(class(x)=="factor") { return(as.numeric(levels(x))[x]) } else { return(x)}} |
|
|
|
|
| |
| cantons$share_above500 <- cantons$num_above500/(cantons$num_above500 + cantons$num_below500) |
|
|
| |
| b0 <- lm(lived_canton_always ~ share_above500 + gender + age + age^2 , data=cantons) |
| cov0 <- vcovHC(b0, type = "HC1") |
| robust.se0 <- sqrt(diag(cov0)) |
| summary(b0) |
|
|
| |
| b1 <- lm(lived_canton_year ~ share_above500 + gender + age + age^2, data=cantons) |
| cov1 <- vcovHC(b1, type = "HC1") |
| robust.se1 <- sqrt(diag(cov1)) |
| summary(b1) |
|
|
| |
| b2 <- lm(born_same_as_mother ~ share_above500 + gender + age + age^2, data=cantons) |
| cov2 <- vcovHC(b2, type = "HC1") |
| robust.se2 <- sqrt(diag(cov2)) |
| summary(b2) |
|
|
|
|
| stargazer(b0,b1,b2, |
| type = "latex", |
| se = list(robust.se0, robust.se1,robust.se2), |
| keep = c("share_above500"), |
| digits = 4, |
| out="./Output/MigrationOutcomes_CantonLevel.tex") |
|
|
|
|
| |
|
|
| |
|
|
| cantons_popcensus <- dplyr::select(poblaccion_section, |
| gender=S06P02, |
| age=S06P03A, |
| S06P07A, S06P08A1, S06P08A2, |
| DEPDSC, MUNDSC, CANDSC, |
| literate = S06P09, |
| educated = S06P10, |
| educ_level = S06P11A, |
| finished_hs = S06P11B) |
|
|
| cantons_popcensus <- mutate(cantons_popcensus, |
| born_same_as_mother= ifelse(S06P07A < 3,S06P07A,NA) , |
| lived_canton_always = ifelse(S06P08A1 < 3,S06P08A1,NA), |
| lived_canton_year = ifelse(S06P08A2>0,S06P08A2,NA), |
| finished_hs = ifelse(finished_hs>0,finished_hs, NA), |
| CODIGO_NOM = toupper(stri_trans_general(paste(DEPDSC, MUNDSC, CANDSC,sep=", "),"Latin-ASCII"))) |
|
|
| cantons_popcensus <- mutate(cantons_popcensus, |
| born_same_as_mother= ifelse(born_same_as_mother ==2 ,0,born_same_as_mother) , |
| finished_hs = ifelse(finished_hs==2, 0, finished_hs), |
| lived_canton_always = ifelse(lived_canton_always ==2 ,0,lived_canton_always) |
| ) |
|
|
| cantons_popcensus_educ <- filter(cantons_popcensus, |
| finished_hs==1) |
|
|
| cantons_popcensus_educ <- filter(cantons_popcensus_educ, CANDSC != "AREA URBANA") |
|
|
| |
| cantons_popcensus_educ <- cantons_popcensus_educ %>% |
| group_by(CODIGO_NOM) %>% |
| summarise_if(is.numeric, mean, na.rm = TRUE) |
|
|
| max.dist <- 15 |
|
|
| cantons <- read_dta(file="./Output/cantons_wGeoCovariates.dta") |
| cantons <- left_join(cantons,canton_rd_vars, by="CODIGO") |
|
|
| cantons$CODIGO_NOM <- as.character(cantons$CODIGO_) |
|
|
|
|
| max.dist <- 10 |
| cantons <- stringdist_join(cantons, cantons_popcensus_educ, |
| by = c("CODIGO_NOM" = "CODIGO_NOM"), |
| mode = "left", |
| method = "jw", |
| max_dist = max.dist, |
| distance_col = "dist") |
|
|
| cantons <- cantons %>% |
| group_by(CODIGO_NOM.x) %>% |
| top_n(1, -dist) %>% ungroup() |
|
|
| as.numeric.factor <- function(x) {as.numeric(levels(x))[x]} |
| as.numeric.factor.wcheck <- function(x) {if(class(x)=="factor") { return(as.numeric(levels(x))[x]) } else { return(x)}} |
|
|
| |
| cantons$share_above500 <- cantons$num_above500/(cantons$num_above500 + cantons$num_below500) |
|
|
| |
| b0 <- lm(lived_canton_always ~ share_above500 + gender + age + age^2 , data=cantons) |
| cov0 <- vcovHC(b0, type = "HC1") |
| robust.se0 <- sqrt(diag(cov0)) |
| summary(b0) |
|
|
| |
| b1 <- lm(lived_canton_year ~ share_above500 + gender + age + age^2, data=cantons) |
| cov1 <- vcovHC(b1, type = "HC1") |
| robust.se1 <- sqrt(diag(cov1)) |
| summary(b1) |
|
|
| |
| b2 <- lm(born_same_as_mother ~ share_above500 + gender + age + age^2, data=cantons) |
| cov2 <- vcovHC(b2, type = "HC1") |
| robust.se2 <- sqrt(diag(cov2)) |
| summary(b2) |
|
|
|
|
| stargazer(b0,b1,b2, |
| type = "latex", |
| se = list(robust.se0, robust.se1,robust.se2), |
| keep = c("share_above500"), |
| digits = 4, |
| out="./Output/MigrationOutcomes_CantonLevel_CompletedHS.tex") |
|
|
|
|
|
|
|
|