-
Notifications
You must be signed in to change notification settings - Fork 0
/
unemploymentAndInflationTimeSeriesAnalysis
133 lines (71 loc) · 3.23 KB
/
unemploymentAndInflationTimeSeriesAnalysis
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
library(urca)
library(tseries)
library(readxl)
library(tsDyn)
library(dplyr); library(ggplot2)
merged0 = read.csv('https://raw.githubusercontent.com/melissaalejandro/Class-Projects/main/unemployment_inflation.csv')
merged = merged0
merged$unemployment = log(merged$unemployment)
# check for NA'S
colSums(is.na(merged))
#cbind(lapply(lapply(merged, is.na), sum))
merged = merged[complete.cases(merged),] #remove na's
#merged = na.omit(merged)
merged = merged %>%
rename(unemp = unemployment, infl = inflation)
plot(infl~unemp, merged) # basic plot (not used in paper)
# Plot the relationship
ggplot(merged, aes(unemp, infl)) + geom_point() + geom_smooth(method="auto", se=TRUE, fullrange=TRUE, level=0.95) + ggtitle("Initial overview of the relationship between the unemployment and inflation rates")+ labs(y= "Inflation Rate (%)", x = "Unemployment Rate (%)")
# ===================================================================
# Test for unit roots and cointegration ----
# ===================================================================
## ADF TESTING (unit root) ------------------------------
# ADF unemployment
adf.test(merged$unemp, k=0) # p-value = 0.5264. CANNOT REJECT NULL
adf.test(merged$unemp, k=1) # p-value = 0.3822. CANNOT REJECT NULL
# with 0 lags, the unemployment p-value = 0.5957. with 1 lag, the unemployment p-value = 0.3822. In both cases, unemp is nonstationary.
# ADF
adf.test(merged$infl, k=0) # p-value = 0.9509 (CANNOT REJECT NULL)
adf.test(merged$infl, k=1) # p-value = 0.2916 (CANNOT REJECT NULL)
# with zero lags, the inflation p-value = 0.9509. with 1 lag, the p-value = 0.2916. In both cases, infl is nonstationry
# ===================================================================
# Calculating first differences for both unemp and infl ----
# ===================================================================
diff_ue <- diff(merged$unemp)
diff_inf <- diff(merged$infl)
diff <- data.frame(ue=diff_ue, inf=diff_inf)
## Use the differences in the ADF test ----------------
adf.test(diff$ue, k=0)
adf.test(diff$inf, k=0)
# Both p-values are 0.01, meaning both are stationary and there is no unit root
# Run regression
reg = lm(inf ~ ue, diff)
summary(reg)
plot(inf ~ ue, diff)
# ===================================================================
# Test for cointegration ----
# ===================================================================
two = subset(merged, select = c(unemp,infl))
jotest = ca.jo(two, K=2, ecdet = 'const', spec="transitory")
summary(jotest)
# ===================================================================
# Conduct VAR or ECM estimation ----
# ===================================================================
# determine number of lags to use
library(vars)
# Estimate VAR
var_aic <- VAR(two, type = "const", lag.max = 4, ic = "AIC")
# Lag order suggested by AIC
var_aic$p
# Estimate a bivariate VECM
vec = VECM(two, lag=1, include='const', estim = 'ML')
summary(vec)
# Estimation using three lags
vec = VECM(two, lag=3, include='const', estim = 'ML')
summary(vec)
# Estimation using six lags
vec = VECM(two, lag=5, include='const', estim = 'ML')
summary(vec)
# Estimation using differenced data
vec = VECM(diff, lag=1, include='const', estim = 'ML')
summary(vec)