Skip to contents

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 the deflators data is used.

deflators

A data frame containing deflator time series data, including columns cpi (Consumer Price Index), ipca_i (Brazilian IPCA index), and date. Defaults to the get_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:

  1. Handles missing values in deflators, issuing a warning if present.

  2. Determines the base date for deflation, either from basedate input or the latest date in deflators.

  3. Calculates deflation ratios (cpi_r, ipca_r) for each date relative to the base date.

  4. Joins the deflators data with the input data based on date.

  5. Deflates the USD-denominated columns (those ending with _usd, such as fob_usd, cif_usd, etc.) using cpi_r.

  6. Converts USD values to BRL based on the exchange rate in the brlusd column.

  7. Deflates columns with BRL values (those ending with _brl) using ipca_r.

  8. Arranges the resulting data by date.

Examples

if (FALSE) { # \dontrun{
} # }