Adds a six-digit ubigeo with its department, province and
department_name. It takes an existing ubigeo column, or builds one from
INEI's separate codes (CCDD, CCPP, CCDI), as in the ENA. Codes are
always text padded to six digits, because INEI's CSV files drop the
leading zero (10101 is 010101).
Argumentos
- data
A data frame.
- var
Name of the ubigeo column. If
NULL, it looks forubigeoand then forccdd,ccppandccdi(any case).- year
Year the data were collected. Needed for
base, and used to flag codes that did not exist that year. Years outside 2004-2025 are moved to the nearest end of the table, with a warning.- base
Year whose coding you want, usually
2017.
Detalles
The codes are INEI's. RENIEC and SUNAT number districts differently
(INEI puts Callao in 07, RENIEC in 24), so do not mix them.
With year and base, it also translates the codes from the coding used
in year to the coding used in base. The natural base is 2017: the
1874 districts of the 2017 Census, the frame of every INEI survey since
2018. The translation follows, and only follows:
the recodings INEI made when it created the provinces of Datem del Maranon (2006) and Putumayo (2015), and the Bagua and La Peca swap of 2007, as seen in RENAMU 2004-2025;
for districts created after 2017, the 2017 district that holds their schools in MINEDU's 2025 school register. This crosswalk has not been checked law by law yet.
Nothing else is guessed. Districts created between 2005 and 2017 have no
known parent, and Lambras and Santa Lucia have two, so they get NA.
Sources and method are in system.file("ubigeo", "README.md", package = "faperu").
ubigeo_status is one of:
"same": the code means the same district in both years."recoded": same district, new code."recoded_partial": same name, new code, but the new province also got new districts at the time, so the old district may have been larger."area_changed": same code, but a district was carved out of it between the two years (from the 2017 crosswalk)."to_parent": a district created afterbase, given the code of the district it came from."multi_parent": created afterbaseout of two districts;NA."created_after_base": created afterbase, parent unknown;NA."legacy": an old code INEI surveys used that matches no district (ENAHO's120699);NA."unknown": not a district inyear;NA.
Ejemplos
fa_ubigeo(data.frame(UBIGEO = c("210101", "150101")))
#> UBIGEO ubigeo department province department_name
#> 1 210101 210101 21 2101 Puno
#> 2 150101 150101 15 1501 Lima
fa_ubigeo(data.frame(CCDD = "21", CCPP = "01", CCDI = "01"))
#> CCDD CCPP CCDI ubigeo department province department_name
#> 1 21 01 01 210101 21 2101 Puno
fa_ubigeo(data.frame(ubigeo = c("130112", "160109")), year = 2024, base = 2017)
#> Warning: 1 distinct codes are not in the INEI district list for 2024.
#> ubigeo department province department_name ubigeo_base ubigeo_status
#> 1 130112 13 1301 La Libertad 130102 to_parent
#> 2 160109 16 1601 Loreto 160801 recoded_partial
