# NOT RUN {
##### Generates poverty.data using the original data from CONEVAL's website #####
# }
# NOT RUN {
# step 1:
# Download and unzip the file "R_2014.zip"
# available in:
# http://www.coneval.org.mx/Medicion/MP/Documents/Programas_calculo_pobreza_10_12_14/R_2014.zip
# step 2:
# extract and read the csv file "pobreza_14.csv"
coneval.poverty.data <- read.csv("pobreza_14.csv", na.strings=c("NA",""))
# step 3:
# Execute the following code...
var_id <- c("proyecto","folioviv","foliohog","numren")
for(i in match(var_id,colnames(coneval.poverty.data)) ){
coneval.poverty.data[,i] <- formatC( x=as.numeric(coneval.poverty.data[,i]),
width=max(nchar(coneval.poverty.data[,i])),
format="f",flag="0",digits=0
)
}
# normalizing the continuous variable for income #
b <- quantile(coneval.poverty.data$ict,probs=0.01)
coneval.poverty.data$ict_norm <- log(coneval.poverty.data$ict+b)
# Aggregating data at household level
Y_names <- c("ict_norm",
"ic_ali","ic_asalud","ic_cv",
"ic_rezedu","ic_sbv","ic_segsoc",
"niv_ed","tam_loc")
agg_form <- as.formula( paste( "cbind(",paste(c(Y_names,"factor_hog"),collapse=",") ,")",
"~proyecto+folioviv+foliohog"
)
)
poverty.data <- aggregate(agg_form,FUN="max",data=coneval.poverty.data)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab