Created
August 17, 2022 23:04
-
-
Save statwonk/a05b3dce89cbd94be0a6a2802d2bbe56 to your computer and use it in GitHub Desktop.
Studying inflation dynamics using an ARDL model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
# CPI | |
# https://data.bls.gov/timeseries/CUSR0000SA0&output_view=pct_1mth | |
readxl::read_xlsx("~/Downloads/SeriesReport-20220817182003_bb0f80.xlsx", skip = 10) %>% | |
mutate(date = seq.POSIXt(as.POSIXct("1957-02-01"), by = "month", length.out = n())) %>% | |
select(date, cpi = Value) %>% | |
inner_join( | |
# Short-term Interest Rates - https://fred.stlouisfed.org/series/DGS1MO | |
read_csv("~/Downloads/DGS1MO (1).csv", col_types = cols( | |
DATE = col_date(format = ""), | |
DGS1MO = col_number() | |
)) %>% | |
janitor::clean_names() %>% | |
rename(treasury_1mo = dgs1mo) %>% | |
# impute some missing values | |
mutate(treasury_1mo = forecast::na.interp(treasury_1mo))) %>% | |
mutate(cpi_annualized = (((1 + cpi/100)^12) - 1)*100, # annualize cpi | |
# standardize on a 4% rate hike to aid interpretation | |
treasury_1mo_std_on_4pct = treasury_1mo/4, | |
lag_cpi_annualized = lag(cpi_annualized), | |
lag_treasury_1mo_std_on_4pct = lag(treasury_1mo_std_on_4pct)) %>% | |
arrange(date) %>% | |
tail(36) -> cpi | |
# Both ~ I(1) | |
forecast::auto.arima(cpi$cpi_annualized) | |
forecast::auto.arima(cpi$treasury_1mo) | |
MASS::rlm(cpi_annualized ~ lag(cpi_annualized) + | |
lag(treasury_1mo_std_on_4pct), | |
data = cpi) -> fit | |
forecast::auto.arima(resid(fit)) | |
plot(resid(fit), type = "b"); abline(h = 0, col = "red") | |
acf(resid(fit)) | |
par(mfrow = c(2, 2)); plot(fit); par(mfrow = c(1, 1)) | |
summary(fit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment