View source: R/fetch-sidra-population.R
| fetch_monthly_population | R Documentation |
Downloads population estimates from IBGE SIDRA API (table 6022) and transforms from moving-quarter to exact monthly values.
fetch_monthly_population(
start_yyyymm = NULL,
end_yyyymm = NULL,
verbose = TRUE,
use_cache = FALSE,
cache_max_age_hours = 24
)
start_yyyymm |
Integer. First month to include (YYYYMM format). If NULL, returns all available months. |
end_yyyymm |
Integer. Last month to include (YYYYMM format). If NULL, returns all available months. |
verbose |
Logical. Print progress messages? Default TRUE. |
use_cache |
Logical. If TRUE, uses cached data if available and not expired. Default FALSE (always fetch fresh data for consistency). Set to TRUE for faster repeated calls during development. |
cache_max_age_hours |
Numeric. Maximum cache age in hours before automatic expiration when use_cache=TRUE. Default 24 hours. |
SIDRA table 6022 provides moving-quarter population estimates. Each value represents the 3-month average centered on the middle month. For example, the value for code 201203 (quarter ending March 2012) represents the population for February 2012.
This function:
Fetches raw moving-quarter data from SIDRA
Transforms to exact monthly values by aligning with middle months
Extrapolates boundary months (first and last) using quadratic regression
The extrapolation uses quadratic regression on population differences to estimate the first month (Jan 2012) and the most recent month.
A data.table with columns:
ref_month_yyyymm: Integer in YYYYMM format
m_populacao: Monthly population in thousands
This function requires the sidrar package for API access.
Install with: install.packages("sidrar")
pnadc_apply_periods which uses this function when
calibrate = TRUE
pop <- fetch_monthly_population()
pop <- fetch_monthly_population(201301, 201912)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.