3.1 Estimation Procedure
This code utilizes the libraries tidyverse and magrittr for data processing and analysis.
The function readRDS() is used to load a data file in RDS format, containing direct estimates and smoothed variance for the proportion of individuals in poverty for the year 2018. Subsequently, the %>% operator from the magrittr library is employed to chain the selection of specific columns, namely dam2, nd, pobreza, vardir, and hat_var.
library(tidyverse)
library(magrittr)
base_FH <- readRDS("Recursos/03_FH_normal/01_base_FH.Rds") %>%
select(dam2,pobreza,hat_var)Reading the covariates, which have been previously obtained. Due to the difference in scales between variables, an adjustment is necessary.
statelevel_predictors_df <- readRDS('Recursos/03_FH_normal/02_statelevel_predictors_dam.rds') %>%
mutate(id_order = 1:n())Next, a full join (full_join) is performed between the dataset base_FH and the predictors statelevel_predictors_df using the variable dam2 as the joining key.
The function tba() is used to display the first 10 rows and 8 columns of the resulting dataset from the previous join.
A full join (full_join) combines data from both datasets, preserving all rows from both and filling in missing values (NA) if matches aren’t found based on the joining variable (dam2 in this case).
The tba() function displays an HTML-formatted table in the R console showing the first 10 rows and 8 columns of the resulting dataset from the join.
| dam2 | pobreza | hat_var | area1 | sex2 | age2 | age3 | age4 |
|---|---|---|---|---|---|---|---|
| 0101 | NA | NA | 1.0000 | 0.5087 | 0.2694 | 0.2297 | 0.1689 |
| 0102 | 0.9836 | 0 | 1.0000 | 0.4754 | 0.2857 | 0.2261 | 0.1527 |
| 0103 | 1.0000 | 0 | 1.0000 | 0.5037 | 0.3095 | 0.2015 | 0.1312 |
| 0201 | NA | NA | 0.5147 | 0.5060 | 0.2962 | 0.2090 | 0.1844 |
| 0202 | 0.9391 | 0 | 0.9986 | 0.5376 | 0.2625 | 0.2226 | 0.2238 |
| 0203 | 0.8117 | 0 | 0.9754 | 0.5432 | 0.2454 | 0.2254 | 0.2388 |
| 0204 | NA | NA | 1.0000 | 0.5300 | 0.3151 | 0.2022 | 0.2034 |
| 0205 | 0.9646 | 0 | 1.0000 | 0.5182 | 0.3057 | 0.2286 | 0.1981 |
| 0206 | NA | NA | 1.0000 | 0.5157 | 0.3192 | 0.1959 | 0.1552 |
| 0207 | NA | NA | 1.0000 | 0.5097 | 0.3099 | 0.1966 | 0.1691 |