Professional Documents
Culture Documents
http://www.econ.uiuc.edu/~econ472/tutorial9.html
Copy and paste the following lines to a blank word document.
Create a subdirectory on your C drive called data. (c:/data)
Use the Edit menu of MS-word and save as
file name is eggs and file type is Plain Text which is not visible at
first blush
Try to open in word the following to make sure typing of names is
correct
c:/data/eggs.txt
money=read.table("c:/data/eggs.txt",header=T)
year
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
chic
468491
449743
436815
444523
433937
389958
403446
423921
389624
418591
438288
422841
476935
542047
582197
516497
523227
467217
499644
430876
456549
430988
426555
398156
396776
390708
383690
391363
374281
387002
369484
366082
377392
375575
382262
394118
393019
428746
425158
422096
egg
3581
3532
3327
3255
3156
3081
3166
3443
3424
3561
3640
3840
4456
5000
5366
5154
5130
5077
5032
5148
5404
5322
5323
5307
5402
5407
5500
5442
5442
5542
5339
5358
5403
5345
5435
5474
5540
5836
5777
5629
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
433280
421763
404191
408769
394101
379754
378361
386518
396933
400585
392110
384838
378609
364584
5704
5806
5742
5502
5461
5382
5377
5408
5608
5777
5825
5625
5800
5656
yt-1 + t
Need to test each series separately. (In the above table see under t
values
and note the statistic of -1.998. This is the test statistic of interest.
We can compare it with Dickey Fuller Tables for significance.
Bannerjee et al page 103 table says
i) Models with intercept and trend (int=T, trend=T)
(ii) Models with intercept but without trend (int=T, trend=F)
(iii) Models without intercept and without trend (int=F, trend=F)
Method 2 in R for doing unit root testing
library(tseries)
adf.test(chic, k=1) #this automatically looks up DF tables and gives pvalues.
# It assumes trend and intercept are present, using k lags in the
regression
Augmented Dickey-Fuller Test
The results are:
data: chic
Dickey-Fuller = -1.998, Lag order = 1, p-value = 0.5753
alternative hypothesis: stationary
p-value is large means we accept the null and reject the alternative.
There is unit root in chicken data.
#adf.test(variable name)$p.value extracts the p-value if one uses
tseries library
Method 3 in R for doing unit root testing
library(urca)
chic.df <- ur.df(y=chic, lags=1, type='trend')
summary(chic.df)
###############################################
# Augmented Dickey-Fuller Test Unit Root Test #
###############################################
Test regression trend
Call:
lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 8.329e+04 4.260e+04
1.955
0.0564 .
z.lag.1
-1.821e-01 9.112e-02 -1.998
0.0514 .
tt
-3.156e+02 2.670e+02 -1.182
0.2429
z.diff.lag -8.620e-02 1.435e-01 -0.601
0.5510
--Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
Residual standard error: 25030 on 48 degrees of freedom
Multiple R-Squared: 0.1067,
Adjusted R-squared: 0.05085
F-statistic: 1.911 on 3 and 48 DF, p-value: 0.1404
Value of test-statistic is: -1.998
Critical values for test statistics:
1%
5%
10%
tau3 -3.98 -3.42 -3.13
Since observed test stat is more extreme than critical value, we reject
the null of unit root in chicken data by this method. So the results do
not agree with ADF tests above.
KPSS test is a fashionable unit root test it has the null of stationarity
and alternative hypothesis of unit root (unlike above tests). The urca
package can all it as follows:
kpss.chic <- ur.kpss(chic, type="tau", lags="short")
summary(kpss.chic)
# KPSS Unit Root Test #
Test is of type: tau with 3 lags.
Value of test-statistic is: 0.0864
Critical value for a significance level of:
10%
5% 2.5%
1%
critical values 0.119 0.146 0.176 0.216
Here the test stat is smaller than critical values so we accept the null of stationarity and
reject the unit root in chicken data. Again this does not agree with ADF test results.
data(npext) #Nelson Plosser data
attach(npext)
#nomgnp (nominal GNP) interest indprod gnpperca
# realgnp
wages
realwag
sp500
# unemploy
velocity
# we know nominal GNP goes up up and away, so does have unit root
kpss.nomgnp= ur.kpss(nomgnp, type="tau", lags="short")
#gives test stat = 0.3411 > crit values 0.119 0.146 0.176 0.216 for
#10%
5% 2.5%
1%. Thus nominal GNP does have unit root nonstationarity
egg
-10.219
7.133
-1.433
0.158
Plot also the residuals versus lagged residuals. Draw your conclusions
(iii) Test whether the residuals are I(0).
This is a residual-based version of the ADF test. The only difference
from the traditional ADF to (this version of) the Engle-Granger test
are the critical values. The critical values to be used here are no
longer the same provided by Dickey-Fuller, but instead provided by
Engle and Yoo (1987) and others (see approximated critical values in
Table B.9, Hamilton 1994). This happens because the residuals above
are not the actual error terms, but estimated values from the long run
equilibrium equation of chickens against eggs.
adf.test(residual, k=1)
#Augmented Dickey-Fuller Test
#data: residual
#Dickey-Fuller = -2.0247, Lag order = 1, p-value = 0.5645
#alternative hypothesis: stationary
- j))
}
iys <- 1 + (L + 1) * (0:(p - 1))
Y <- D[, iys]
X <- D[, - iys]
Ly <- ts.intersect(Ly, D)[, 1:p]
ZD <- lm(Y ~ X)$resid
ZL <- lm(Ly ~ X)$resid
df <- nrow(X) - ncol(X) - 1
S00 <- crossprod(ZD)/df
S11 <- crossprod(ZL)/df
S01 <- crossprod(ZD, ZL)/df
M <- solve(S11) %*% t(S01) %*% solve(S00) %*% S01
eigen(M)$values
}
#To this point.
Your job is to copy the code above and paste in the R console. This will
create a R function called "johansen" that calculates the eigenvalues.
The command to obtain the eigenvalues is:
johansen(cbind(egg,chic), L=1)
[1] 0.16562116 0.05024913
The code above refers to the case including trend and intercept, and
the appropriate critical values should be used. Note that the
theoretical background here is essential, given that you need to
interpret the eigenvalues and calculate the test statistic by yourself,
before to draw your conclusions.
library(urca)
data(npext)
attach(npext)
#nomgnp (nominal GNP) interest indprod gnpperca
# realgnp
wages
realwag
sp500
# unemploy
velocity
np4=cbind(interest, indprod, gnpperca, wages)
np4.vecm <- ca.jo(np4, constant=TRUE, type="eigen", K=2, spec="longrun",
season=4, ctable="A3")
summary(np4.vecm)
<= 3
<= 2
<= 1
= 0
test
10%
5%
1%
| 4.70 7.56 9.09 12.74
| 9.69 13.78 15.75 19.83
| 19.97 19.80 21.89 26.41
| 23.30 25.61 28.17 33.12
accept
reject
accept
accept
null at 5%
null at 5%
null
null
Weights W:
(This is the loading matrix)
[1,]
[2,]
[3,]
[4,]
[,1]
[,2]
[,3]
[,4]
[,5]
-7.790924e-04 -0.012636958 0.0007507385 -0.0644947339 1.719589e-15
-1.876329e-03 0.011329379 -0.0095969956 -0.0005951474 9.891543e-16
-7.962321e-06 0.006601913 -0.0056842480 -0.0004599648 1.300587e-16
-6.189149e-04 0.008883549 0.0006473886 -0.0010482132 -6.601809e-16
test
5.56
10%
7.56
5%
1%
9.09 12.74
accept at 5%
r = 0
accept at 5%
Weights W:
(This is the loading matrix)
[,1]
[,2]
[,3]
[1,] -1.638589e-01 -0.046540914 -2.984694e-16
[2,] -2.771808e-05 -0.000542545 1.321877e-18