knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(hayashir) library(ggplot2) library(dplyr) library(zoo)
head(mishkin)
First we construct a date variable and then calculate CPI inflation
The library zoo
contains the function as.yearmon()
to construct dates containing only year and months.
mishkin2 <- mishkin %>% mutate(time_period = as.yearmon(paste(year, month, sep = "-")), cpi_inflation = (cpi/lag(cpi) - 1) * 100 * 12 )
Now we plot the data:
ggplot(mishkin2) + geom_line(aes(time_period, tbill_1, linetype = "tbill_1")) + geom_line(aes(time_period, cpi_inflation, linetype = "cpi_inflation")) + xlab("Date") + ylab("percent") + theme_bw() + theme(legend.position="bottom") + scale_linetype_manual(name = element_blank(), values = c(tbill_1 = "solid", cpi_inflation = "dotted"), labels = c("inflation rate", "1 month T-bill rate") )
Compute real interest rate:
mishkin2 <- mishkin2 %>% mutate(real_rate = tbill_1 - cpi_inflation)
And now plot:
ggplot(mishkin2) + geom_line(aes(time_period, real_rate, linetype = "tbill_1")) + geom_hline(yintercept = 0, linetype = "dashed", color = "red") + xlab("Date") + ylab("percent") + theme_bw() + theme(legend.position="none")
First we subset the data. The relevant Date range is January 1953 to July 1971.
fama <- mishkin2 %>% filter(between(as.yearmon(time_period), as.yearmon("Jan 1953"), as.yearmon("Jul 1971") ) )
library(skimr) skim(fama$real_rate)
Then the ACF
acf(fama$real_rate, lag.max = 12, plot = FALSE)
Then the Ljung Box Q tests (use the portes
package for more flexibility)
library(portes)
LjungBox(fama$real_rate, lags = seq(1, 12))
model1 <- lm(cpi_inflation ~ tbill_1, data = fama) summary(model1)
library(sandwich) library(lmtest) coeftest(model1, vcov = vcovHC(model1, "HC0")) # white's
library(car) linearHypothesis(model1, "tbill_1 = 1", white.adjust = "hc0")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.