This function deflates USD-denominated values using specified deflators (CPI for USD, IPCA for BRL after converting using the exchange rate of the date of the statistics)
Usage
comex_deflate(data, basedate = NULL, deflators = get_deflators(na_omit = TRUE))Arguments
- data
A data frame or tibble containing data to be deflated.
- basedate
An optional date object specifying the base date for deflation. If
NULL, the latest available date in thedeflatorsdata is used.- deflators
A data frame containing deflator time series data, including columns
cpi(Consumer Price Index),ipca_i(Brazilian IPCA index), anddate. Defaults to theget_deflators()function's output with missing values removed.
Value
A modified version of the input data, with the following changes:
New columns for deflated USD values (e.g.,
fob_usd_deflated,cif_usd_deflated).New columns for BRL values based on the exchange rate and USD values (e.g.,
fob_brl,cif_brl).New columns for deflated BRL values using the IPCA deflator (e.g.,
fob_brl_deflated).
Details
The function performs the following steps:
Handles missing values in
deflators, issuing a warning if present.Determines the base date for deflation, either from
basedateinput or the latest date indeflators.Calculates deflation ratios (
cpi_r,ipca_r) for each date relative to the base date.Joins the
deflatorsdata with the inputdatabased ondate.Deflates the USD-denominated columns (those ending with _usd, such as
fob_usd,cif_usd, etc.) usingcpi_r.Converts USD values to BRL based on the exchange rate in the
brlusdcolumn.Deflates columns with BRL values (those ending with _brl) using
ipca_r.Arranges the resulting data by
date.