Econ 5316 time Series Econometrics(Spring 2017) / Homework4 Problem1 (Feb.21)
Keunyoung (Kay) Kim

1. Introduction

Choose the time series from each of categories and determine whether to transform it using logarithm.
Plot the original, transformed time series and first differences of log-transformed time series.
Perform ADF, KPSS and ERS tests on log-transformed time series and first differences of log-transformed time series.
Summarize the results of the tests and determine which time series appear to be I(0), I(1), I(2)


2.Data

Data for the unit root tests are imported from Quandl website.

A: Real Personal Consumption Expenditures Per Capita

Both Original and log transformed data have a deterministic trend => suppose Model C

The log difference data does not show a deterministic trend, but variability appears to be smaller in recent years.

B: S&P 500 Index

Both Original and log transformed data have a deterministic trend => suppose Model C

The log difference data does not show a deterministic trend and seems to be stationary.

C: Gross Domestic Product: Implicit Price Deflator

Both Original and log transformed data have a deterministic trend => suppose Model C

The log difference data does not show a deterministic trend and does not appear to be stationary. So it is necessary to take the second difference.

D: 10-Year Treasury Constant Maturity Rate

Both Original and log transformed data does not have a deterministic trend => suppose Model B
The log difference data does not show a deterministic trend, but variability appears to be larger in recent years.

E: Labor Force Participation Rate

Both Original and log transformed data have a deterministic trend => suppose Model B

The log difference data does not show a deterministic trend, but variability appears to be smaller in recent years.

F: Japan / U.K. Foreign Exchange Rate

Both Original and log transformed data have a little bit deterministic trend(downward) => suppose Model B or C

The log difference data does not show a deterministic trend.


3. Methodology

To test unit root, we performed ADF, KPSS, ERS tests on log-transformed time series and first difference of log time series.

A: Real Personal Consumption Expenditures Per Capita

The test results below indicate that the first difference of log transformed time series does not have unit root. => I(1)

## 
##  Augmented Dickey-Fuller Test
## 
## data:  l_rpce
## Dickey-Fuller = -1.2427, Lag order = 6, p-value = 0.8951
## alternative hypothesis: stationary
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dl_rpce
## Dickey-Fuller = -5.7821, Lag order = 6, p-value = 0.01
## alternative hypothesis: stationary
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dl_rpce
## KPSS Trend = 0.094181, Truncation lag parameter = 3, p-value = 0.1
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type P-test 
## detrending of series with intercept and trend 
## 
## Value of test-statistic is: 1.4007 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type DF-GLS 
## detrending of series with intercept and trend 
## 
## 
## Call:
## lm(formula = dfgls.form, data = data.dfgls)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.049531 -0.004098 -0.000192  0.003198  0.032589 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## yd.lag       -0.55916    0.09178  -6.093 3.83e-09 ***
## yd.diff.lag1 -0.34986    0.08845  -3.955 9.78e-05 ***
## yd.diff.lag2  0.05094    0.08636   0.590    0.556    
## yd.diff.lag3  0.09321    0.08103   1.150    0.251    
## yd.diff.lag4 -0.02976    0.06033  -0.493    0.622    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.007794 on 269 degrees of freedom
## Multiple R-squared:  0.5079, Adjusted R-squared:  0.4988 
## F-statistic: 55.53 on 5 and 269 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -6.0926 
## 
## Critical values of DF-GLS are:
##                  1pct  5pct 10pct
## critical values -3.48 -2.89 -2.57

B: S&P 500 Index

The test results below indicate that the first difference of log transformed time series does not have unit root. => I(1)

## 
##  Augmented Dickey-Fuller Test
## 
## data:  l_sp
## Dickey-Fuller = -2.2329, Lag order = 25, p-value = 0.4797
## alternative hypothesis: stationary
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dl_sp
## Dickey-Fuller = -26.405, Lag order = 25, p-value = 0.01
## alternative hypothesis: stationary
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dl_sp
## KPSS Trend = 0.066239, Truncation lag parameter = 29, p-value =
## 0.1
## 
## ############################################### 
## # 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.0134 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type DF-GLS 
## detrending of series with intercept and trend 
## 
## 
## Call:
## lm(formula = dfgls.form, data = data.dfgls)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.216997 -0.006451 -0.001622  0.003481  0.131864 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## yd.lag       -0.390294   0.011289  -34.57   <2e-16 ***
## yd.diff.lag1 -0.451084   0.011585  -38.94   <2e-16 ***
## yd.diff.lag2 -0.368314   0.011097  -33.19   <2e-16 ***
## yd.diff.lag3 -0.234705   0.009854  -23.82   <2e-16 ***
## yd.diff.lag4 -0.117211   0.007643  -15.34   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0103 on 16881 degrees of freedom
## Multiple R-squared:  0.4198, Adjusted R-squared:  0.4196 
## F-statistic:  2443 on 5 and 16881 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -34.5717 
## 
## Critical values of DF-GLS are:
##                  1pct  5pct 10pct
## critical values -3.48 -2.89 -2.57

C: Gross Domestic Product: Implicit Price Deflator

The test results below indicate that it is hard to determine the stationarity for the first difference of log transformed time series, since the result of ADF and others are different. Thus it is necessary to perform these tests for series in second differences.

## 
##  Augmented Dickey-Fuller Test
## 
## data:  l_def
## Dickey-Fuller = -1.0427, Lag order = 6, p-value = 0.9304
## alternative hypothesis: stationary
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dl_def
## Dickey-Fuller = -3.5413, Lag order = 6, p-value = 0.03919
## alternative hypothesis: stationary
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dl_def
## KPSS Trend = 0.7009, Truncation lag parameter = 3, p-value = 0.01
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type P-test 
## detrending of series with intercept and trend 
## 
## Value of test-statistic is: 2.7719 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type DF-GLS 
## detrending of series with intercept and trend 
## 
## 
## Call:
## lm(formula = dfgls.form, data = data.dfgls)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0225613 -0.0017828 -0.0002331  0.0013980  0.0182848 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## yd.lag       -0.14752    0.04007  -3.682  0.00028 ***
## yd.diff.lag1 -0.27011    0.06529  -4.137 4.71e-05 ***
## yd.diff.lag2 -0.09393    0.06583  -1.427  0.15473    
## yd.diff.lag3  0.06496    0.06427   1.011  0.31306    
## yd.diff.lag4  0.04599    0.05916   0.778  0.43754    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.003774 on 269 degrees of freedom
## Multiple R-squared:  0.1701, Adjusted R-squared:  0.1546 
## F-statistic: 11.03 on 5 and 269 DF,  p-value: 1.136e-09
## 
## 
## Value of test-statistic is: -3.6818 
## 
## Critical values of DF-GLS are:
##                  1pct  5pct 10pct
## critical values -3.48 -2.89 -2.57

Tests for series in second differences of log transformed time series shows that this time series does not have unit root. => I(2)

## 
##  Augmented Dickey-Fuller Test
## 
## data:  d2l_def
## Dickey-Fuller = -10.103, Lag order = 6, p-value = 0.01
## alternative hypothesis: stationary
## 
##  KPSS Test for Trend Stationarity
## 
## data:  d2l_def
## KPSS Trend = 0.018593, Truncation lag parameter = 3, p-value = 0.1
## 
## ############################################### 
## # 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.5416 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type DF-GLS 
## detrending of series with intercept and trend 
## 
## 
## Call:
## lm(formula = dfgls.form, data = data.dfgls)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0294488 -0.0023297 -0.0004795  0.0011940  0.0162278 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## yd.lag       -0.98483    0.15115  -6.515 3.57e-10 ***
## yd.diff.lag1 -0.27129    0.13758  -1.972   0.0497 *  
## yd.diff.lag2 -0.27318    0.12037  -2.269   0.0240 *  
## yd.diff.lag3 -0.12444    0.09442  -1.318   0.1887    
## yd.diff.lag4 -0.01466    0.05876  -0.249   0.8032    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.004058 on 268 degrees of freedom
## Multiple R-squared:  0.634,  Adjusted R-squared:  0.6272 
## F-statistic: 92.85 on 5 and 268 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -6.5154 
## 
## Critical values of DF-GLS are:
##                  1pct  5pct 10pct
## critical values -3.48 -2.89 -2.57

D: 10-Year Treasury Constant Maturity Rate

The test results below indicate that the first difference of log transformed time series does not have unit root. => I(1)

## 
##  Augmented Dickey-Fuller Test
## 
## data:  l_tb
## Dickey-Fuller = -2.2743, Lag order = 23, p-value = 0.4622
## alternative hypothesis: stationary
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dl_tb
## Dickey-Fuller = -23.063, Lag order = 23, p-value = 0.01
## alternative hypothesis: stationary
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dl_tb
## KPSS Trend = 0.023913, Truncation lag parameter = 27, p-value =
## 0.1
## 
## ############################################### 
## # 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.0178 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type DF-GLS 
## detrending of series with intercept and trend 
## 
## 
## Call:
## lm(formula = dfgls.form, data = data.dfgls)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.184942 -0.002324  0.003321  0.007816  0.094627 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## yd.lag       -0.598998   0.015010 -39.908  < 2e-16 ***
## yd.diff.lag1 -0.283956   0.014337 -19.806  < 2e-16 ***
## yd.diff.lag2 -0.219314   0.013160 -16.666  < 2e-16 ***
## yd.diff.lag3 -0.126455   0.011313 -11.177  < 2e-16 ***
## yd.diff.lag4 -0.059233   0.008513  -6.958  3.6e-12 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01326 on 13756 degrees of freedom
## Multiple R-squared:  0.4398, Adjusted R-squared:  0.4396 
## F-statistic:  2160 on 5 and 13756 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -39.9077 
## 
## Critical values of DF-GLS are:
##                  1pct  5pct 10pct
## critical values -3.48 -2.89 -2.57

E: Labor Force Participation Rate

The test results below indicate that it is hard to determine the stationarity for the first difference of log transformed time series, since the result of ADF and KPSS are different. Thus it is necessary to perform these tests for series in second differences.

## 
##  Augmented Dickey-Fuller Test
## 
## data:  l_lf
## Dickey-Fuller = 0.84234, Lag order = 9, p-value = 0.99
## alternative hypothesis: stationary
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dl_lf
## Dickey-Fuller = -9.9101, Lag order = 9, p-value = 0.01
## alternative hypothesis: stationary
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dl_lf
## KPSS Trend = 0.27007, Truncation lag parameter = 6, p-value = 0.01
## 
## ############################################### 
## # 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.3409 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type DF-GLS 
## detrending of series with intercept and trend 
## 
## 
## Call:
## lm(formula = dfgls.form, data = data.dfgls)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0131935 -0.0021302 -0.0002437  0.0016600  0.0159664 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## yd.lag       -0.25843    0.04670  -5.534 4.23e-08 ***
## yd.diff.lag1 -0.83125    0.05084 -16.349  < 2e-16 ***
## yd.diff.lag2 -0.66341    0.05354 -12.390  < 2e-16 ***
## yd.diff.lag3 -0.42093    0.04883  -8.621  < 2e-16 ***
## yd.diff.lag4 -0.17591    0.03371  -5.219 2.28e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.003367 on 818 degrees of freedom
## Multiple R-squared:  0.5665, Adjusted R-squared:  0.5638 
## F-statistic: 213.8 on 5 and 818 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -5.5335 
## 
## Critical values of DF-GLS are:
##                  1pct  5pct 10pct
## critical values -3.48 -2.89 -2.57

Tests for series in second differences of log transformed time series shows two different results. So, it is more reasonable to consider both I(1) and (2).

## 
##  Augmented Dickey-Fuller Test
## 
## data:  d2l_lf
## Dickey-Fuller = -17.669, Lag order = 9, p-value = 0.01
## alternative hypothesis: stationary
## 
##  KPSS Test for Trend Stationarity
## 
## data:  d2l_lf
## KPSS Trend = 0.006525, Truncation lag parameter = 6, p-value = 0.1
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type P-test 
## detrending of series with intercept and trend 
## 
## Value of test-statistic is: 13.787 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type DF-GLS 
## detrending of series with intercept and trend 
## 
## 
## Call:
## lm(formula = dfgls.form, data = data.dfgls)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0148912 -0.0024208 -0.0000198  0.0024940  0.0236644 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## yd.lag       -0.07144    0.02686   -2.66  0.00797 ** 
## yd.diff.lag1 -1.47131    0.03980  -36.97  < 2e-16 ***
## yd.diff.lag2 -1.39570    0.05552  -25.14  < 2e-16 ***
## yd.diff.lag3 -0.91510    0.05381  -17.01  < 2e-16 ***
## yd.diff.lag4 -0.34371    0.03209  -10.71  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.004366 on 817 degrees of freedom
## Multiple R-squared:  0.7719, Adjusted R-squared:  0.7705 
## F-statistic:   553 on 5 and 817 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -2.6597 
## 
## Critical values of DF-GLS are:
##                  1pct  5pct 10pct
## critical values -3.48 -2.89 -2.57

F: Japan / U.K. Foreign Exchange Rate

The test results below indicate that the first difference of log transformed time series does not have unit root. => I(1)

## 
##  Augmented Dickey-Fuller Test
## 
## data:  l_jex
## Dickey-Fuller = -2.0413, Lag order = 8, p-value = 0.5608
## alternative hypothesis: stationary
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dl_jex
## Dickey-Fuller = -6.9831, Lag order = 8, p-value = 0.01
## alternative hypothesis: stationary
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dl_jex
## KPSS Trend = 0.03457, Truncation lag parameter = 5, p-value = 0.1
## 
## ############################################### 
## # 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.3503 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type DF-GLS 
## detrending of series with intercept and trend 
## 
## 
## Call:
## lm(formula = dfgls.form, data = data.dfgls)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.093483 -0.013630  0.001471  0.017841  0.076581 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## yd.lag       -0.72964    0.07075 -10.313   <2e-16 ***
## yd.diff.lag1  0.06945    0.06613   1.050   0.2940    
## yd.diff.lag2  0.02402    0.06016   0.399   0.6899    
## yd.diff.lag3  0.07436    0.05180   1.436   0.1517    
## yd.diff.lag4  0.08035    0.04316   1.862   0.0632 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.02542 on 543 degrees of freedom
## Multiple R-squared:  0.3424, Adjusted R-squared:  0.3363 
## F-statistic: 56.55 on 5 and 543 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -10.3129 
## 
## Critical values of DF-GLS are:
##                  1pct  5pct 10pct
## critical values -3.48 -2.89 -2.57

4.Conclusions

In conclusion, time series of C(Gross Domestic Product: Implicit Price Deflator) appears to be I(2), that is the second difference of log-transformed time series do not have unit root. On the other hand, A, B, D, F time series appear to be I(1), since the first difference of log-transformed time series do not have unit root. For E(Labor Force Participation Rate), we can consider both I(1) and I(2).

* R code for analysis

library(Quandl)
Quandl.api_key("XzdSwkDsE98Mxj3ixQzG")

# A: Real Personal Consumption Expenditures Per Capita FRED/A794RX0Q048SBEA
rpce <- Quandl("FRED/A794RX0Q048SBEA", type = "zoo")
l_rpce <- log(rpce)
dl_rpce <- diff(l_rpce)
plot(xts(rpce, order.by = index(rpce)), xlab="Year", ylab="", main="Real Personal Consumption Expenditures Per Capital", major.format="%YQ%q", auto.grid=FALSE)
plot(xts(l_rpce, order.by = index(l_rpce)), xlab="Year", ylab="", main="(Log) Real Personal Consumption Expenditures Per Capital", major.format="%YQ%q", auto.grid=FALSE)
plot(xts(dl_rpce, order.by = index(dl_rpce)), xlab="Year", ylab="", main="(Log Diff.) Real Personal Consumption Expenditures Per Capital", major.format="%YQ%q", auto.grid=FALSE)


# ADF

library(tseries)
adf.test(l_rpce)
adf.test(dl_rpce)

# KPSS
library(tseries)
kpss.test(dl_rpce, null="Trend")

# ERS : P-test
library(urca)
dl_rpce.urers1 <- ur.ers(dl_rpce, type="P-test", model="trend")
summary(dl_rpce.urers1)

# ERS : DF-GLS test
library(urca)
dl_rpce.urers2 <- ur.ers(dl_rpce, type="DF-GLS", model="trend")
summary(dl_rpce.urers2)


# B: S&P 500 Index YAHOO/INDEX_GSPC
sp.all <- Quandl("YAHOO/INDEX_GSPC", type = "zoo")
sp <- sp.all$Close
l_sp <- log(sp)
dl_sp <- diff(l_sp)
plot(xts(sp, order.by = index(sp)), xlab="Year", ylab="", main="S&P 500 Index", major.format="%Y/%m/%d", auto.grid=FALSE)
plot(xts(l_sp, order.by = index(l_sp)), xlab="Year", ylab="", main="(Log) S&P 500 Index", major.format="%Y/%m/%d", auto.grid=FALSE)
plot(xts(dl_sp, order.by = index(dl_sp)), xlab="Year", ylab="", main="(Log Diff.) S&P 500 Index", major.format="%Y/%m/%d", auto.grid=FALSE)

# ADF, KPSS and ERS
library(tseries)
adf.test(l_sp)
adf.test(dl_sp)
kpss.test(dl_sp, null="Trend")

library(urca)
dl_sp.urers1 <- ur.ers(dl_sp, type="P-test", model="trend")
summary(dl_sp.urers1)
dl_sp.urers2 <- ur.ers(dl_sp, type="DF-GLS", model="trend")
summary(dl_sp.urers2)


# C: Gross Domestic Product: Implicit Price Deflator, FRED/GDPDEF
def <- Quandl("FRED/GDPDEF", type = "zoo")
l_def <- log(def)
dl_def <- diff(l_def)
d2l_def = diff(dl_def)

plot(xts(def, order.by = index(def)), xlab="Year", ylab="", main="Gross Domestic Product: Implicit Price Deflator", major.format="%YQ%q", auto.grid=FALSE)
plot(xts(l_def, order.by = index(l_def)), xlab="Year", ylab="", main="(Log) Gross Domestic Product: Implicit Price Deflator", major.format="%YQ%q", auto.grid=FALSE)
plot(xts(dl_def, order.by = index(dl_def)), xlab="Year", ylab="", main="(Log Diff.) Gross Domestic Product: Implicit Price Deflator", major.format="%YQ%q", auto.grid=FALSE)
plot(xts(d2l_def, order.by = index(dl_def)), xlab="Year", ylab="", main="(Log 2Diff.) Gross Domestic Product: Implicit Price Deflator", major.format="%YQ%q", auto.grid=FALSE)


# ADF, KPSS and ERS
library(tseries)
adf.test(l_def)
adf.test(dl_def)
kpss.test(dl_def, null="Trend")

library(urca)
dl_def.urers1 <- ur.ers(dl_def, type="P-test", model="trend")
summary(dl_def.urers1)
dl_def.urers2 <- ur.ers(dl_def, type="DF-GLS", model="trend")
summary(dl_def.urers2)

# D: 10-Year Treasury Constant Maturity Rate, FRED/DGS10
tb <- Quandl("FRED/DGS10", type="zoo")
l_tb <- log(tb)
dl_tb <- diff(l_tb)
plot(xts(tb, order.by = index(tb)), xlab="Year", ylab="", main="10-Year Treasury Constant Maturity Rate", major.format="%Y/%m/%d", auto.grid=FALSE)
plot(xts(l_tb, order.by = index(l_tb)), xlab="Year", ylab="", main="(Log) 10-Year Treasury Constant Maturity Rate", major.format="%Y/%m/%d", auto.grid=FALSE)

# ADF, KPSS and ERS
library(tseries)
adf.test(l_tb)
adf.test(dl_tb)
kpss.test(dl_tb, null="Trend")

library(urca)
dl_tb.urers1 <- ur.ers(dl_tb, type="P-test", model="trend")
summary(dl_tb.urers1)
dl_tb.urers2 <- ur.ers(dl_tb, type="DF-GLS", model="trend")
summary(dl_tb.urers2)

# E: Labor Force Participation Rate, FRED/CIVPART
lf <- Quandl("FRED/CIVPART", type="zoo")
l_lf <- log(lf)
dl_lf <- diff(l_lf)
d2l_lf = diff(dl_lf)

plot(xts(lf, order.by = index(lf)), xlab="Year", ylab="", main="Labor Force Participation Rate", major.format="%Y/%m", auto.grid=FALSE)
plot(xts(l_lf, order.by = index(l_lf)), xlab="Year", ylab="", main="(Log) Labor Force Participation Rate", major.format="%Y/%m", auto.grid=FALSE)
plot(xts(dl_lf, order.by = index(dl_lf)), xlab="Year", ylab="", main="(Log Diff.) Labor Force Participation Rate", major.format="%Y/%m", auto.grid=FALSE)
plot(xts(d2l_lf, order.by = index(dl_lf)), xlab="Year", ylab="", main="(Log 2Diff.) Labor Force Participation Rate", major.format="%Y/%m", auto.grid=FALSE)

# ADF, KPSS and ERS
library(tseries)
adf.test(l_lf)
adf.test(dl_lf)
kpss.test(dl_lf, null="Trend")

library(urca)
dl_lf.urers1 <- ur.ers(dl_lf, type="P-test", model="trend")
summary(dl_lf.urers1)
dl_lf.urers2 <- ur.ers(dl_lf, type="DF-GLS", model="trend")
summary(dl_lf.urers2)


# F: Japan / U.K. Foreign Exchange Rate FRED/EXJPUS
jex <- Quandl("FRED/EXJPUS", type="zoo")
l_jex <- log(jex)
dl_jex <- diff(l_jex)
plot(xts(jex, order.by = index(jex)), xlab="Year", ylab="", main="Japan / U.K. Foreign Exchange Rate", major.format="%Y/%m", auto.grid=FALSE)
plot(xts(l_jex, order.by = index(l_jex)), xlab="Year", ylab="", main="(Log) Japan / U.K. Foreign Exchange Rate", major.format="%Y/%m", auto.grid=FALSE)
plot(xts(dl_jex, order.by = index(dl_jex)), xlab="Year", ylab="", main="(Log Diff) Japan / U.K. Foreign Exchange Rate", major.format="%Y/%m", auto.grid=FALSE)

# ADF, KPSS and ERS
library(tseries)
adf.test(l_jex)
adf.test(dl_jex)
kpss.test(dl_jex, null="Trend")

library(urca)
dl_jex.urers1 <- ur.ers(dl_jex, type="P-test", model="trend")
summary(dl_jex.urers1)
dl_jex.urers2 <- ur.ers(dl_jex, type="DF-GLS", model="trend")
summary(dl_jex.urers2)