library("Quandl")
library("zoo")
library("xts")
library("urca")
library("vars")
library("dygraphs")
library("stargazer")
library("forecast")
Quandl.api_key("sfE3eBMHtyGwpQTDwkWQ")
O <-Quandl("FRED/OPHNFB",collapse="quarter", type="zoo")
H <-Quandl("FRED/HOANBS",collapse="quarterly",type="zoo")
lO <- log(O)
lH <- log (H)
dlO <- diff(lO)
dlH <- diff(lH)
par(mfrow=c(1,2), cex=0.8)
plot(O, xlab="", ylab="", main="Real Output Per Hour of All Persons", col="blue")
lines(H, col="red", lty="dashed")
legend("topleft",c("output/hour", "hours worked"), bty = "n", col = c(4,2), lty = c(1,2))
plot(dlO, xlab="", ylab="", main="Real Output Per Hour of All Persons % change", col="blue", ylim=c(-0.14,0.14))
lines(dlH, col="red", lty="dashed")
lY <- cbind(lO, lH)
dlY <- cbind(dlO, dlH)
test <- ur.ers(lY, type="P-test", lag.max=12, model="trend")
summary(test)
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type P-test
## detrending of series with intercept and trend
##
## Value of test-statistic is: 25.9987
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 3.96 5.62 6.89
We reject the null of unit root since the 25.9987 >3.96 5.62 6.89, so there is a unit root.
test1 <- ur.ers(dlY, type="P-test", lag.max=12, model="trend")
summary(test1)
##
## ###############################################
## # Elliot, Rothenberg and Stock Unit Root Test #
## ###############################################
##
## Test of type P-test
## detrending of series with intercept and trend
##
## Value of test-statistic is: 0.7814
##
## Critical values of P-test are:
## 1pct 5pct 10pct
## critical values 3.96 5.62 6.89
We do not reject the null of unit root since the 0.7814 < 3.96 5.62 6.89, so there is no unit root.
varp <- VAR(dlY, ic="AIC", lag.max=8, type="const")
varp
##
## VAR Estimation Results:
## =======================
##
## Estimated coefficients for equation dlO:
## ========================================
## Call:
## dlO = dlO.l1 + dlH.l1 + dlO.l2 + dlH.l2 + dlO.l3 + dlH.l3 + const
##
## dlO.l1 dlH.l1 dlO.l2 dlH.l2 dlO.l3
## -0.061099629 0.063118172 0.051485308 -0.196577779 0.005240038
## dlH.l3 const
## -0.192381110 0.006233742
##
##
## Estimated coefficients for equation dlH:
## ========================================
## Call:
## dlH = dlO.l1 + dlH.l1 + dlO.l2 + dlH.l2 + dlO.l3 + dlH.l3 + const
##
## dlO.l1 dlH.l1 dlO.l2 dlH.l2 dlO.l3
## 0.1065853542 0.6259177078 0.1047852502 -0.0181069034 0.0884737276
## dlH.l3 const
## -0.0441193518 -0.0002739886
summary(varp)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: dlO, dlH
## Deterministic variables: const
## Sample size: 276
## Log Likelihood: 1939.243
## Roots of the characteristic polynomial:
## 0.7387 0.7387 0.4311 0.4311 0.4069 0.4069
## Call:
## VAR(y = dlY, type = "const", lag.max = 8, ic = "AIC")
##
##
## Estimation results for equation dlO:
## ====================================
## dlO = dlO.l1 + dlH.l1 + dlO.l2 + dlH.l2 + dlO.l3 + dlH.l3 + const
##
## Estimate Std. Error t value Pr(>|t|)
## dlO.l1 -0.0610996 0.0592136 -1.032 0.30307
## dlH.l1 0.0631182 0.0712786 0.886 0.37667
## dlO.l2 0.0514853 0.0559621 0.920 0.35840
## dlH.l2 -0.1965778 0.0840083 -2.340 0.02002 *
## dlO.l3 0.0052400 0.0550610 0.095 0.92425
## dlH.l3 -0.1923811 0.0731269 -2.631 0.00901 **
## const 0.0062337 0.0007462 8.353 3.56e-15 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.00793 on 269 degrees of freedom
## Multiple R-Squared: 0.1176, Adjusted R-squared: 0.09788
## F-statistic: 5.973 on 6 and 269 DF, p-value: 7.068e-06
##
##
## Estimation results for equation dlH:
## ====================================
## dlH = dlO.l1 + dlH.l1 + dlO.l2 + dlH.l2 + dlO.l3 + dlH.l3 + const
##
## Estimate Std. Error t value Pr(>|t|)
## dlO.l1 0.1065854 0.0506809 2.103 0.0364 *
## dlH.l1 0.6259177 0.0610073 10.260 <2e-16 ***
## dlO.l2 0.1047853 0.0478979 2.188 0.0296 *
## dlH.l2 -0.0181069 0.0719026 -0.252 0.8014
## dlO.l3 0.0884737 0.0471267 1.877 0.0616 .
## dlH.l3 -0.0441194 0.0625892 -0.705 0.4815
## const -0.0002740 0.0006387 -0.429 0.6683
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.006787 on 269 degrees of freedom
## Multiple R-Squared: 0.4387, Adjusted R-squared: 0.4261
## F-statistic: 35.03 on 6 and 269 DF, p-value: < 2.2e-16
##
##
##
## Covariance matrix of residuals:
## dlO dlH
## dlO 6.288e-05 7.009e-06
## dlH 7.009e-06 4.606e-05
##
## Correlation matrix of residuals:
## dlO dlH
## dlO 1.0000 0.1302
## dlH 0.1302 1.0000
The correlation between residuals of dlO and dlH is 0.1302. This means that there is some sort of causal relationship between two variables.
svar1<-VAR(dlY,ic="AIC", lag.max=8)
svar11<-BQ(svar1)
summary(svar11)
##
## SVAR Estimation Results:
## ========================
##
## Call:
## BQ(x = svar1)
##
## Type: Blanchard-Quah
## Sample size: 276
## Log Likelihood: 1932.152
##
## Estimated contemporaneous impact matrix:
## dlO dlH
## dlO 0.006523 0.004509
## dlH -0.003099 0.006038
##
## Estimated identified long run impact matrix:
## dlO dlH
## dlO 0.007195 0.00000
## dlH -0.002159 0.01384
##
## Covariance matrix of reduced form residuals (*100):
## dlO dlH
## dlO 0.0062881 0.0007009
## dlH 0.0007009 0.0046064
The result rom the SVAR test is: The technology shocks will lead to increase the Real Output Per Hour of All Persons by 0.006523 and decrease the Nonfarm Business Sector: Hours of All Persons by 0.003099. The demand shocks will lead to increase the Real Output Per Hour of All Persons by 0.004509 and increase the Nonfarm Business Sector: Hours of All Persons by 0.006038.
The technology shocks will lead to increase the Real Output Per Hour of All Persons by 0.007195 and decrease the Nonfarm Business Sector: Hours of All Persons by 0.002159 The demand shocks will not affect the Real Output Per Hour of All Persons bur increase the Nonfarm Business Sector: Hours of All Persons by 0.01384.
svar11.irfs <- irf(svar11, n.ahead=10)
par(mfcol=c(2,2), cex=0.6)
plot(svar11.irfs, plot.type="single")
svar11.fevd <- fevd(svar11, n.ahead=10)
svar11.fevd[[1]][c(1,3,6,10),]
## dlO dlH
## [1,] 0.6766369 0.3233631
## [2,] 0.6773475 0.3226525
## [3,] 0.6289225 0.3710775
## [4,] 0.6265654 0.3734346
par(mfcol=c(2,2), cex=0.6)
plot(svar11.fevd)
par(mfcol=c(2,2), cex=0.6)
plot(svar11.fevd, addbars=8)
The IRFs are different in this model compared to Gali (1999). Technology shocks and demand shocks: For the Real Output Per Hour of All Persons compared to GDP in Gali (1999) they have the same shape or path with different values or levels. However,the Nonfarm Business Sector: Hours of All Persons compared to hours in Gali (1999) they have the revere path.
svar11.fevd <- fevd(svar11, n.ahead=10)
svar11.fevd[[1]][c(1,3,6,10),]
## dlO dlH
## [1,] 0.6766369 0.3233631
## [2,] 0.6773475 0.3226525
## [3,] 0.6289225 0.3710775
## [4,] 0.6265654 0.3734346
svar11.fevd[[2]][c(1,3,6,10),]
## dlO dlH
## [1,] 0.2085518 0.7914482
## [2,] 0.1488563 0.8511437
## [3,] 0.1542054 0.8457946
## [4,] 0.1544352 0.8455648