if(!is.null(level)) assertthat::assert_that(level %in% c("household", "h", "individual", "i"), msg = "Verifica el nivel seleccionado")
# design ---
design_ech <- ech::set_design(data = data, level = level)
# supressed warnings ---
options(survey.lonely.psu="adjust")
options(dplyr.summarise.inform = FALSE)
# estimation ---
if(is.null(by.x) & is.null(by.y) & is.null(domain)){
estimation <- design_ech %>%
srvyr::summarise(colname = srvyr::survey_ratio(.data[[variable.x]], .data[[variable.y]]))
} else if(is.character(by.x) & is.null(by.y) & is.null(domain)){
estimation <- design_ech %>%
srvyr::group_by(.data[[by.x]]) %>%
srvyr::summarise(as.name(colname) = srvyr::survey_ratio(.data[[variable.x]], .data[[variable.y]]))
} else if(is.character(by.x) & is.character(by.y) & is.null(domain)){
estimation <- design_ech %>%
srvyr::group_by(.data[[by.x]], .data[[by.y]]) %>%
srvyr::summarise(colname = srvyr::survey_ratio(.data[[variable.x]], .data[[variable.y]]))
} else if(is.null(by.x) & is.null(by.y) & is.logical(domain)){
estimation <- design_ech %>%
srvyr::filter(domain) %>%
srvyr::summarise(colname = srvyr::survey_ratio(.data[[variable.x]], .data[[variable.y]]))
} else if(is.character(by.x) & is.null(by.y) & is.logical(domain)){
estimation <- design_ech %>%
srvyr::filter(domain) %>%
srvyr::group_by(.data[[by.x]]) %>%
srvyr::summarise(colname = srvyr::survey_ratio(.data[[variable.x]], .data[[variable.y]]))
} else {
estimation <- design_ech %>%
srvyr::filter(domain) %>%
srvyr::group_by(.data[[by.x]], .data[[by.y]]) %>%
srvyr::summarise(colname = srvyr::survey_ratio(.data[[variable.x]], .data[[variable.y]]))
}
return(estimation)
}
get_estimation_ratio <- function(data = ech::toy_ech_2018,
variable.x = NULL,
variable.y = NULL,
by.x = NULL,
by.y = NULL,
domain = NULL,
level = NULL,
colname = "estimacion"){
# checks ----
assertthat::assert_that(!is.null(data) | !is.null(variable.x) | !is.null(variable.y), msg = "Debe indicar la variable")
assertthat::assert_that(all(variable.x %in% names(data)), msg = glue::glue("La variable {variable.x} no esta en {data}"))
assertthat::assert_that(all(variable.y %in% names(data)), msg = glue::glue("La variable {variable.y} no esta en {data}"))
if(!is.null(by.x)) assertthat::assert_that(by.x %in% names(data), msg = glue::glue("La variable {by.x} no esta en {data}"))
if(!is.null(by.y)) assertthat::assert_that(by.y %in% names(data), msg = glue::glue("La variable {by.y} no esta en {data}"))
if(!is.null(level)) assertthat::assert_that(level %in% c("household", "h", "individual", "i"), msg = "Verifica el nivel seleccionado")
# design ---
design_ech <- ech::set_design(data = data, level = level)
# supressed warnings ---
options(survey.lonely.psu="adjust")
options(dplyr.summarise.inform = FALSE)
# estimation ---
if(is.null(by.x) & is.null(by.y) & is.null(domain)){
estimation <- design_ech %>%
srvyr::summarise(colname = srvyr::survey_ratio(.data[[variable.x]], .data[[variable.y]]))
} else if(is.character(by.x) & is.null(by.y) & is.null(domain)){
estimation <- design_ech %>%
srvyr::group_by(.data[[by.x]]) %>%
srvyr::summarise(colname = srvyr::survey_ratio(.data[[variable.x]], .data[[variable.y]]))
} else if(is.character(by.x) & is.character(by.y) & is.null(domain)){
estimation <- design_ech %>%
srvyr::group_by(.data[[by.x]], .data[[by.y]]) %>%
srvyr::summarise(colname = srvyr::survey_ratio(.data[[variable.x]], .data[[variable.y]]))
} else if(is.null(by.x) & is.null(by.y) & is.logical(domain)){
estimation <- design_ech %>%
srvyr::filter(domain) %>%
srvyr::summarise(colname = srvyr::survey_ratio(.data[[variable.x]], .data[[variable.y]]))
} else if(is.character(by.x) & is.null(by.y) & is.logical(domain)){
estimation <- design_ech %>%
srvyr::filter(domain) %>%
srvyr::group_by(.data[[by.x]]) %>%
srvyr::summarise(colname = srvyr::survey_ratio(.data[[variable.x]], .data[[variable.y]]))
} else {
estimation <- design_ech %>%
srvyr::filter(domain) %>%
srvyr::group_by(.data[[by.x]], .data[[by.y]]) %>%
srvyr::summarise(colname = srvyr::survey_ratio(.data[[variable.x]], .data[[variable.y]]))
}
return(estimation)
}
a <- get_estimation_mean(data = d, variable = "pobre06", level = "h")
ech_2018 <- employment(data = ech::toy_ech_2018, pobpcoac = "pobpcoac")
get_estimation_total <- function(data = ech::toy_ech_2018,
variable = NULL,
by.x = NULL,
by.y = NULL,
domain = NULL,
level = NULL,
colname = "estimacion"){
# checks ----
assertthat::assert_that(!is.null(data) | !is.null(variable), msg = "Debe indicar la variable")
assertthat::assert_that(all(variable %in% names(data)), msg = glue::glue("La variable {variable} no esta en {data}"))
if(!is.null(by.x)) assertthat::assert_that(by.x %in% names(data), msg = glue::glue("La variable {by.x} no esta en {data}"))
if(!is.null(by.y)) assertthat::assert_that(by.y %in% names(data), msg = glue::glue("La variable {by.y} no esta en {data}"))
if(!is.null(level)) assertthat::assert_that(level %in% c("household", "h", "individual", "i"), msg = "Verifica el nivel seleccionado")
# design ----
design_ech <- ech::set_design(data = data, level = level)
# supressed warnings ---
options(survey.lonely.psu = "adjust")
options(dplyr.summarise.inform = FALSE)
# estimation ----
if(is.null(by.x) & is.null(by.y) & is.null(domain)){
estimation <- design_ech %>%
srvyr::summarise(colname = srvyr::survey_total(.data[[variable]]))
} else if(is.character(by.x) & is.null(by.y) & is.null(domain)){
estimation <- design_ech %>%
srvyr::group_by(.data[[by.x]], add = T) %>%
srvyr::summarise(colname = srvyr::survey_total(.data[[variable]]))
} else if(is.character(by.x) & is.character(by.y) & is.null(domain)){
estimation <- design_ech %>%
srvyr::group_by(.data[[by.x]], .data[[by.y]]) %>%
srvyr::summarise(colname = srvyr::survey_total(.data[[variable]]))
} else if(is.null(by.x) & is.null(by.y) & is.logical(domain)){
estimation <- design_ech %>%
srvyr::filter(domain) %>%
srvyr::summarise(colname = srvyr::survey_total(.data[[variable]]))
} else if(is.character(by.x) & is.null(by.y) & is.logical(domain)){
estimation <- design_ech %>%
srvyr::filter(domain) %>%
srvyr::group_by(.data[[by.x]]) %>%
srvyr::summarise(colname = srvyr::survey_total(.data[[variable]]))
} else {
estimation <- design_ech %>%
srvyr::filter(domain) %>%
srvyr::group_by(.data[[by.x]], .data[[by.y]]) %>%
srvyr::summarise(colname = srvyr::survey_total(.data[[variable]]))
}
return(estimation)
}
d = ech::toy_ech_2018
a <- get_estimation_total(variable = "pobre06", level = "h")
names(a)
a <- get_estimation_total(variable = "pobre06", level = "h", colname = "aaaa")
names(a)
get_estimation_total <- function(data = ech::toy_ech_2018,
variable = NULL,
by.x = NULL,
by.y = NULL,
domain = NULL,
level = NULL,
colname = "estimacion"){
# checks ----
assertthat::assert_that(!is.null(data) | !is.null(variable), msg = "Debe indicar la variable")
assertthat::assert_that(all(variable %in% names(data)), msg = glue::glue("La variable {variable} no esta en {data}"))
if(!is.null(by.x)) assertthat::assert_that(by.x %in% names(data), msg = glue::glue("La variable {by.x} no esta en {data}"))
if(!is.null(by.y)) assertthat::assert_that(by.y %in% names(data), msg = glue::glue("La variable {by.y} no esta en {data}"))
if(!is.null(level)) assertthat::assert_that(level %in% c("household", "h", "individual", "i"), msg = "Verifica el nivel seleccionado")
# design ----
design_ech <- ech::set_design(data = data, level = level)
# supressed warnings ---
options(survey.lonely.psu = "adjust")
options(dplyr.summarise.inform = FALSE)
# estimation ----
if(is.null(by.x) & is.null(by.y) & is.null(domain)){
estimation <- design_ech %>%
srvyr::summarise(.data[[colname]] = srvyr::survey_total(.data[[variable]]))
} else if(is.character(by.x) & is.null(by.y) & is.null(domain)){
estimation <- design_ech %>%
srvyr::group_by(.data[[by.x]], add = T) %>%
srvyr::summarise(.data[[colname]] = srvyr::survey_total(.data[[variable]]))
} else if(is.character(by.x) & is.character(by.y) & is.null(domain)){
estimation <- design_ech %>%
srvyr::group_by(.data[[by.x]], .data[[by.y]]) %>%
srvyr::summarise(.data[[colname]] = srvyr::survey_total(.data[[variable]]))
} else if(is.null(by.x) & is.null(by.y) & is.logical(domain)){
estimation <- design_ech %>%
srvyr::filter(domain) %>%
srvyr::summarise(.data[[colname]] = srvyr::survey_total(.data[[variable]]))
} else if(is.character(by.x) & is.null(by.y) & is.logical(domain)){
estimation <- design_ech %>%
srvyr::filter(domain) %>%
srvyr::group_by(.data[[by.x]]) %>%
srvyr::summarise(.data[[colname]] = srvyr::survey_total(.data[[variable]]))
} else {
estimation <- design_ech %>%
srvyr::filter(domain) %>%
srvyr::group_by(.data[[by.x]], .data[[by.y]]) %>%
srvyr::summarise(.data[[colname]] = srvyr::survey_total(.data[[variable]]))
}
return(estimation)
}
library(survey)
data(api)
dstrata <- apistrat %>%
as_survey_design(strata = stype, weights = pw)
library(srvyr)
library(survey)
data(api)
dstrata <- apistrat %>%
as_survey_design(strata = stype, weights = pw)
dstrata <- apistrat %>%
as_survey_design("strata" = stype, weights = pw)
dstrata <- apistrat %>%
as_survey_design("variable" = stype, weights = pw)
dstrata <- apistrat %>%
as_survey_design("strata" = stype, weights = pw)
dstrata %>%
summarise(api99 = survey_mean(api99)
)
dstrata %>%
summarise(estima = survey_mean(api99))
dstrata %>%
summarise("estima" = survey_mean(api99))
a <- get_estimation_total(variable = "pobre06", level = "h", colname = "aaaa")
expect_equal(nrow(a), 1)
a <- get_estimation_total(data = d, variable = "pobre06", domain = d$dpto == 1, level = "h")
expect_equal(nrow(a), 1)
library(testthat)
a <- get_estimation_total(data = d, variable = "pobre06", domain = d$dpto == 1, level = "h")
expect_equal(nrow(a), 1)
a <- get_estimation_total(data = d, variable = "pobre06", by.x = "mes", domain = d$dpto == 1, level = "h")
names(a)
nombres <- names(a)
str_replace_all(names(a), "colname", colname)
name <- "hogares_pobres"
str_replace_all(names(a), "colname", name)
stringr::str_replace_all(names(a), "colname", name)
install.packages("here")
# get_microdata(year = 2018, folder = tempdir(), toR = FALSE)
aaa <- read_microdata(path = here::here("/data/toy_ech_2018.rda"))
read_microdata <- function(path = NULL){
#stopifnot(is.character(filename))
if (!is.null(path)) {
format = tolower(fs::path_ext(path))
if (!format %in% c("sav", "dta", "rds", "rda", "rdata"))
stop(glue::glue("No es posible abrir un archivo con formato {format}"))
} else {
stop(glue::glue("No es posible abrir {path}"))
}
# read file
if(format == "sav"){
df <- haven::read_sav(path)
#haven::zap_labels() %>%  haven::zap_formats() %>%  haven::zap_label()
} else if(format == "dta"){
df <- haven::read_dta(path)
#haven::zap_labels() %>%  haven::zap_formats() %>%  haven::zap_label()
} else if (format == "rds"){
df <- readRDS(path)
} else{
load(path)
}
}
# get_microdata(year = 2018, folder = tempdir(), toR = FALSE)
aaa <- read_microdata(path = here::here("/data/toy_ech_2018.rda"))
# get_microdata(year = 2018, folder = tempdir(), toR = FALSE)
read_microdata(path = here::here("/data/toy_ech_2018.rda"))
# get_microdata(year = 2018, folder = tempdir(), toR = FALSE)
read_microdata(path = here::here("/data/toy_ech_2018.rda"))
read_microdata <- function(path = NULL){
#stopifnot(is.character(filename))
if (!is.null(path)) {
format = tolower(fs::path_ext(path))
if (!format %in% c("sav", "dta", "rds", "rda", "rdata"))
stop(glue::glue("No es posible abrir un archivo con formato {format}"))
} else {
stop(glue::glue("No es posible abrir {path}"))
}
# read file
if(format == "sav"){
df <- haven::read_sav(path)
#haven::zap_labels() %>%  haven::zap_formats() %>%  haven::zap_label()
} else if(format == "dta"){
df <- haven::read_dta(path)
#haven::zap_labels() %>%  haven::zap_formats() %>%  haven::zap_label()
} else if (format == "rds"){
df <- readRDS(path)
} else{
load(path)
}
}
# get_microdata(year = 2018, folder = tempdir(), toR = FALSE)
read_microdata(path = here::here("/data/toy_ech_2018.rda"))
path = here::here("/data/toy_ech_2018.rda")
# get_microdata(year = 2018, folder = tempdir(), toR = FALSE)
read_microdata(path = here::here("data/toy_ech_2018.rda"))
path = here::here("data/toy_ech_2018.rda")
if (!is.null(path)) {
format = tolower(fs::path_ext(path))
if (!format %in% c("sav", "dta", "rds", "rda", "rdata"))
stop(glue::glue("No es posible abrir un archivo con formato {format}"))
} else {
stop(glue::glue("No es posible abrir {path}"))
}
# read file
if(format == "sav"){
df <- haven::read_sav(path)
#haven::zap_labels() %>%  haven::zap_formats() %>%  haven::zap_label()
} else if(format == "dta"){
df <- haven::read_dta(path)
#haven::zap_labels() %>%  haven::zap_formats() %>%  haven::zap_label()
} else if (format == "rds"){
df <- readRDS(path)
} else{
load(path)
}
path = paste0(fs::path_wd,"data/toy_ech_2018.rda"
)
fs::path_package()
fs::path_package(ech)
fs::path_package("ech")
path = paste0(fs::path_package("ech"),"data/toy_ech_2018.rda")
covr::codecov()
archivo <- fs::dir_ls(folder, regexp = "\\.rda$")
archivo <- fs::dir_ls(getwd(), regexp = "\\.rda$")
get_microdata(year = 2016, folder = tempdir(), toR = FALSE)
get_microdata <- function(year = NULL,
folder = tempdir(),
toR = TRUE){
# checks ----
stopifnot(is.numeric(year) | is.null(year) | length(year) <= 1)
if (!is.character(folder) | length(folder) != 1) {
message(glue::glue("Debe ingresar un directorio..."))
}
if (length(fs::dir_ls(folder, regexp = "\\.rar$")) != 0) {
message(glue::glue("Existen en la carpeta otros archivos .rar que se van a leer..."))
}
# download ----
try(dir.create(folder))
all_years <- 2011:2019
if (!is.null(year) & any(year %in% all_years) == FALSE) {
stop("Por el momento ech solo funciona con microdatos de 2011 a 2019")
}
if (is.null(year)) {
year <- max(all_years)
}
urls <- data.frame(yy = 2011:2019,
md_sav = fs::path("www.ine.gub.uy/c/document_library",
c("get_file?uuid=cc986929-5916-4d4f-a87b-3fb20a169879&groupId=10181",
"get_file?uuid=144daa3d-0ebf-4106-ae11-a150511addf9&groupId=10181",
"get_file?uuid=9ddf38cc-99bb-4196-992b-77530b025237&groupId=10181",
"get_file?uuid=68cc1d11-e017-4a6d-a749-5a1e1a4a5306&groupId=10181",
"get_file?uuid=7c62ef78-0cc6-4fba-aae4-921ff5ceddd6&groupId=10181",
"get_file?uuid=715c873b-539f-4e92-9159-d38063270951&groupId=10181",
"get_file?uuid=e38ea53c-7253-4007-9f67-2f5f161eea91&groupId=10181",
"get_file?uuid=b63b566f-8d11-443d-bcd8-944f137c5aaf&groupId=10181",
"get_file?uuid=8c934d2a-ad67-4208-8f21-96989696510e&groupId=10181"
)),
dic = fs::path("www.ine.gub.uy/c/document_library",
c("get_file?uuid=54523778-5f53-4df1-a265-3ff520941bca&groupId=10181",
"get_file?uuid=8e8963a6-b9f2-47f3-abf5-119f988ad868&groupId=10181",
"get_file?uuid=055d37e5-d587-4ba7-8a0d-358cd99a9e24&groupId=10181",
"get_file?uuid=9c9612fd-3bc3-47c5-a684-06daaf25da6c&groupId=10181",
"get_file?uuid=6287d12b-1003-4402-86ba-a48866743d88&groupId=10181",
"get_file?uuid=54f72e41-e671-4bea-993c-631596e16883&groupId=10181",
"get_file?uuid=b60f247b-03cb-4bb1-b84b-5d7328479fe2&groupId=10181",
"get_file?uuid=73b6cc21-1bb0-483b-a463-819315b5fff3&groupId=10181",
"get_file?uuid=800e3c63-5cbc-4842-ad00-745f801f9220&groupId=10181")),
file = paste0(folder, "/ech_", all_years, "_sav.rar"),
stringsAsFactors = FALSE)
links <- urls %>% dplyr::filter(.data$yy %in% year)
u <- links$md_sav
f <- links$file
y <- links$yy
if (!file.exists(f)) {
message(glue::glue("Intentando descargar ECH {y}..."))
try(utils::download.file(u, f, mode = "wb", method = "libcurl"))
} else {
message(glue::glue("ECH {y} ya existe, se omite la descarga"))
}
# read----
archivo <- fs::dir_ls(folder, regexp = "\\.rar$")
archivo <- archivo[which.max(file.info(archivo)$mtime)]
ext <- fs::path_ext(archivo)
compressed_formats <- c("zip", "rar")
uncompressed_formats <- "sav"
if (ext %in% c(compressed_formats, uncompressed_formats) != TRUE) {
formats_string <- paste(c(compressed_formats, uncompressed_formats[length(uncompressed_formats) - 1]),
collapse = ", ")
formats_string <- paste(c(formats_string, uncompressed_formats[length(uncompressed_formats)]),
collapse = " o ")
stop(glue::glue("Los metadatos de {archivo} indica que este archivo no sirve.
Asegurate de que el formato es {formats_string}."))
}
if (ext %in% compressed_formats) {
message(glue::glue("Los metadatos de {archivo} indican que el formato comprimido es adecuado,
intentando leer..."))
try(archive_extract(archive.path = archivo, dest.path = folder))
descomprimido <- fs::dir_ls(folder, regexp = "\\.sav$")
descomprimido <- descomprimido[(stringr::str_detect(descomprimido, "HyP") == T |
stringr::str_detect(descomprimido, "Fusionado") == T) &
stringr::str_detect(descomprimido, as.character(year)) == T]
d <- try(haven::read_sav(descomprimido))
}
if (ext %in% uncompressed_formats) {
message(glue::glue("Los metadatos de {archivo} indican que el formato no comprimido es adecuado,
intentando leer..."))
d <- haven::read_sav(archivo)
}
if (any(class(d) %in% "data.frame")) {
message(glue::glue("{archivo} se pudo leer como tibble :-)"))
d <- janitor::clean_names(d)
} else {
stop(glue::glue("{archivo} no se pudo leer como tibble :-("))
}
# save ----
if (isTRUE(toR)) {
saveRDS(d, file = fs::path(folder, paste0("ECH_", year, ".Rds")))
message(glue::glue("Se ha guardado el archivo en formato R"))
sav <- fs::dir_ls(folder, regexp = "\\.sav$")
fs::file_delete(archivo)
fs::file_delete(sav)
}
return(d)
}
get_microdata(year = 2016, folder = tempdir(), toR = FALSE)
get_microdata(year = 2018, folder = tempdir(), toR = FALSE)
library(ech)
get_microdata(year = 2016, folder = tempdir(), toR = FALSE)
geouy::load_geouy("Localidades")
geouy::load_geouy("Localidades_pg")
loc <- geouy::load_geouy("Localidades pg")
a <- cranlogs::cran_downloads("geouy", from = "2020-05-01", to = "2020-07-13")
b <- cranlogs::cran_downloads("chilemapas", from = "2020-05-01", to = "2020-07-13")
c <- cranlogs::cran_downloads("eph", from = "2020-05-01", to = "2020-07-13")
d <- cranlogs::cran_downloads("casen", from = "2020-05-01", to = "2020-07-13")
e <- cranlogs::cran_downloads("speech", from = "2020-05-01", to = "2020-07-13")
abc <- rbind(a,b,c,d, e)
ggplot2::ggplot(data = abc, ggplot2::aes(x=date, y=count, col=package) ) + ggplot2::geom_line()
dic <- ech::dic
View(dic[, c(1:3,5,17,18)])
dic <- edit(dic)
dic <- edit(dic)
View(dic[, c(1:3,5,17,18)])
save(dic, file = "C:/Users/Usuario/Desktop/R/ech/data/dic.rda")
View(dic[, c(1:3,5,17,18)])
dic <- ech::dic
View(dic[, c(1:3,5,17,18)])
load("C:/Users/Usuario/Desktop/R/ech/data/dic.rda")
View(dic[, c(1:3,5,17,18)])
dic <- edit(dic)
dic2 <- rbind(dic[1:270,],dic[271],dic[271:973])
dic2 <- rbind(dic[1:270,],dic[271,],dic[271:973,])
dic <- edit(dic2)
dic <- rbind(dic[1:360,],dic[360,],dic[360:973,])
dic <- edit(dic)
dic <- rbind(dic[-360,],dic2[974,])
dic <- edit(dic)
save(dic, file = "C:/Users/Usuario/Desktop/R/ech/data/dic.rda")
usethis::use_data(loc_agr_ine)
usethis::use_data(dic)
usethis::use_data(dic, overwrite = T)
a <- cranlogs::cran_downloads("geouy", from = "2020-05-01", to = "2020-07-13")
b <- cranlogs::cran_downloads("chilemapas", from = "2020-05-01", to = "2020-07-13")
c <- cranlogs::cran_downloads("eph", from = "2020-05-01", to = "2020-07-13")
d <- cranlogs::cran_downloads("casen", from = "2020-05-01", to = "2020-07-13")
e <- cranlogs::cran_downloads("speech", from = "2020-05-01", to = "2020-07-13")
abc <- rbind(a,b,c,d, e)
ggplot2::ggplot(data = abc, ggplot2::aes(x=date, y=count, col=package) ) + ggplot2::geom_line()
a <- cranlogs::cran_downloads("geouy", from = "2020-05-01", to = "2020-07-16")
b <- cranlogs::cran_downloads("chilemapas", from = "2020-05-01", to = "2020-07-16")
c <- cranlogs::cran_downloads("eph", from = "2020-05-01", to = "2020-07-16")
d <- cranlogs::cran_downloads("casen", from = "2020-05-01", to = "2020-07-16")
e <- cranlogs::cran_downloads("speech", from = "2020-05-01", to = "2020-07-16")
abc <- rbind(a,b,c,d, e)
ggplot2::ggplot(data = abc, ggplot2::aes(x=date, y=count, col=package) ) + ggplot2::geom_line()
covr::codecov()
a <- gini()
library(ech)
a <- gini()
data = ech::toy_ech_2018
data %<>% filter(.data$nper == 1)
library(magrittr)
library(dplyr)
data %<>% filter(.data$nper == 1)
data <- income_constant_prices(data = data, base.month = 1, base.year = 2005)
data <- income_constant_prices(data = data, base_month = 1, base_year = 2005)
library(ech)
a <- gini()
data %<>% mutate(ypcsvl_deflate_gini = .data$ht11_svl_per_capita_deflate) %>%
select(-.data$ht11_per_capita:-.data$ht11_per_capita_deflate) # ver como no sobreescribir
weights = "pesoano";
domain = NULL
data <- income_constant_prices(data = data, base_month = 1, base_year = 2005)
data <- income_constant_prices(data = data, base_month = "01", base_year = 2005)
ipc = "G"
df_year = NULL
base_month = 1; base_year = 2005
if (ipc == "G") {
df <- ech::ipc_base2010
}  else if (ipc == "M"){
df <- ech::ipc_base2010_mdeo
} else {
df <- ech::ipc_base2010_int
}
mes_base <- df %>%
dplyr::filter(.data$fecha == paste0(base_year, "-", base_month, "-01")) %>%
dplyr::select(.data$indice) %>% as.numeric
rows1 <- which(df$fecha == paste0(df_year - 1, "-",12, "-01"))
rows2 <- which(df$fecha == paste0(df_year, "-",11, "-01"))
gini <- function(data = ech::toy_ech_2018,
df_year = 2018,
weights = "pesoano",
domain = NULL) {
data %<>% filter(.data$nper == 1)
# ipc montevideo
data <- income_constant_prices(data = data, base_month = 1, base_year = 2005, df_year = df_year)
data %<>% mutate(ypcsvl_deflate_gini = .data$ht11_svl_per_capita_deflate) %>%
select(-.data$ht11_per_capita:-.data$ht11_per_capita_deflate) # ver como no sobreescribir
# ipc interior
if (is.null(domain)) {
indice <- laeken::gini(inc = data$ypcsvl_deflate_gini, weights = pull(data[,weights]))
} else {
indice <- laeken::gini(data$ypcsvl_deflate_gini, weights = pull(data[,weights]), breakdown = pull(data[,domain]))
}
# ver como llenar los slots de indice...
return(indice)
}
a <- gini()
