Skip to content

Commit

Permalink
v0.0.1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
calcita committed Aug 23, 2020
1 parent 82277b4 commit 1cffca5
Show file tree
Hide file tree
Showing 54 changed files with 479 additions and 159 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export(overcrowding)
export(poverty)
export(read_microdata)
export(set_design)
export(underemployment)
export(unlabelled)
export(unsatisfied_basic_needs)
export(years_of_schooling)
Expand Down
2 changes: 1 addition & 1 deletion R/add_geom.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' add_geom
#' This function allows you to add geom variable to a with a code varible of "zona", "barrio", "localidad", "segmentos", "secciones" or "departamentos".
#' @description This function allows you to add a geom variable with a code variable of "zona", "barrio", "localidad", "segmentos", "secciones" or "departamentos".
#'
#' @param data data.frame
#' @param unit spatial unit of data, may be: "Departamentos", "Secciones", "Secc MVD 2004", "Segmentos", "Segm MVD 2004", "Segm URB INT 2004", "Zonas", "Zonas MVD 2004", "Zonas URB INT 2004", "Localidades pg", "Municipios" o "Barrios".
Expand Down
22 changes: 14 additions & 8 deletions R/dwelling.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' housing_deprivation
#' This function allows you to calculate the housing status
#' @description This function allows you to calculate the housing status
#'
#' @param data data.frame
#' @param n number of deprivations to consider. Default 1
Expand Down Expand Up @@ -117,13 +117,15 @@ housing_deprivation <- function(data = ech::toy_ech_2018,
electricity (Carencia: Red electrica);
housing_deprivation_q (Suma de carencias habitacionales) &
housing_deprivation (Carencia habitacional en relacion al parametro n)")
data

return(data)

}



#' housing_situation
#' A function to calculate the housing situation
#' @description This function allows you to calculate the housing situation
#'
#' @param data data.frame
#' @param c5_1 Variable name of roof condensation
Expand Down Expand Up @@ -197,7 +199,7 @@ housing_situation <- function(data = ech::toy_ech_2018,


#' housing_conditions
#' A function to calculate the housing conditions
#' @description This function allows you to calculate the housing conditions
#'
#' @param data data.frame
#' @param c2 Variable name of predominant material on external walls
Expand Down Expand Up @@ -242,7 +244,7 @@ housing_conditions <- function(data = ech::toy_ech_2018,
}

#' overcrowding
#' A function to calculate overcrowding in the household
#' @description This function allows you to calculate overcrowding in the household
#'
#' @param data data.frame
#' @param ht19 Variable name of umber of individuals in the household
Expand Down Expand Up @@ -275,12 +277,14 @@ overcrowding <- function(data = ech::toy_ech_2018,
overcrowding = haven::labelled(overcrowding, labels = c("Hacinado" = 1, "No hacinado" = 0),
label = "Hacinamiento"))
message("A variable has been created: \n \t overcrowding (hacinamiento)")
data

return(data)

}


#' housing_tenure
#' A function to calculate the housing tenure
#' @description This function allows you to calculate the housing tenure
#'
#' @param data data.frame
#' @param d8_1 Variable name of housing_tenure (owner, renter, rent-free occupancy, etc.)
Expand Down Expand Up @@ -315,5 +319,7 @@ housing_tenure <- function(data = ech::toy_ech_2018,


message("A variable has been created: \n \t housing_tenure (tenencia de la vivienda)")
data

return(data)

}
17 changes: 8 additions & 9 deletions R/education.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#' enrolled_school
#' A function to calculate people enrolled in school
#' @description This function allows you to calculate the people enrolled in school
#'
#' This function allows you to calculate people enrolled in school
#' @param data data.frame with necessary variables Defaults to ech.
#' @param e193 Variable name of attendance school
#' @param e197 Variable name of attendance primary
Expand Down Expand Up @@ -70,7 +69,7 @@ enrolled_school <- function(data = ech::toy_ech_2018,
}

#' years_of_schooling
#' A function to calculate the years of schooling
#' @description This function allows you to calculate the years of schooling
#'
#' @param data data.frame
#' @param e193 Variable name of attendance school
Expand Down Expand Up @@ -177,13 +176,13 @@ years_of_schooling <- function(data = ech::toy_ech_2018,
}

message("A variable has been created: \n \t years_schooling (anios de escolaridad)")
data
return(data)
}



#' level_education
#' A function to calculate the highest level of education achieved
#' @description This function allows you to calculate the highest level of education achieved
#'
#' @param data data.frame
#' @param e51_2 Variable name of years passed in primary
Expand Down Expand Up @@ -262,14 +261,14 @@ level_education <- function(data = ech::toy_ech_2018,
labels = c("Sin instruccion" = 0, "Primaria" = 1, "Secundaria" = 2, "UTU" = 3, "Magisterio o profesorado" = 4, "Universidad o similar" = 5),
label = "Nivel educativo")
)
message("A variable has been created: \n \t level_education (nivel educativo)")
data
message("A variable has been created: \n \t highest level_education achieved (maximo nivel educativo alcanzado)")
return(data)
}



#' level_completion
#' A function to calculate the level of school completion
#' @description This function allows you to calculate the level of school completion
#'
#' @param data data.frame
#' @param e197 Variable name of attends primary school
Expand Down Expand Up @@ -333,5 +332,5 @@ level_completion <- function(data = ech::toy_ech_2018,
message("Variables have been created: \n \t primary_completion (primaria completa);
lower_secondary_completion (ciclo basico completo) &
upper_secondary_completion (bachillerato completo)")
data
return(data)
}
65 changes: 61 additions & 4 deletions R/employment.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' employment
#' This function allows you to calculate the variables: PEA, PET, PO, PD
#' @description This function allows you to calculate the variables: PEA, PET, PO, PD
#'
#' @param data data.frame with microdata
#' @param pobpcoac Variable name of definition of population by activity status. Default: "pobpcoac"
Expand Down Expand Up @@ -28,7 +28,15 @@ employment <- function(data = ech::toy_ech_2018,
data <- data %>% dplyr::mutate(pea = ifelse(pobpcoac %in% 2:5, 1, 0),
pet = ifelse(pobpcoac != 1, 1, 0),
po = ifelse(pobpcoac == 2, 1, 0),
pd = ifelse(pobpcoac %in% 3:5, 1, 0)
pd = ifelse(pobpcoac %in% 3:5, 1, 0),
pea = haven::labelled(pea, labels = c("Si" = 1, "No" = 0),
label = "Poblacion economicamente activa"),
pet = haven::labelled(pet, labels = c("Si" = 1, "No" = 0),
label = "Poblacion en edad de trabajar"),
po = haven::labelled(po, labels = c("Si" = 1, "No" = 0),
label = "Poblacion ocupada"),
pd = haven::labelled(pd, labels = c("Si" = 1, "No" = 0),
label = "Poblacion desocupada")
)

message("Variables have been created: \n \t pea (Poblacion economicamente activa);
Expand All @@ -38,15 +46,63 @@ employment <- function(data = ech::toy_ech_2018,
return(data)
}

#' underemployment
#' @description This function allows you to identify underemployed people
#'
#' @param data data.frame
#' @param pobpcoac Variable name of definition of population by activity status. Default: "pobpcoac"
#' @param f85 Variable name of number of hours worked in the main job
#' @param f98 Variable name of Number of hours worked at the secondary job
#' @param f101 Variable name of reasons why you want another job
#' @param f102 Variable name of want to work more hours
#' @param f103 Variable name of are available to work more hours at this time
#' @param f104 Variable name of reasons why you dont work more hours
#'
#' @importFrom dplyr mutate case_when
#' @importFrom haven labelled
#' @return data.frame
#' @export
#' @details
#' Disclaimer: This script is not an official INE product.
#' Aviso: El script no es un producto oficial de INE.
#'
#' @examples
#' toy_ech_2018 <- underemployment(data = ech::toy_ech_2018)
#'
underemployment <- function(data = ech::toy_ech_2018,
pobpcoac = "pobpcoac",
f85 = "f85",
f98 = "f98",
f101 = "f101",
f102 = "f102",
f103 = "f103",
f104 = "f104"){

data <- data %>% dplyr::mutate(underemployment = dplyr::case_when(pobpcoac == 2 & (f85 + f98 < 40) & (f101 == 1 | f102 == 1) & (f103 == 1) & (f104 == 5) ~ 1,
TRUE ~ 0),
underemployment = haven::labelled(underemployment, labels = c("Si" = 1, "No" = 0), label = "Poblacion subempleada")
)

message("A variable has been created: \n \t underemployment (Poblacion subempleada)")
return(data)

}
#' employment_restrictions
#'
#' @description This function allows you to identify workers with employment restrictions
#' @param data data.frame
#' @param f82 Variable name of
#' @param underemployment Variable name of
#' @param f82 Variable name of contribution to the pension fund
#' @param underemployment Variable name of underemployment
#'
#' @return data.frame
#' @export
#' @details
#' Disclaimer: This script is not an official INE product.
#' Aviso: El script no es un producto oficial de INE.
#'
#' @examples
#' toy_ech_2018 <- underemployment(data = ech::toy_ech_2018)
#' toy_ech_2018 <- employment_restrictions(data = toy_ech_2018)
#'
employment_restrictions <- function(data = ech::toy_ech_2018,
f82 = "f82",
Expand All @@ -67,6 +123,7 @@ employment_restrictions <- function(data = ech::toy_ech_2018,

#' branch_ciuu
#'
#' @description This function allows you to identify activity branches
#' @param data data.frame
#' @param f72_2 Variable name of ciiu code rev.4
#' @param group logical to define 12 or 18 categories, if FALSE code 18. Default: TRUE
Expand Down
2 changes: 1 addition & 1 deletion R/get_dictionary.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' get_dictionary
#' Download ECH dictionaries from INE website
#' @description This function allows you to download ECH dictionaries from INE website
#'
#' @param year allows download data from 2011 to 2019. Default the last year
#' @param folder Folder where are the files or be download
Expand Down
13 changes: 7 additions & 6 deletions R/get_estimation.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' get_estimation_mean
#'
#' This function allows you to estimate mean variable at universe level.
#' @description This function allows you to estimate mean variable at universe level.
#'
#' @param data data frame with ECH microdata
#' @param variable data frame column to estimate
#' @param by.x data frame column
Expand Down Expand Up @@ -139,7 +140,7 @@ get_estimation_mean <- function(data = ech::toy_ech_2018,

#' get_estimation_total
#'
#' This function allows you to estimate total variable at universe level.
#' @description This function allows you to estimate total variable at universe level.
#' @param data data frame with ECH microdata
#' @param variable data frame column to estimate
#' @param by.x data frame column
Expand Down Expand Up @@ -278,7 +279,7 @@ get_estimation_total <- function(data = ech::toy_ech_2018,

#' get_estimation_ratio
#'
#' This function allows you to estimate ratio variable at universe level.
#' @description This function allows you to estimate ratio variables at universe level.
#' @param data data frame with ECH microdata
#' @param variable.x data frame column to estimate
#' @param variable.y data frame column to estimate
Expand Down Expand Up @@ -388,6 +389,7 @@ get_estimation_ratio <- function(data = ech::toy_ech_2018,

#' get_estimation_gini
#'
#' @description This function allows you to estimate the Gini coeficient
#' @param data ech data frame
#' @param variable income without rental value per capita deflated
#' @param by variable
Expand All @@ -406,9 +408,9 @@ get_estimation_ratio <- function(data = ech::toy_ech_2018,
#'
#' @examples
#' \donttest{
#' df <- income_constant_prices(data = ech::toy_ech_2018, ipc = "R",
#' toy_ech_2018 <- income_constant_prices(data = ech::toy_ech_2018, ipc = "R",
#' base_month = "01", base_year = "2005")
#' get_estimation_gini(data = df, level = "h")
#' get_estimation_gini(data = toy_ech_2018, level = "h")
#' }
#
get_estimation_gini <- function(data = ech::toy_ech_2018,
Expand All @@ -421,7 +423,6 @@ get_estimation_gini <- function(data = ech::toy_ech_2018,
pesoano = "pesoano",
name = "estimacion"){


# design ---
design_ech <- ech::set_design(data = data, level = level)

Expand Down
6 changes: 3 additions & 3 deletions R/get_microdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ archive_extract <- function(archive.path = NULL, dest.path = NULL) {
#### get_microdata ####

#' get_microdata
#' Download and read ECH from INE website
#' @description This function allows you to download and read ECH from INE website
#'
#' @param year allows download data from 2011 to 2019. Default the last year
#' @param folder Folder where are the files or be download
Expand Down Expand Up @@ -286,7 +286,7 @@ get_microdata <- function(year = NULL,
#### read_microdata ####

#' read_microdata
#' Read ECH from a local folder
#' @description This function allows you to read ECH from a local folder
#'
#' @param path Folder where are the files or be download
#' @importFrom fs path
Expand Down Expand Up @@ -340,7 +340,7 @@ read_microdata <- function(path = NULL){

#' get_marco
#'
#' Download and read ECH from INE website
#' @description This unction allows you to download and read the sampling frame from INE website
#' @param year allows download data of 2011, 2004, 1996 or 1985. Default 2011
#' @param folder Folder where are the files or be download
#' @param toR write data frame in R format and delete download file and unpack files
Expand Down
5 changes: 3 additions & 2 deletions R/household_type.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' household_type
#' This function allows you to calculate the household type for each household in the survey. A household is composed of one or more people who occupy a housing unit.
#' @description This function allows you to calculate the household type for each household in the survey. A household is composed of one or more people who occupy a housing unit.
#'
#' @param data data frame with ECH microdata
#' @param numero Variable name of household id
Expand Down Expand Up @@ -75,5 +75,6 @@ household_type <- function(data = ech::toy_ech_2018,

data <- data %>% dplyr::select(everything(), -.data$sex_householder:-.data$no_rel)
message("A variable has been created: \n \t household_type (Tipo de hogar)")
data
return(data)

}
8 changes: 5 additions & 3 deletions R/income.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ income_quantiles <- function(data = ech::toy_ech_2018,

#' labor_income_per_capita
#'
#' @description This function allows you to calculate the labor income per capita
#' @param data data frame
#' @param numero Variable name of household id
#' @param pobpcoac Variable name of definition of population by activity status
Expand Down Expand Up @@ -293,13 +294,14 @@ labor_income_per_capita <- function(data = ech::toy_ech_2018,

message("Variables have been created: \n \t labor_income (Ingresos laborales) &
labor_income_h (Ingresos laborales del hogar) &
labor_income_h_percapita (Ingresos laborales del hogar per capita)")
labor_income_h_percapita (Ingresos laborales per capita)")
return(data)
}


#' labor_income_per_hour
#'
#' @description This function allows you to calculate the labor income per hour
#' @param data data frame
#' @param numero Variable name of household id
#' @param f85 Variable name of hours worked per week
Expand All @@ -319,8 +321,8 @@ labor_income_per_capita <- function(data = ech::toy_ech_2018,
#'
#' @examples
#' \donttest{
#' df <- ech::toy_ech_2018
#' toy_ech_2018 <- labor_income_per_hour(data = df, base_month = "06", base_year = "2018")
#' toy_ech_2018 <- ech::toy_ech_2018
#' toy_ech_2018 <- labor_income_per_hour(data = toy_ech_2018, base_month = "06", base_year = "2018")
#' }
#'
labor_income_per_hour <- function(data = ech::toy_ech_2018,
Expand Down
Loading

0 comments on commit 1cffca5

Please sign in to comment.