Skip to contents

Downloads population estimates from IBGE SIDRA API (table 6022) and transforms from moving-quarter to exact monthly values.

Usage

fetch_monthly_population(
  start_yyyymm = NULL,
  end_yyyymm = NULL,
  verbose = TRUE,
  use_cache = FALSE,
  cache_max_age_hours = 24
)

Arguments

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.

Value

A data.table with columns:

  • ref_month_yyyymm: Integer in YYYYMM format

  • m_populacao: Monthly population in thousands

Details

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:

  1. Fetches raw moving-quarter data from SIDRA

  2. Transforms to exact monthly values by aligning with middle months

  3. 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.

Dependencies

This function requires the sidrar package for API access. Install with: install.packages("sidrar")

See also

pnadc_apply_periods which uses this function when calibrate = TRUE

Examples

if (FALSE) { # \dontrun{
# Fetch all available months
pop <- fetch_monthly_population()

# Fetch specific date range
pop <- fetch_monthly_population(201301, 201912)
} # }