% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fetch-sidra-population.R
\name{fetch_monthly_population}
\alias{fetch_monthly_population}
\title{Fetch Monthly Population from SIDRA}
\usage{
fetch_monthly_population(
  start_yyyymm = NULL,
  end_yyyymm = NULL,
  verbose = TRUE,
  use_cache = FALSE,
  cache_max_age_hours = 24
)
}
\arguments{
\item{start_yyyymm}{Integer. First month to include (YYYYMM format).
If NULL, returns all available months.}

\item{end_yyyymm}{Integer. Last month to include (YYYYMM format).
If NULL, returns all available months.}

\item{verbose}{Logical. Print progress messages? Default TRUE.}

\item{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.}

\item{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:
\itemize{
\item \code{ref_month_yyyymm}: Integer in YYYYMM format
\item \code{m_populacao}: Monthly population in thousands
}
}
\description{
Downloads population estimates from IBGE SIDRA API (table 6022) and
transforms from moving-quarter to exact monthly values.
}
\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:
\enumerate{
\item Fetches raw moving-quarter data from SIDRA
\item Transforms to exact monthly values by aligning with middle months
\item 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.
}
\section{Dependencies}{

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

\examples{
\donttest{
pop <- fetch_monthly_population()

pop <- fetch_monthly_population(201301, 201912)
}

}
\seealso{
\code{\link{pnadc_apply_periods}} which uses this function when
\code{calibrate = TRUE}
}
