% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mensalize-sidra-series.R
\name{mensalize_sidra_series}
\alias{mensalize_sidra_series}
\title{Convert Rolling Quarters to Exact Monthly Series}
\usage{
mensalize_sidra_series(
  rolling_quarters,
  starting_points = NULL,
  series = "all",
  compute_derived = TRUE,
  verbose = TRUE
)
}
\arguments{
\item{rolling_quarters}{data.table from \code{\link{fetch_sidra_rolling_quarters}}
containing rolling quarter series with columns \code{anomesfinaltrimmovel},
\code{mesnotrim}, and series value columns.}

\item{starting_points}{Optional data.table with precomputed starting points
(y0 values). If NULL (default), uses bundled \code{pnadc_series_starting_points}.
See Details for format.}

\item{series}{Character vector of series names to mensalize, or "all" (default)
for all series in the input data (except price indices).}

\item{compute_derived}{Logical. Compute derived series (rates, aggregates)?
Default TRUE.}

\item{verbose}{Logical. Print progress messages? Default TRUE.}
}
\value{
A data.table with columns:
\describe{
\item{anomesexato}{Integer. YYYYMM exact month}
\item{m_*}{Numeric. Mensalized value for each series (one column per series)}
}
}
\description{
Transforms SIDRA rolling quarterly averages into exact monthly values using
the mathematical relationship between consecutive rolling quarters.
}
\details{
The algorithm exploits the mathematical property of rolling quarterly averages:

\deqn{RQ_t - RQ_{t-1} = (Month_t - Month_{t-3}) / 3}

This means exact 3-month variations can be extracted from consecutive rolling
quarters. By accumulating these variations separately for each month-position
(1, 2, or 3), we build cumulative variation series. The only unknown is the
starting level for Jan, Feb, and Mar 2012.

\strong{Starting points} are estimated by:
\enumerate{
\item Computing monthly estimates from calibrated microdata (z_ variables)
\item Calculating cumulative variations from SIDRA (cum_ variables)
\item Backprojecting: e0 = z_ - cum_ over calibration period (2013-2019)
\item Averaging e0 by month position to get y0_ for each position
}

\strong{Final adjustment} ensures the average of 3 consecutive mensalized values
equals the original rolling quarter value.
}
\section{Starting Points Format}{

If providing custom starting points, the data.table must have columns:
\itemize{
\item \code{series_name}: Character. Series name matching rolling_quarters columns
\item \code{mesnotrim}: Integer (1, 2, or 3). Month position in quarter
\item \code{y0}: Numeric. Starting point value
}
}

\section{Mathematical Foundation}{

The mensalization algorithm proceeds in steps:
\enumerate{
\item Calculate d3 = 3 * (RQ_t - RQ_t-1)
\item Separate d3 by month position: d3m1, d3m2, d3m3
\item Cumulate separately: cum1, cum2, cum3
\item Apply starting points: y = y0 + cum
\item Final adjustment for rolling quarter consistency
}
}

\examples{
\donttest{
rq <- fetch_sidra_rolling_quarters(
  series = c("taxadesocup", "popocup", "popdesocup")
)
monthly <- mensalize_sidra_series(rq)
head(monthly)
}

}
\seealso{
\code{\link{fetch_sidra_rolling_quarters}} to obtain input data
\code{\link{compute_series_starting_points}} for custom calibration
}
