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.
adj_inflation(data, value, year, base_year = 2022, verbose = TRUE, key = NULL)
A data frame containing monetary values by year.
Bare column name of monetary values; for safety, has no default.
Bare column name of years; for safety, has no default.
Year on which to base inflation amounts. Defaults to 2022, which corresponds to saying "... adjusted to 2022 dollars."
Logical: if TRUE
(default), this will print overview information about the series being used, as returned by the API.
A string giving the BLS API key. If NULL
(the default), will take the value in Sys.getenv("BLS_KEY")
.
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
.
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.
if (FALSE) {
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)
}