*! version 1.0.0 2022-01-06

Title

inflate -- Inflate variables to real dollars using the CPI-U series

Syntax

Inflate variables

inflate
varlist [if] [in],
{year(varname)| start(int)} end(int) [options]

options

Main
year(varname) year variable

start(int) start date between 1913-today.

end(int) end date between 1913-today.

More Precise Time Periods
half(varname) half variable

quarter(varname) quarter variable

month(varname) month variable

Variable Creation
generate(varlist) specify the name of the new inflated variable

replace replaces variable with the inflated version instead of making a new variable

keepcpi keeps cpi values and multiplier used to inflate the variables

CPI Data
apikey(string) specify a FRED API key for downloading the CPI data from FRED.

update updates CPI data to most recent release from FRED

cpicheck opens the current CPI data file stored

Description

inflate is a one-line command to inflate (or deflate) variables from any year to any other year based on the annual average Consumer Price Index All Urban, All Items U.S. City Average. inflate adjusts to the year specified in
end(int) using either a constant starting year in start(int) or a year variable that can change across observations in year(varname).
Inflation is calculated according to the simple formula: newvar = oldvar*(CPI_end / CPI_start or CPI_year).

By default, inflate generates a new inflated variable suffixed with "_real" ordered after the original variable.

inflate relies on functionality introduced in Stata 16, specifically frame/frames.

inflate requires a FRED API key to download the CPI series. A FRED API key may be obtained from https://fred.stlouisfed.org/docs/api/api_key.html

Updating the CPI series

inflate uses the CPIAUCNS series from FRED.

To update the CPI series stored locally to the most recent release, run:

inflate, update apikey(yourFREDapikey)

inflate stores the CPI series in a Stata dta file in PLUS/i folder.
This file contains annual, biannual, and quarterly averages in addition to the monthly values.

To view your current CPI data file, run:

inflate, cpicheck

Options

Main

year(varname) chooses the year variable used to match with starting CPI values.
Inflates each observation to the end() date based on its year in the specified variable.
The variable in year(varname) should be numeric and take values in 1913-current year.

start(int) chooses a constant starting year as the base for inflation to the date in end().

You can also choose a more precise time period as the start date including year-half, year-quarter, or year-month.
More precise time periods are inputted as year then the time period type, then which half, quarter, or month.
For example, to inflate from July 1985, input 1985M07 or 1985M7.

end(int) chooses a constant end year to inflate to.

You can also choose a more precise time period as the end date including year-half, year-quarter, or year-month.
More precise time periods are inputted as year then the time period type, then which half, quarter, or month.
For example, to inflate to the first quarter of 2021, input 2021Q01 or 2021Q1.

More Precise Time Periods

half(varname) specifies the half variable used to match with starting CPI values.
half(varname) must be used in combination with year(varname).
Inflates each observation to the end() date based on its year and half values in the specified variables.
The variable in half(varname) should be numeric and take values 1 or 2.

quarter(varname) specifies the quarter variable used to match with starting CPI values.
quarter(varname) must be used in combination with year(varname).
Inflates each observation to the end() date based on its year and quarter values in the specified variables.
The variable in quarter(varname) should be numeric and take values in 1-4.

month(varname) specifies the month variable used to match with starting CPI values.
month(varname) must be used in combination with year(varname).
Inflates each observation to the end() date based on its year and month values in the specified variables.
The variable in month(varname) should be numeric and take values in 1-12.

Variable Creation

generate(varlist) allows you to specify the new variable names,
rather than naming each variable oldvariablename_real.

replace replaces the current variable with an inflated version, dropping the original variable.

keepcpi generates variables with the base CPI values, the end CPI value, and CPI_end / CPI_base as start_cpi, end_cpi, and inflator in addition to the new inflated variables.

CPI Data

apikey(string) specify a FRED API key for downloading the CPI data from FRED. Required the first time using inflate or when updating the CPI data. A FRED API key can be obtained from
https://fred.stlouisfed.org/docs/api/api_key.html

update updates the CPI series to the most recent FRED release.
Replaces CPI data in the PLUS/i folder.

checkcpi opens the local CPI data that inflate is using in the current Stata session.

Examples

Example 1: One variable with a constant start year

Load NLSW 1988 Data.

. clear

. sysuse nlsw88

Inflate the hourly wage from 1988 to 2020 $.

. inflate wage, start(1988) end(2020)

There is now an inflated wage variable called wage_real in the dataset ordered after the original variable.

To do the same thing but keep the CPI values used:

. drop wage_real

. inflate wage, start(1988) end(2020) keepcpi

Example 2: Multiple variables, inflate on year() and month()

Set your FRED API key. To download other series from FRED.

. clear

. set fredkey yourFREDapikey

Load monthly time series of the nominal M1 and M2 money stocks from FRED.

. import fred M1SL M2SL

Make year and month variables.

. gen year = year(daten)

. gen month = month(daten)

Inflate both series to 2023 $.

. inflate M1SL M2SL, year(year) month(month) end(2023)

Author

Sean McCulloch

sean_mcculloch@brown.edu

Acknowledgements

inflate would not be able to update the CPI series easily without FRED providing the CPI data series in their publicly available API.

FRED Citation: U.S. Bureau of Labor Statistics, Consumer Price Index for All Urban Consumers: All Items in U.S. City Average [CPIAUCSL], retrieved from FRED, Federal Reserve Bank of St. Louis

Also See

Built in: import fred

Online: freduse (on SSC)

Online: cpigen (on SSC)

Online: cpiget (on SSC)

License

MIT License

Copyright (c) 2024 Sean McCulloch

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

-----------------------