Appends housing variables from a household-level source to a person-level ENEMDU source using a controlled household-key match. The function preserves the number and order of person rows. It only joins sources; it does not derive NBI components and does not validate official estimates.
Usage
enemdu_join_nbi_sources(
person_data,
household_data,
household_id = "id_hogar",
housing_vars = c("vi04a", "vi05a", "vi07", "vi09", "vi10", "vi10a"),
overwrite = FALSE,
strict = TRUE
)Arguments
- person_data
Person-level ENEMDU data.
- household_data
Household- or housing-level ENEMDU data.
- household_id
Household identifier used in both sources.
- housing_vars
Housing variables to append from
household_data.- overwrite
Logical. If
TRUE, replace existinghousing_varsinperson_data.- strict
Logical. If
TRUE, abort when a non-missing household inperson_datahas no match inhousehold_data. IfFALSE, unmatched person rows are preserved and receiveNAhousing values.
Examples
person <- tibble::tibble(
id_hogar = c("h1", "h1", "h2"),
p01 = c(1, 2, 1),
p03 = c(40, 8, 45)
)
household <- tibble::tibble(
id_hogar = c("h1", "h2"),
vi04a = c(7, 1),
vi05a = c(1, 6),
vi07 = c(0, 1),
vi09 = c(5, 1),
vi10 = c(1, 2),
vi10a = c(1, 3)
)
joined <- enemdu_join_nbi_sources(person, household)
joined$vi04a
#> [1] 7 7 1