adj_inflation: Add inflation-adjusted values to a data frame

View source: R/adj_inflation.R

adj_inflationR Documentation

Add inflation-adjusted values to a data frame

Description

This is modeled after blscrapeR::inflation_adjust that joins a data frame with an inflation adjustment table from the Bureau of Labor Statistics' Consumer Price Index, then calculates adjusted values. It returns the original data frame with two additional columns for adjustment factors and adjustment values.

Usage

adj_inflation(data, value, year, base_year = 2022, verbose = TRUE, key = NULL)

Arguments

data

A data frame containing monetary values by year.

value

Bare column name of monetary values; for safety, has no default.

year

Bare column name of years; for safety, has no default.

base_year

Year on which to base inflation amounts. Defaults to 2022, which corresponds to saying "... adjusted to 2022 dollars."

verbose

Logical: if TRUE (default), this will print overview information about the series being used, as returned by the API.

key

A string giving the BLS API key. If NULL (the default), will take the value in Sys.getenv("BLS_KEY").

Details

Note: Because adj_inflation makes API calls, internet access is required.

According to the BLS research page, the series this uses is best suited to data going back to about 2000, when their methodology changed. For previous years, a more accurate version of the index is available on their site.

Value

A data frame with two additional columns: adjustment factors, and adjusted values. The adjusted values column is named based on the name supplied as value; e.g. if value = avg_wage, the adjusted column is named adj_avg_wage.

Examples

## Not run: 
  wages <- data.frame(
    fiscal_year = 2010:2016,
    wage = c(50000, 51000, 52000, 53000, 54000, 55000, 54000)
  )
  adj_inflation(wages, value = wage, year = fiscal_year, base_year = 2016)

## End(Not run)

CT-Data-Haven/cwi documentation built on July 1, 2024, 7:45 a.m.