Question

The Task is to choose a specific time series from each category and for each of the time series set chosen: 1.determine whether to transform it using logarithm. 2.plot the original and transformed time series. 3.Plot first differences of either original or log-transformed time series. 4.Perform ADF,KPSS and ERS tests on either original or log-transformed time series: - If these tests suggest the presence of a unit root also perform these tests for series in first differences, and if necessary also on second differences. 5.Summarize the results of the tests - determine which time series appear to be I(0), I(1), I(2).

The answer: The chosen time series: Category A: Real Personal Consumption Expenditures Per Capita. Category B: Shanghai Composite Index Category C: Consumer Price Index for All Urban Consumers: All Items. Category D: 3-Month Treasury Bills Secondary Market Rate. Category E: Unemployment Rate. Category F: Canada / U.S. Foreign Exchange Rate.

Catogry A

overview

library(Quandl)
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(forecast)
library(urca)
rpce <- Quandl("FRED/A794RX0Q048SBEA", type="zoo")
str(rpce)
## 'zooreg' series from 1947 Q1 to 2016 Q4
##   Data: num [1:280] 8378 8479 8468 8431 8437 ...
##   Index: Class 'yearqtr'  num [1:280] 1947 1947 1948 1948 1948 ...
##   Frequency: 4
summary(rpce)
##      Index           rpce      
##  Min.   :1947   Min.   : 8378  
##  1st Qu.:1964   1st Qu.:11720  
##  Median :1982   Median :17762  
##  Mean   :1982   Mean   :19920  
##  3rd Qu.:1999   3rd Qu.:27782  
##  Max.   :2017   Max.   :35987
head(rpce)
## 1947 Q1 1947 Q2 1947 Q3 1947 Q4 1948 Q1 1948 Q2 
##    8378    8479    8468    8431    8437    8501
tail(rpce)
## 2015 Q3 2015 Q4 2016 Q1 2016 Q2 2016 Q3 2016 Q4 
##   35015   35147   35236   35550   35743   35987

part 1 ,2

Oroginal Data

plot(rpce, xlab="Years", ylab="Thousand $", main="quarterly Real Personal Consumption Expenditures Per Capita")

Logarithm

lrpce <- log(rpce)

plot

plot(lrpce, xlab="Years", ylab="Thousand $", main="Log of quarterly Real Personal Consumption Expenditures Per Capita")

##Part 3 #first differences of original data

drpce <- diff(rpce)
summary(drpce)
##      Index          drpce        
##  Min.   :1947   Min.   :-470.00  
##  1st Qu.:1965   1st Qu.:  24.00  
##  Median :1982   Median : 101.00  
##  Mean   :1982   Mean   :  98.96  
##  3rd Qu.:1999   3rd Qu.: 182.00  
##  Max.   :2017   Max.   : 414.00
plot(drpce, xlab="Years", ylab="Thousand $", main="first differences of quarterly Real Personal Consumption Expenditures Per Capita")

2nd differences of original data.

drpce2 <-diff(drpce)
summary(drpce2)
##      Index          drpce2         
##  Min.   :1948   Min.   :-734.0000  
##  1st Qu.:1965   1st Qu.:-102.0000  
##  Median :1982   Median :  -3.5000  
##  Mean   :1982   Mean   :   0.5144  
##  3rd Qu.:1999   3rd Qu.:  86.7500  
##  Max.   :2017   Max.   : 582.0000
plot(drpce2, type= "l", xlab= "Years", ylab="drpce", main=" Second differences of quarterly Real Personal Consumption Expenditures/Capita", major.format="%Y Q%q")
## Warning in plot.window(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "major.format" is not a graphical
## parameter
## Warning in axis(side, at = z, labels = labels, ...): "major.format" is not
## a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "major.format"
## is not a graphical parameter
## Warning in box(...): "major.format" is not a graphical parameter
## Warning in title(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "major.format" is
## not a graphical parameter

Part 4

ADF,KPSS,ERS tests original data

1.ADF

library(tseries)
adf.test(rpce)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  rpce
## Dickey-Fuller = -2.1827, Lag order = 6, p-value = 0.4991
## alternative hypothesis: stationary
adf.test(drpce)
## Warning in adf.test(drpce): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  drpce
## Dickey-Fuller = -4.9702, Lag order = 6, p-value = 0.01
## alternative hypothesis: stationary
adf.test(drpce2)
## Warning in adf.test(drpce2): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  drpce2
## Dickey-Fuller = -8.1753, Lag order = 6, p-value = 0.01
## alternative hypothesis: stationary

2.KPSS test

kpss.test(rpce, null="Trend")
## Warning in kpss.test(rpce, null = "Trend"): p-value smaller than printed p-
## value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  rpce
## KPSS Trend = 1.327, Truncation lag parameter = 3, p-value = 0.01
kpss.test(drpce, null="Trend")
## Warning in kpss.test(drpce, null = "Trend"): p-value greater than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  drpce
## KPSS Trend = 0.098054, Truncation lag parameter = 3, p-value = 0.1
kpss.test(drpce2, null="Trend")
## Warning in kpss.test(drpce2, null = "Trend"): p-value greater than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  drpce2
## KPSS Trend = 0.0092178, Truncation lag parameter = 3, p-value =
## 0.1

ERS test

rpce.ers <- ur.ers(rpce, type="P-test", model="trend")
summary(rpce.ers)
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type P-test 
## detrending of series with intercept and trend 
## 
## Value of test-statistic is: 39.9552 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
drpce.ers <- ur.ers(drpce, type="P-test", model="trend")
summary(drpce.ers)
## 
## ############################################### 
## # 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.3946 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
drpce2.ers <- ur.ers(drpce2, type="P-test", model="trend")
summary(drpce2.ers)
## 
## ############################################### 
## # 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.1519 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89

Catogry B

overview

library(Quandl)
library(forecast)
library(urca)
SHci <- Quandl("YAHOO/INDEX_SSEC", type="zoo")
str(SHci)
## 'zoo' series from 1997-07-02 to 2017-04-18
##   Data: num [1:4799, 1:6] 1256 1195 1139 1162 1093 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr [1:6] "Open" "High" "Low" "Close" ...
##   Index:  Date[1:4799], format: "1997-07-02" "1997-07-03" "1997-07-04" "1997-07-07" ...
summary(SHci)
##      Index                 Open           High           Low        
##  Min.   :1997-07-02   Min.   :1008   Min.   :1020   Min.   : 998.2  
##  1st Qu.:2002-06-27   1st Qu.:1495   1st Qu.:1508   1st Qu.:1481.2  
##  Median :2007-06-15   Median :2066   Median :2079   Median :2053.0  
##  Mean   :2007-06-04   Mean   :2235   Mean   :2256   Mean   :2211.9  
##  3rd Qu.:2012-05-19   3rd Qu.:2843   3rd Qu.:2875   3rd Qu.:2811.3  
##  Max.   :2017-04-18   Max.   :6057   Max.   :6124   Max.   :6040.7  
##      Close          Volume         Adjusted Close
##  Min.   :1011   Min.   :       0   Min.   :1011  
##  1st Qu.:1495   1st Qu.:       0   1st Qu.:1495  
##  Median :2068   Median :   51400   Median :2068  
##  Mean   :2236   Mean   :   82775   Mean   :2236  
##  3rd Qu.:2847   3rd Qu.:  114400   3rd Qu.:2847  
##  Max.   :6092   Max.   :10065200   Max.   :6092
head(SHci)
##                Open     High      Low    Close Volume Adjusted Close
## 1997-07-02 1255.909 1261.571 1147.331 1199.061      0       1199.061
## 1997-07-03 1194.676 1194.676 1149.940 1150.623      0       1150.623
## 1997-07-04 1138.921 1163.249 1124.776 1159.342      0       1159.342
## 1997-07-07 1161.707 1163.447 1085.572 1096.819      0       1096.819
## 1997-07-08 1092.799 1115.433 1066.044 1109.666      0       1109.666
## 1997-07-09 1113.641 1122.674 1104.086 1120.841      0       1120.841
tail(SHci)
##                Open     High      Low    Close Volume Adjusted Close
## 2017-04-11 3266.222 3290.389 3244.405 3288.966 281300       3288.966
## 2017-04-12 3283.837 3284.934 3262.277 3273.830 269400       3273.830
## 2017-04-13 3265.218 3281.137 3261.490 3275.960 207300       3275.960
## 2017-04-14 3276.138 3276.711 3238.896 3244.483 208100       3244.483
## 2017-04-17 3229.949 3229.949 3199.912 3222.167 212700       3222.167
## 2017-04-18 3215.396 3225.055 3196.488 3196.713 188700       3196.713

part 1 ,2

Oroginal Data

plot(SHci, xlab="Years", ylab="", main="Shanghai Composite daily Index")

Logarithm

lSHci <- log(SHci)

plot

plot(lSHci, xlab="Years", ylab="", main="Log of Shanghai Composite daily Index")

##Part 3 #first differences of original data

dSHci <- diff(SHci)
summary(dSHci)
##      Index                 Open                High          
##  Min.   :1997-07-03   Min.   :-417.3838   Min.   :-382.9287  
##  1st Qu.:2002-06-28   1st Qu.: -15.4878   1st Qu.: -11.6674  
##  Median :2007-06-16   Median :   0.7080   Median :   1.3391  
##  Mean   :2007-06-05   Mean   :   0.4084   Mean   :   0.4092  
##  3rd Qu.:2012-05-20   3rd Qu.:  17.4638   3rd Qu.:  13.3383  
##  Max.   :2017-04-18   Max.   : 423.4558   Max.   : 296.4800  
##       Low                Close               Volume         
##  Min.   :-379.3320   Min.   :-354.6841   Min.   :-10058200  
##  1st Qu.: -13.3188   1st Qu.: -13.8298   1st Qu.:    -4000  
##  Median :   0.1230   Median :   1.1175   Median :        0  
##  Mean   :   0.4271   Mean   :   0.4164   Mean   :       39  
##  3rd Qu.:  15.8318   3rd Qu.:  15.9780   3rd Qu.:     3200  
##  Max.   : 371.7500   Max.   : 351.4028   Max.   : 10060800  
##  Adjusted Close     
##  Min.   :-354.6841  
##  1st Qu.: -13.8298  
##  Median :   1.1175  
##  Mean   :   0.4164  
##  3rd Qu.:  15.9780  
##  Max.   : 351.4028
plot(dSHci, xlab="Years", ylab="", main="first differences of Shanghai Composite daily Index")

2nd differences of original data.

dSHci2 <-diff(dSHci)
summary(dSHci2)
##      Index                 Open                High          
##  Min.   :1997-07-04   Min.   :-501.9382   Min.   :-396.2495  
##  1st Qu.:2002-07-01   1st Qu.: -24.7910   1st Qu.: -17.8320  
##  Median :2007-06-18   Median :  -1.3881   Median :  -1.7361  
##  Mean   :2007-06-05   Mean   :   0.0097   Mean   :   0.0129  
##  3rd Qu.:2012-05-21   3rd Qu.:  24.4680   3rd Qu.:  16.7539  
##  Max.   :2017-04-18   Max.   : 634.3257   Max.   : 419.6191  
##       Low                Close               Volume         
##  Min.   :-466.2334   Min.   :-447.7144   Min.   :-20119000  
##  1st Qu.: -20.9869   1st Qu.: -23.2788   1st Qu.:    -5200  
##  Median :   0.4279   Median :  -1.6161   Median :        0  
##  Mean   :  -0.0013   Mean   :   0.0048   Mean   :       -5  
##  3rd Qu.:  20.1458   3rd Qu.:  22.6301   3rd Qu.:     6800  
##  Max.   : 533.5911   Max.   : 497.9800   Max.   : 10061400  
##  Adjusted Close     
##  Min.   :-447.7144  
##  1st Qu.: -23.2788  
##  Median :  -1.6161  
##  Mean   :   0.0048  
##  3rd Qu.:  22.6301  
##  Max.   : 497.9800
plot(dSHci2, type= "l", xlab= "Years", ylab="dSHci", main="Second differences of Shanghai Composite daily Index", major.format="%Y Q%q")
## Warning in plot.window(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "major.format" is not a graphical
## parameter
## Warning in axis(side, at = z, labels = labels, ...): "major.format" is not
## a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "major.format"
## is not a graphical parameter
## Warning in box(...): "major.format" is not a graphical parameter
## Warning in title(...): "major.format" is not a graphical parameter
## Warning in axis(side = 2, xpd = NA, major.format = "%Y Q%q"):
## "major.format" is not a graphical parameter
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "major.format" is
## not a graphical parameter
## Warning in plot.window(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "major.format" is not a graphical
## parameter
## Warning in axis(side, at = z, labels = labels, ...): "major.format" is not
## a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "major.format"
## is not a graphical parameter
## Warning in box(...): "major.format" is not a graphical parameter
## Warning in title(...): "major.format" is not a graphical parameter
## Warning in axis(side = 2, xpd = NA, major.format = "%Y Q%q"):
## "major.format" is not a graphical parameter
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "major.format" is
## not a graphical parameter
## Warning in plot.window(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "major.format" is not a graphical
## parameter
## Warning in axis(side, at = z, labels = labels, ...): "major.format" is not
## a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "major.format"
## is not a graphical parameter
## Warning in box(...): "major.format" is not a graphical parameter
## Warning in title(...): "major.format" is not a graphical parameter
## Warning in axis(side = 2, xpd = NA, major.format = "%Y Q%q"):
## "major.format" is not a graphical parameter
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "major.format" is
## not a graphical parameter
## Warning in plot.window(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "major.format" is not a graphical
## parameter
## Warning in axis(side, at = z, labels = labels, ...): "major.format" is not
## a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "major.format"
## is not a graphical parameter
## Warning in box(...): "major.format" is not a graphical parameter
## Warning in title(...): "major.format" is not a graphical parameter
## Warning in axis(side = 2, xpd = NA, major.format = "%Y Q%q"):
## "major.format" is not a graphical parameter
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "major.format" is
## not a graphical parameter
## Warning in plot.window(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "major.format" is not a graphical
## parameter
## Warning in axis(side, at = z, labels = labels, ...): "major.format" is not
## a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "major.format"
## is not a graphical parameter
## Warning in box(...): "major.format" is not a graphical parameter
## Warning in title(...): "major.format" is not a graphical parameter
## Warning in axis(side = 2, xpd = NA, major.format = "%Y Q%q"):
## "major.format" is not a graphical parameter
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "major.format" is
## not a graphical parameter
## Warning in plot.window(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "major.format" is not a graphical
## parameter
## Warning in axis(side, at = z, labels = labels, ...): "major.format" is not
## a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "major.format"
## is not a graphical parameter
## Warning in box(...): "major.format" is not a graphical parameter
## Warning in title(...): "major.format" is not a graphical parameter
## Warning in axis(side = 2, xpd = NA, major.format = "%Y Q%q"):
## "major.format" is not a graphical parameter
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "major.format" is
## not a graphical parameter

Part 4

ADF,KPSS,ERS tests original data

1.ADF Couldn’t preform

2.KPSS test

SHci.urkpss <- ur.kpss(SHci, type="tau", lags="short")
summary(SHci.urkpss)
## 
## ####################### 
## # KPSS Unit Root Test # 
## ####################### 
## 
## Test is of type: tau with 16 lags. 
## 
## Value of test-statistic is: 3.2268 
## 
## Critical value for a significance level of: 
##                 10pct  5pct 2.5pct  1pct
## critical values 0.119 0.146  0.176 0.216
dSHci.urkpss <- ur.kpss(dSHci, type="tau", lags="short")
summary(dSHci.urkpss)
## 
## ####################### 
## # KPSS Unit Root Test # 
## ####################### 
## 
## Test is of type: tau with 16 lags. 
## 
## Value of test-statistic is: 4e-04 
## 
## Critical value for a significance level of: 
##                 10pct  5pct 2.5pct  1pct
## critical values 0.119 0.146  0.176 0.216
dSHci2.urkpss <- ur.kpss(dSHci2, type="tau", lags="short")
summary(dSHci2.urkpss)
## 
## ####################### 
## # KPSS Unit Root Test # 
## ####################### 
## 
## Test is of type: tau with 16 lags. 
## 
## Value of test-statistic is: 3e-04 
## 
## Critical value for a significance level of: 
##                 10pct  5pct 2.5pct  1pct
## critical values 0.119 0.146  0.176 0.216

ERS test

SHci.ers <- ur.ers(SHci, type="P-test", model="trend")
summary(SHci.ers)
## 
## ############################################### 
## # 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.0603 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
dSHci.ers <- ur.ers(dSHci, type="P-test", model="trend")
summary(dSHci.ers)
## 
## ############################################### 
## # 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.0512 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
dSHci2.ers <- ur.ers(dSHci2, type="P-test", model="trend")
summary(dSHci2.ers)
## 
## ############################################### 
## # 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.7694 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89

Catogry C

overview

library(Quandl)
library(forecast)
library(urca)
cpi <- Quandl("FRED/CPIAUCSL", type="zoo")
str(cpi)
## 'zooreg' series from Jan 1947 to Mar 2017
##   Data: num [1:843] 21.5 21.6 22 22 21.9 ...
##   Index: Class 'yearmon'  num [1:843] 1947 1947 1947 1947 1947 ...
##   Frequency: 12
summary(cpi)
##      Index           cpi        
##  Min.   :1947   Min.   : 21.48  
##  1st Qu.:1965   1st Qu.: 31.04  
##  Median :1982   Median : 94.70  
##  Mean   :1982   Mean   :104.58  
##  3rd Qu.:2000   3rd Qu.:167.45  
##  Max.   :2017   Max.   :244.46
head(cpi)
## Jan 1947 Feb 1947 Mar 1947 Apr 1947 May 1947 Jun 1947 
##    21.48    21.62    22.00    22.00    21.95    22.08
tail(cpi)
## Oct 2016 Nov 2016 Dec 2016 Jan 2017 Feb 2017 Mar 2017 
##  241.694  242.199  242.821  244.158  244.456  243.752

part 1 ,2

Oroginal Data

plot(cpi, xlab="Years", ylab="", main="consumer Price Index for All Urban Consumers")

Logarithm

lcpi <- log(cpi)

plot

plot(lcpi, xlab="Years", ylab="", main="Log of consumer Price Index for All Urban Consumers")

##Part 3 #first differences of original data

dcpi <- diff(cpi)
summary(dcpi)
##      Index           dcpi       
##  Min.   :1947   Min.   :-3.842  
##  1st Qu.:1965   1st Qu.: 0.057  
##  Median :1982   Median : 0.200  
##  Mean   :1982   Mean   : 0.264  
##  3rd Qu.:2000   3rd Qu.: 0.400  
##  Max.   :2017   Max.   : 2.700
plot(dcpi, xlab="Years", ylab="", main="first differences of consumer Price Index for All Urban Consumers")

2nd differences of original data.

dcpi2 <-diff(dcpi)
summary(dcpi2)
##      Index          dcpi2          
##  Min.   :1947   Min.   :-2.400000  
##  1st Qu.:1965   1st Qu.:-0.100000  
##  Median :1982   Median : 0.000000  
##  Mean   :1982   Mean   :-0.001004  
##  3rd Qu.:2000   3rd Qu.: 0.100000  
##  Max.   :2017   Max.   : 2.290000
plot(dcpi2, type= "l", xlab= "Years", ylab="dcpi", main="Second differences of consumer Price Index for All Urban Consumers", major.format="%Y Q%q")
## Warning in plot.window(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "major.format" is not a graphical
## parameter
## Warning in axis(side, at = z, labels = labels, ...): "major.format" is not
## a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "major.format"
## is not a graphical parameter
## Warning in box(...): "major.format" is not a graphical parameter
## Warning in title(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "major.format" is
## not a graphical parameter

Part 4

ADF,KPSS,ERS tests original data

1.ADF

library(tseries)
adf.test(cpi)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  cpi
## Dickey-Fuller = -2.8415, Lag order = 9, p-value = 0.2221
## alternative hypothesis: stationary
adf.test(dcpi)
## Warning in adf.test(dcpi): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dcpi
## Dickey-Fuller = -6.4061, Lag order = 9, p-value = 0.01
## alternative hypothesis: stationary
adf.test(dcpi2)
## Warning in adf.test(dcpi2): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dcpi2
## Dickey-Fuller = -16.132, Lag order = 9, p-value = 0.01
## alternative hypothesis: stationary

2.KPSS test

kpss.test(cpi, null="Trend")
## Warning in kpss.test(cpi, null = "Trend"): p-value smaller than printed p-
## value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  cpi
## KPSS Trend = 2.593, Truncation lag parameter = 6, p-value = 0.01
kpss.test(dcpi, null="Trend")
## Warning in kpss.test(dcpi, null = "Trend"): p-value smaller than printed p-
## value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dcpi
## KPSS Trend = 0.53688, Truncation lag parameter = 6, p-value = 0.01
kpss.test(dcpi2, null="Trend")
## Warning in kpss.test(dcpi2, null = "Trend"): p-value greater than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dcpi2
## KPSS Trend = 0.0092016, Truncation lag parameter = 6, p-value =
## 0.1

ERS test

cpi.ers <- ur.ers(cpi, type="P-test", model="trend")
summary(cpi.ers)
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type P-test 
## detrending of series with intercept and trend 
## 
## Value of test-statistic is: 430.6597 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
dcpi.ers <- ur.ers(dcpi, type="P-test", model="trend")
summary(dcpi.ers)
## 
## ############################################### 
## # 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.7125 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
dcpi2.ers <- ur.ers(dcpi2, type="P-test", model="trend")
summary(dcpi2.ers)
## 
## ############################################### 
## # 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.6564 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89

Catogry D

overview

library(Quandl)
library(forecast)
library(urca)
TBsmr <- Quandl("FRED/TB3MS", type="zoo")
str(TBsmr)
## 'zooreg' series from Jan 1934 to Mar 2017
##   Data: num [1:999] 0.72 0.62 0.24 0.15 0.16 0.15 0.15 0.19 0.21 0.27 ...
##   Index: Class 'yearmon'  num [1:999] 1934 1934 1934 1934 1934 ...
##   Frequency: 12
summary(TBsmr)
##      Index          TBsmr       
##  Min.   :1934   Min.   : 0.010  
##  1st Qu.:1955   1st Qu.: 0.380  
##  Median :1976   Median : 3.040  
##  Mean   :1976   Mean   : 3.521  
##  3rd Qu.:1996   3rd Qu.: 5.355  
##  Max.   :2017   Max.   :16.300
head(TBsmr)
## Jan 1934 Feb 1934 Mar 1934 Apr 1934 May 1934 Jun 1934 
##     0.72     0.62     0.24     0.15     0.16     0.15
tail(TBsmr)
## Oct 2016 Nov 2016 Dec 2016 Jan 2017 Feb 2017 Mar 2017 
##     0.33     0.45     0.51     0.51     0.52     0.74

part 1 ,2

Oroginal Data

plot(TBsmr, xlab="Years", ylab="", main="3-Month Treasury Bills Secondary Market Rate")

Logarithm

lTBsmr <- log(TBsmr)

plot

plot(lTBsmr, xlab="Years", ylab="", main="Log of 3-Month Treasury Bills Secondary Market Rate")

##Part 3 #first differences of original data

dTBsmr <- diff(TBsmr)
summary(dTBsmr)
##      Index          dTBsmr        
##  Min.   :1934   Min.   :-4.62000  
##  1st Qu.:1955   1st Qu.:-0.05000  
##  Median :1976   Median : 0.00000  
##  Mean   :1976   Mean   : 0.00002  
##  3rd Qu.:1996   3rd Qu.: 0.09000  
##  Max.   :2017   Max.   : 2.61000
plot(dTBsmr, xlab="Years", ylab="", main="first differences of 3-Month Treasury Bills Secondary Market Rate")

2nd differences of original data.

dTBsmr2 <-diff(dTBsmr)
summary(dTBsmr2)
##      Index         dTBsmr2         
##  Min.   :1934   Min.   :-4.340000  
##  1st Qu.:1955   1st Qu.:-0.080000  
##  Median :1976   Median : 0.000000  
##  Mean   :1976   Mean   : 0.000321  
##  3rd Qu.:1996   3rd Qu.: 0.090000  
##  Max.   :2017   Max.   : 3.110000
plot(dTBsmr2, type= "l", xlab= "Years", ylab="dTBsmr", main="Second differences of 3-Month Treasury Bills Secondary Market Rate", major.format="%Y Q%q")
## Warning in plot.window(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "major.format" is not a graphical
## parameter
## Warning in axis(side, at = z, labels = labels, ...): "major.format" is not
## a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "major.format"
## is not a graphical parameter
## Warning in box(...): "major.format" is not a graphical parameter
## Warning in title(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "major.format" is
## not a graphical parameter

Part 4

ADF,KPSS,ERS tests original data

1.ADF

library(tseries)
adf.test(TBsmr)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  TBsmr
## Dickey-Fuller = -2.1747, Lag order = 9, p-value = 0.5044
## alternative hypothesis: stationary
adf.test(dTBsmr)
## Warning in adf.test(dTBsmr): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dTBsmr
## Dickey-Fuller = -9.4505, Lag order = 9, p-value = 0.01
## alternative hypothesis: stationary
adf.test(dTBsmr2)
## Warning in adf.test(dTBsmr2): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dTBsmr2
## Dickey-Fuller = -18.521, Lag order = 9, p-value = 0.01
## alternative hypothesis: stationary

2.KPSS test

kpss.test(TBsmr, null="Trend")
## Warning in kpss.test(TBsmr, null = "Trend"): p-value smaller than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  TBsmr
## KPSS Trend = 2.311, Truncation lag parameter = 7, p-value = 0.01
kpss.test(dTBsmr, null="Trend")
## Warning in kpss.test(dTBsmr, null = "Trend"): p-value greater than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dTBsmr
## KPSS Trend = 0.034017, Truncation lag parameter = 7, p-value = 0.1
kpss.test(dTBsmr2, null="Trend")
## Warning in kpss.test(dTBsmr2, null = "Trend"): p-value greater than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dTBsmr2
## KPSS Trend = 0.0047924, Truncation lag parameter = 7, p-value =
## 0.1

ERS test

TBsmr.ers <- ur.ers(TBsmr, type="P-test", model="trend")
summary(TBsmr.ers)
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type P-test 
## detrending of series with intercept and trend 
## 
## Value of test-statistic is: 11.6282 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
dTBsmr.ers <- ur.ers(dTBsmr, type="P-test", model="trend")
summary(dTBsmr.ers)
## 
## ############################################### 
## # 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.1397 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
dTBsmr2.ers <- ur.ers(dTBsmr2, type="P-test", model="trend")
summary(dTBsmr2.ers)
## 
## ############################################### 
## # 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.1808 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89

Catogry E

overview

library(Quandl)
library(forecast)
library(urca)
Unr <- Quandl("FRED/UNRATE", type="zoo")
str(Unr)
## 'zooreg' series from Jan 1948 to Mar 2017
##   Data: num [1:831] 3.4 3.8 4 3.9 3.5 3.6 3.6 3.9 3.8 3.7 ...
##   Index: Class 'yearmon'  num [1:831] 1948 1948 1948 1948 1948 ...
##   Frequency: 12
summary(Unr)
##      Index           Unr        
##  Min.   :1948   Min.   : 2.500  
##  1st Qu.:1965   1st Qu.: 4.700  
##  Median :1983   Median : 5.600  
##  Mean   :1983   Mean   : 5.806  
##  3rd Qu.:2000   3rd Qu.: 6.900  
##  Max.   :2017   Max.   :10.800
head(Unr)
## Jan 1948 Feb 1948 Mar 1948 Apr 1948 May 1948 Jun 1948 
##      3.4      3.8      4.0      3.9      3.5      3.6
tail(Unr)
## Oct 2016 Nov 2016 Dec 2016 Jan 2017 Feb 2017 Mar 2017 
##      4.8      4.6      4.7      4.8      4.7      4.5

part 1 ,2

Oroginal Data

plot(Unr, xlab="Years", ylab="", main="Unemployment Rate")

Logarithm

lUnr <- log(Unr)

plot

plot(lUnr, xlab="Years", ylab="", main="Log of Unemployment Rate")

##Part 3 #first differences of original data

dUnr <- diff(Unr)
summary(dUnr)
##      Index           dUnr          
##  Min.   :1948   Min.   :-1.500000  
##  1st Qu.:1965   1st Qu.:-0.100000  
##  Median :1983   Median : 0.000000  
##  Mean   :1983   Mean   : 0.001325  
##  3rd Qu.:2000   3rd Qu.: 0.100000  
##  Max.   :2017   Max.   : 1.300000
plot(dUnr, xlab="Years", ylab="", main="first differences of Unemployment Rate")

2nd differences of original data.

dUnr2 <-diff(dUnr)
summary(dUnr2)
##      Index          dUnr2           
##  Min.   :1948   Min.   :-2.8000000  
##  1st Qu.:1965   1st Qu.:-0.2000000  
##  Median :1983   Median : 0.0000000  
##  Mean   :1983   Mean   :-0.0007238  
##  3rd Qu.:2000   3rd Qu.: 0.2000000  
##  Max.   :2017   Max.   : 1.7000000
plot(dUnr2, type= "l", xlab= "Years", ylab="dUnr", main="Second differences of Unemployment Rate", major.format="%Y Q%q")
## Warning in plot.window(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "major.format" is not a graphical
## parameter
## Warning in axis(side, at = z, labels = labels, ...): "major.format" is not
## a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "major.format"
## is not a graphical parameter
## Warning in box(...): "major.format" is not a graphical parameter
## Warning in title(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "major.format" is
## not a graphical parameter

Part 4

ADF,KPSS,ERS tests original data

1.ADF

library(tseries)
adf.test(Unr)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  Unr
## Dickey-Fuller = -3.9387, Lag order = 9, p-value = 0.01206
## alternative hypothesis: stationary
adf.test(dUnr)
## Warning in adf.test(dUnr): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dUnr
## Dickey-Fuller = -8.2844, Lag order = 9, p-value = 0.01
## alternative hypothesis: stationary
adf.test(dUnr2)
## Warning in adf.test(dUnr2): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dUnr2
## Dickey-Fuller = -12.179, Lag order = 9, p-value = 0.01
## alternative hypothesis: stationary

2.KPSS test

kpss.test(Unr, null="Trend")
## Warning in kpss.test(Unr, null = "Trend"): p-value smaller than printed p-
## value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  Unr
## KPSS Trend = 0.50543, Truncation lag parameter = 6, p-value = 0.01
kpss.test(dUnr, null="Trend")
## Warning in kpss.test(dUnr, null = "Trend"): p-value greater than printed p-
## value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dUnr
## KPSS Trend = 0.031636, Truncation lag parameter = 6, p-value = 0.1
kpss.test(dUnr2, null="Trend")
## Warning in kpss.test(dUnr2, null = "Trend"): p-value greater than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dUnr2
## KPSS Trend = 0.0073992, Truncation lag parameter = 6, p-value =
## 0.1

ERS test

Unr.ers <- ur.ers(Unr, type="P-test", model="trend")
summary(Unr.ers)
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type P-test 
## detrending of series with intercept and trend 
## 
## Value of test-statistic is: 3.8756 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
dUnr.ers <- ur.ers(dUnr, type="P-test", model="trend")
summary(dUnr.ers)
## 
## ############################################### 
## # 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.1915 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
dUnr2.ers <- ur.ers(dUnr2, type="P-test", model="trend")
summary(dUnr2.ers)
## 
## ############################################### 
## # 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.3631 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89

Catogry F

overview

library(Quandl)
library(forecast)
library(urca)
CUSAfex <- Quandl("FRED/EXCAUS", type="zoo")
str(CUSAfex)
## 'zooreg' series from Jan 1971 to Apr 2017
##   Data: num [1:556] 1.01 1.01 1.01 1.01 1.01 ...
##   Index: Class 'yearmon'  num [1:556] 1971 1971 1971 1971 1971 ...
##   Frequency: 12
summary(CUSAfex)
##      Index         CUSAfex      
##  Min.   :1971   Min.   :0.9553  
##  1st Qu.:1983   1st Qu.:1.0576  
##  Median :1994   Median :1.1988  
##  Mean   :1994   Mean   :1.2170  
##  3rd Qu.:2006   3rd Qu.:1.3508  
##  Max.   :2017   Max.   :1.5997
head(CUSAfex)
## Jan 1971 Feb 1971 Mar 1971 Apr 1971 May 1971 Jun 1971 
##   1.0118   1.0075   1.0064   1.0077   1.0087   1.0213
tail(CUSAfex)
## Nov 2016 Dec 2016 Jan 2017 Feb 2017 Mar 2017 Apr 2017 
##   1.3434   1.3339   1.3183   1.3109   1.3387   1.3358

part 1 ,2

Oroginal Data

plot(CUSAfex, xlab="Years", ylab="", main="Canada / U.S. Foreign Exchange Rate")

Logarithm

lCUSAfex <- log(CUSAfex)

plot

plot(lCUSAfex, xlab="Years", ylab="", main="Log of Canada / U.S. Foreign Exchange Rate")

##Part 3 #first differences of original data

dCUSAfex <- diff(CUSAfex)
summary(dCUSAfex)
##      Index         dCUSAfex         
##  Min.   :1971   Min.   :-0.0742000  
##  1st Qu.:1983   1st Qu.:-0.0090000  
##  Median :1994   Median : 0.0001000  
##  Mean   :1994   Mean   : 0.0005838  
##  3rd Qu.:2006   3rd Qu.: 0.0105500  
##  Max.   :2017   Max.   : 0.1265000
plot(dCUSAfex, xlab="Years", ylab="", main="first differences of Canada / U.S. Foreign Exchange Rate")

2nd differences of original data.

dCUSAfex2 <-diff(dCUSAfex)
summary(dCUSAfex2)
##      Index        dCUSAfex2         
##  Min.   :1971   Min.   :-9.410e-02  
##  1st Qu.:1983   1st Qu.:-1.130e-02  
##  Median :1994   Median : 2.000e-04  
##  Mean   :1994   Mean   : 2.530e-06  
##  3rd Qu.:2006   3rd Qu.: 1.140e-02  
##  Max.   :2017   Max.   : 1.218e-01
plot(dCUSAfex2, type= "l", xlab= "Years", ylab="dCUSAfex", main="Second differences of Canada / U.S. Foreign Exchange Rate", major.format="%Y Q%q")
## Warning in plot.window(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "major.format" is not a graphical
## parameter
## Warning in axis(side, at = z, labels = labels, ...): "major.format" is not
## a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "major.format"
## is not a graphical parameter
## Warning in box(...): "major.format" is not a graphical parameter
## Warning in title(...): "major.format" is not a graphical parameter
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "major.format" is
## not a graphical parameter

Part 4

ADF,KPSS,ERS tests original data

1.ADF

library(tseries)
adf.test(CUSAfex)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  CUSAfex
## Dickey-Fuller = -1.7258, Lag order = 8, p-value = 0.6944
## alternative hypothesis: stationary
adf.test(dCUSAfex)
## Warning in adf.test(dCUSAfex): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dCUSAfex
## Dickey-Fuller = -7.6633, Lag order = 8, p-value = 0.01
## alternative hypothesis: stationary
adf.test(dCUSAfex2)
## Warning in adf.test(dCUSAfex2): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dCUSAfex2
## Dickey-Fuller = -14.707, Lag order = 8, p-value = 0.01
## alternative hypothesis: stationary

2.KPSS test

kpss.test(CUSAfex, null="Trend")
## Warning in kpss.test(CUSAfex, null = "Trend"): p-value smaller than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  CUSAfex
## KPSS Trend = 1.3198, Truncation lag parameter = 5, p-value = 0.01
kpss.test(dCUSAfex, null="Trend")
## Warning in kpss.test(dCUSAfex, null = "Trend"): p-value greater than
## printed p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dCUSAfex
## KPSS Trend = 0.098258, Truncation lag parameter = 5, p-value = 0.1
kpss.test(dCUSAfex2, null="Trend")
## Warning in kpss.test(dCUSAfex2, null = "Trend"): p-value greater than
## printed p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dCUSAfex2
## KPSS Trend = 0.0054261, Truncation lag parameter = 5, p-value =
## 0.1

ERS test

CUSAfex.ers <- ur.ers(CUSAfex, type="P-test", model="trend")
summary(CUSAfex.ers)
## 
## ############################################### 
## # Elliot, Rothenberg and Stock Unit Root Test # 
## ############################################### 
## 
## Test of type P-test 
## detrending of series with intercept and trend 
## 
## Value of test-statistic is: 18.2746 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
dCUSAfex.ers <- ur.ers(dCUSAfex, type="P-test", model="trend")
summary(dCUSAfex.ers)
## 
## ############################################### 
## # 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.3213 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89
dCUSAfex2.ers <- ur.ers(dCUSAfex2, type="P-test", model="trend")
summary(dCUSAfex2.ers)
## 
## ############################################### 
## # 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.0012 
## 
## Critical values of P-test are:
##                 1pct 5pct 10pct
## critical values 3.96 5.62  6.89