Final Paper: Initial Analysis

Set work directory

setwd("C:/Users/victo/Downloads/ECON 4310/Paper")

Loading Packages

We are using various R packages that need to be installed and added. You might have to uncomment/run the chunk below. Alternatively, you may be able to install the missing packages through RStudio, selecting “packages” and “install”, entering the names.

#install.packages("invgamma")
library(invgamma)

#install.packages("matlib")
library(matlib)

#install.packages("MASS")
library(MASS)

#install.packages("MCMCpack")
library(MCMCpack) #for Inverse Wishart
## Warning: package 'MCMCpack' was built under R version 4.2.3
## Loading required package: coda
## Warning: package 'coda' was built under R version 4.2.3
## ##
## ## Markov Chain Monte Carlo Package (MCMCpack)
## ## Copyright (C) 2003-2023 Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park
## ##
## ## Support provided by the U.S. National Science Foundation
## ## (Grants SES-0350646 and SES-0350613)
## ##
## 
## Attaching package: 'MCMCpack'
## The following objects are masked from 'package:invgamma':
## 
##     dinvgamma, rinvgamma
#install.packages("mvtnorm")
library(mvtnorm) #for multivariate Normal

#install.packages("HypergeoMat")
library(HypergeoMat) #for multivariate gamma function (VAR-MDD calculation)
## Warning: package 'HypergeoMat' was built under R version 4.2.3

Load Data

Load monthly data and trim to 1997, Q2 (max MPR data):

data  <- read.csv("Chile_1986_Monthly.csv", header=TRUE)
# head(data)
#na.omit(as.numeric(data$CPI))
#na.omit(data$CPI)
UE <- ts(data$UE, frequency=12,start=c(1986,1))
CPI <- ts(data$CPI, frequency=12, start=c(1986,1))
UE <- window(UE,start=c(1997,2),end=c(2022,12))
CPI <- window(CPI,start=c(1997,2),end=c(2022,12))

Convert monthly to quarterly data

MonthlyToQuarterly <- function(MonthlyData,start,namevec){
  ## Assume that first obs is first month of quarter
  ## Assume that last obs is last month of quarter
  nobsMonth <- length(MonthlyData)
  nobsQuart <- nobsMonth/3
  firstyear <- start[1]
  firstquarter <- ((start[2]-1) %/% 3)+1
  QuarterlyData <- matrix(0,nrow=nobsQuart,ncol=1)
  for(i in 1:nobsQuart){
     QuarterlyData[i] <- mean(MonthlyData[(1+3*(i-1)):(3*i)],na.rm=FALSE)
  }
  QuarterlyData <- ts(QuarterlyData,frequency=4,start=c(firstyear,firstquarter),
                      names=namevec)
  return(QuarterlyData)
}

UEq <- MonthlyToQuarterly(UE,c(1996,1),"UE")
UEq <- window(UEq,start=c(1997,2))
#print(UEq)

CPIq <- MonthlyToQuarterly(CPI,c(1996,1),"CPI")
CPIq <- window(CPIq,start=c(1997,2))
#print(CPIq)

Load Monetary Policy Rate data (MPR)

data <- read.csv("Chile_MPR_monthly_F1997.csv", header = T)
MPR <- ts(data$MPR, frequency = 12, start = c(1997, 2))
MPRq <- MonthlyToQuarterly(MPR, c(1997,2), "MPR")
MPRq <- window(MPRq, start=c(1997,2), end=c(2021,3))
#print(MPRq)

Load the GDP data (unnecessary for monetary policy shock)

data     <- read.csv("Chile_1996_Quarterly.csv", header=TRUE)


GDP <- gsub(",","",data$GDP)
GDP <- as.numeric(GDP)
GDP      <- ts(GDP, frequency=4, start=c(1997,2))
#head(GDP)
GDPlog <- log(GDP)
GDPlogdiff <- diff(GDPlog)
GDPgrowth <- 400*GDPlogdiff
GDPgrowth <- ts(GDPgrowth, frequency = 4,start=c(1997,2), end=c(2021,3))

Plot of Unemployment Rate

plot.ts(UEq,cex=0.25,xlab="",ylab="Unemployment Rate (%)",col="blue",lwd=2)

Plot of Consumer Price Index

plot.ts(CPI,cex=0.25,xlab="",ylab="CPI (Percent Change)",col="red",lwd=2)

Plot of Monetary Policy Rate

plot.ts(MPRq, cex=0.25, xlab="", ylab="Monetary Policy Rate (%)", col = "green", lwd=2)

Plot of GDP

plot.ts(GDP, cex = 0.25, xlab="", ylab="GDP", col="purple",lwd=2)

Plot of GDP Growth

plot.ts(GDPgrowth, cex = 0.25, xlab="", ylab="GDP Growth", col="pink",lwd=2)

Plots Combined:

ts.plot(ts.union(UEq,CPIq,MPRq, GDPgrowth),
        gpars=list(xlab="",ylab="Percent",col=c("blue","red","green","pink"),lwd=c(2,3)) )

Plots without GDP Growth

ts.plot(ts.union(UEq,CPIq,MPRq),
        gpars=list(xlab="",ylab="Percent",col=c("blue","red","green"),lwd=c(2,3)) )