#Open the libraries
library(vars);library(tsDyn);library(readr);library(dplyr);library(reshape2);library(ggplot2);library(ggthemes)
#Import the data
olddata <- read_csv("GDP.csv")
#Log the old dataset
newdata <- log(olddata)
#Create another new dataset that is differenced
newnewdata <- newdata %>% mutate(d.GDP = c(NA, diff(GDP)), d.CONS = c(NA, diff(consumption))) %>% filter(!is.na(d.GDP)) %>% dplyr::select(-GDP, -consumption)
#Fit a vector autoregression to the two series
myfittedmodel <- VAR(newnewdata, p = 5, type = "const")
#Akaike Information Criterion
AIC(myfittedmodel)
## [1] -4175.933
#Generate impulse responses
myirfs <- irf(myfittedmodel)
#Plot
plot(myirfs)
#Fit a vector error correction model
vecm1 <- VECM(data= newdata, lag = 5, r = 1, include = "const", estim = "ML", beta = 0)
#Generate irfs again
myirfs2 <- irf(vecm1)
#Plot
plot(myirfs2)
There is a substantial difference, growth is higher for both.
#Generate forecasts for GDP & consumption growth for next 4 quarters
prediction <- predict(myfittedmodel, n.ahead = 4)
#Plot
plot(prediction)