0% found this document useful (0 votes)
20 views21 pages

Handout 4 Cointegration

Uploaded by

Bot Gamers
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views21 pages

Handout 4 Cointegration

Uploaded by

Bot Gamers
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

EC226 (Term 2: Handout 4) 1 DEFINITION

Cointegration
Reading:

• Stock and Watson (2003): Chapter 16

• Dougherty (2016): Chapter 13

• Wooldridge (2013): Chapter 18

1 Definition
The variables yt and xt are said to be cointegrated of order d, b, denoted, if

1. the variables yt and xt are I(d), that is, they need d differences to induce stationarity

2. there exists a vector β (̸= 0) so that εt = yt − βxt ∼ I(d − b)

The coefficient β is called the cointegrating vector (the coefficient parameter in the case of there
just be two variables). In economics the case generally considered is when d = b=1. This is an
important result as any arbitrary linear combination of I(1) series will be I(1) (unless the series are
cointegrated).
NOTE:
You cannot find cointegration between an I(0) (stationary) dependent variable and I(1) (non-stationary)
explanatory variables. Similarly cointegration cannot be between an I(1) dependent variable and I(0)
explanatory variables). Both of these regressions would be unbalanced (in that the variables are
not all integrated of the same order).
For the series to be cointegrated if they must have a common I(1) (stochastic trend) compo-
nent, such that a linear combination of the series eliminates this common stochastic trend.
Consider, for example,
t
X
xt = ξt + εt = zt + εt
j=1

and xt is made up of two elements:


P
1. the I(1) component, (which is the stochastic trend) zt = ξj
j

2. a stationary I(0) component, εt

If we also have:
yt = βzt + ςt

then yt has the same I(1) stochastic trend component zt as well as a distinction stationary term, ςt .
There is a linear combination of yt and xt will eliminate the common stochastic trend, zt , and this
is written as:
yt − βxt = (βzt + ς) − β(zy + εt ) = ςt − βεt
| {z }
εt

the right hand side term ςt − βεt is a linear combination of two I(0) series and is therefore I(0) 1 . This
means that while yt and xt are both I(1), there is a linear combination yt − βxt which is I(0) and
1 Any linear combination of stationary (I(0)) series must itself be stationary (I(0))

1
EC226 (Term 2: Handout 4) 1 DEFINITION

this is an example of cointegration, which is whether there is a linear combination of non-stationary


series which produces a stationary series - implying the there is co-movement in the integrated series
and hence the term cointegration.
One can think of cointegrating equations as long-run “equilibrium” equations between economic vari-
ables, then it seems sensible to try and discover and make use of these relationships. An alternative
approach to discovering the relationship between I(1) series is to make all of the series I(0) series
(by taking a first difference of the series) and then to look for linear relationships between these I(0)
series. However, this approach throws useful long-run information away as it is solely concerned with
short-run movements, ie. the value of a series today, yt , compared to its previous period yt−1 .

2
EC226 (Term 2: Handout 4) 2 SPURIOUS VS COINTEGRATING RELATIONSHIPS

2 Spurious vs cointegrating relationships


In trying to find equilibrium (long-run) relationships between I(1) series, one needs to be careful
to distinguish cointegrating relationships from non-cointegrating relationships (known as spurious
relations).

2.1 Spurious regressions


Consider the case, where you have a variable, yt

t
X
yt = yt−1 + εt where εt ∼ (0, σ12 ) ⇒ yt = y0 + εj
j=1

and a variable, xt
t
X
xt = xt−1 + ςt where ς2t ∼ (0, σ22 ) ⇒ xt = x0 + ςj
j=1

In this case both yt and xt are random walk processes without drift (and so are I(1) series). If we
also assume E(εt ςt ) = 0, then there is nothing linking the two series together. Despite this as yt
Pt t
P
and xt are trending over time (this is because of the stochastic trend εj in yt and ςj in xt ).
j=1 j=1
Therefore if we run a regression between the two variables:

yt = α + βxt + εt (1)

then while we would expect to only reject H0 : β = 0 around 5% of the time (for a 5% significance
level), when we are dealing with non-stationary series we can reject the null hypothesis up to 77% of
the time. If yt and xt were nonstationary processes with a non-zero drift parameter these rejection
rates would be even greater.
Consequently, we need to distinguish between

1. Spurious (nonsense) regressions, in which we observe an apparently significant relationship


between unrelated series.

2. Genuine cointegrating relationships between series.

2.2 Cointegrating regressions


For ease of notation, we will consider testing for cointegration when we have two (n = 2) I(1) vari-
ables, in which case there is at most r = 1 cointegrating relationship. The analysis can be extended
to looking for cointegration between n ≥ 2 variables, in which case there could in principle be up
to r = n − 1 cointegrating relationships - see Johansen (1988) for looking for multiple cointegration
relationships. In this module we will limit our analysis to identifying just one cointegrating rela-
tionship using the approach of Engle and Granger (1987), who recommend a two-step procedure for
cointegration analysis (between up to k variables):
STEP ONE
Estimate a long-run (equilibrium) equation either by:

3
EC226 (Term 2: Handout 4) 2 SPURIOUS VS COINTEGRATING RELATIONSHIPS

1. Estimating a static (long-run) equation such as:

yt = δ0 + δ1 xt + εt (2)

by OLS, or

2. Estimating a dynamic equation, such as:

yt = γ0 + γ1 xt + γ2 xt−1 + γ3 xt−2 + γ4 yt−1 + γ5 yt−2 + ut

by OLS, and solving for that equation for the long-run equation, that is:

γ0 (γ1 + γ2 + γ3 ) ut
yt = + xt + (3)
(1 − γ4 − γ5 ) (1 − γ4 − γ5 ) (1 − γ4 − γ5 )
| {z }
et

Either equation (2) or equation (3) is the long-run equation and the residuals from equation (2),
denoted as:
et = yt − δ̂0 − δ̂1 xt (4)

Where δ̂j j = 0, 1 is the OLS estimator of δj j = 0, 1, or the residuals from equation (3), denoted as:
 
γ̂0 (γ̂1 + γ̂2 + γ̂3 )
et = yt − + xt (5)
(1 − γ̂4 − γ̂5 ) (1 − γ̂4 − γ̂5 )

are measures of ”disequilibrium” between yt and xt and cointegration requires that the residuals
(which can be referred to as a ”disequilibrium” term) are stationary. Therefore a test for cointegration
revolves around whether the residuals (”disequilibrium” term), et in equation (4) or equation (5), is
stationary.
The stationarity of the residuals et , is determined using an ADF test as
p
X
∆et = µ + γet−1 + δj ∆et−j + ηt
j=1

and we re testing H0 : γ = 0 (the residuals are non-stationary and therefore the regression is spurious)
versus H1 : γ < 0 the residuals are stationary and therefore the regression was a cointegrating
regression.
The critical values are taken from MacKinnon (1991) have to be corrected for the number of non-
stationary variable you estimated in the long-run equation, n. The reason for this is that OLS by
definition finds the parameters which minimise the RSS (and hence the finds the residuals which are
most stationary, which therefore biases the results to finding a cointegrating equation, consequently
we adjust the critical values for n the number of non-stationary variables in the long-run equation.
STEP TWO:
If there is a cointegrating equation then you should estimate an Error Correction Model (ECM) of
the form:
X X
∆yt = ϕ0 + ϕj ∆yt−j + θh ∆xt−h + αet−1 + ηt (6)
j=1 h=1

by OLS, where we assume ηt is a well-behaved error term, as this equation has only I(0) variables
(remember the long-run residuals et−1 are stationary and all other variables are in first differences)

4
EC226 (Term 2: Handout 4) 2 SPURIOUS VS COINTEGRATING RELATIONSHIPS

standard hypothesis testing using t-ratios and diagnostic testing of the error term is appropriate,
note α < 0 as this is an error correcting model, such that if:
et−1 > 0 ⇒ yt−1 > δ̂0 + δ̂1 xt−1 and yt−1
is above its equilibrium value. In which case αet−1 < 0 ⇒ ∆yt < 0, that is, the dependent variable
falls.
Similarly, if
et−1 < 0 ⇒ yt−1 < δ̂0 + δ̂1 xt−1
and yt−1 is below its equilibrium value. In which case αet−1 > 0 ⇒ ∆yt > 0, that is, the dependent
variable rises – in general the dependent variable is adjusting (correcting) for disequilibrium (errors)
in the previous period. This equation has only I(0) variables and therefore the equation should be
consistent with CLRM assumptions, and this can be tested as the distribution of all statistics is
well-behaved.

2.3 Non-cointegrating regressions


If you do not have cointegration in STEP 1 then you do not have an equilibrium equation and
therefore there you cannot build an error correction model as there are no long-run (equilibrium)
errors for which the model need to correct. The short-run equation should still be balanced and so
we still need to difference all of the non-stationary variables to make them stationary:
X X
∆yt = ϕ0 + ϕj ∆yt−j + θh ∆xt−h + ηt
j=1 h=1

This equation looks a bit like the ECM in equation (6), apart from (and very importantly) we do
not have the error correction term, et−1 , but we have still transformed all of the variables to be I(0).
If you have a combination of I(1) and I(0) variables in your regression and you do not have cointe-
gration between the I(1) variables, then any short-run regression you estimate between the variables
must involve only the I(0) variables (thereby ensuring the equation is balanced), and so we may have:
X X X
∆yt = ϕ0 + ϕj ∆yt−j + θh ∆x1t−h + κh x2t−h + ηt
j=1 h=1 h=1

if
yt ∼ I(1), x1t ∼ I(1), x2t ∼ I(0)

Alternatively,
X X X
yt = ϕ0 + ϕj yt−j + θh ∆x1t−h + κh ∆x2t−h + ηt
j=1 h=1 h=1

yt ∼ I(0), x1t ∼ I(1), x2t ∼ I(1)

2.4 Super Consistency


From term 1 we spent some considerable time worry about whether our biases in our OLS coefficients
and found that in a number of instances the OLS coefficient are biased (and even inconsistent) due
to

1. Omitted relevant variables

2. incorrect function form

5
EC226 (Term 2: Handout 4) 2 SPURIOUS VS COINTEGRATING RELATIONSHIPS

3. measurement errors in the explanatory variables

4. endogeneity

However, we do not have to worry about these issues as much with cointegration analysis and estimat-
ing our long-run equations by OLS. The reason for this is donw to the fact that the OLS estimators
of the long-run coefficients are said to be ;;super-consistent”.
The idea of super-consistent is that the OLS estimator approaches the true coefficient very quickly
as the number of observations T increases. Considerthe OLS estimator for equation (4) is:
P P P
(xt − x̄)(yt − ȳ) (xt − x̄)εt (xt − x̄)εt /T
δ̂1 = t P 2 = δ 1 + t
P 2 ⇒ δ̂ 1 − δ 1 = t
P 2 (7)
(xt − x̄) (xt − x̄) (xt − x̄) /T
t t t

P
now (xt − x̄)εt /T , is the covariance between a stationary I(0) series εt and the nonstationary I(1)
t
P 2
series, xt , and this term will not increase over time. In contrast (xt − x̄) /T is the variance of the
t
I(1) series, xt , and this increases with T . Consequently, as T → ∞ the denominator becomes very
large relative to the numerator, therefore the term
P
(xt − x̄)εt /T
t
P 2 →0
(xt − x̄) /T
t

quickly, meaning the bias disappears very quickly and this will always be the case providing the terms
entering into ε are I(0) terms.
For example, consider the case where there is an omitted relevant variables (which is expressed as
an incorrectly specified dynamic equation) and there is a true (T) equation and an estimated (F)
equation:
yt =β0 + β1 xt−1 + εt (T)
yt =δ0 + δ1 xt − δ1 (xt − xt−1 ) + εt (F)

Here the omitted variable is zt = −δ(xt − xt−1 ), which is an I(0) process. Therefore,

cov(xt , zt )
E(δ̂1 ) =β1 − δ1
var(xt )
cov(xt , ∆xt )
= β1 − δ 1 (8)
var(xt )
cov(xt , ∆xt )/T
= β1 − δ 1
var(xt )/T

The numerator of the bias term in equation (8) will not increase with T as it is the covariance between
an I(1) and an I(0) series, while the denominator will increase with T , therefore asymptotically the
bias term goes to zero. The same proof works for measurement error, incorrect function form, and
endogeneity bias, which are all likely to be I(0) biases.
NOTE:
The t-ratios from estimating equation (2) cannot be interpreted, as this long-run equation will have
serial correlation (due to incorrectly specified dynamics) as well as omitted variable problems. The
traditional diagnostic tests from (2) are largely unimportant as the only important question is the
stationarity or otherwise of the residuals.

6
EC226 (Term 2: Handout 4) A EXAMPLE OF COINTEGRATION ANALYSIS

A Example of Cointegration Analysis


Consider the 4 series y1t , y2t , y3t , y4t for which we plot the series and the ACF

Figure A1.1 Plot of the 4 series

7
EC226 (Term 2: Handout 4) A EXAMPLE OF COINTEGRATION ANALYSIS

Figure A1.2: ACF of the 4 series

8
EC226 (Term 2: Handout 4) A EXAMPLE OF COINTEGRATION ANALYSIS

For all series these is some evidence of potential non-stationarity and as a result we undertake
unit root tests on each of the series using model C and 2 lags as the model, i.e. ∆yt = α + µt +
2
P
γyt−1 + δj ∆yt−j + εt With H0 : γ = 0; H1 : γ < 0
j=1

Which suggest we are able to reject H0 and y1t ∼ I(0)

Which suggest we are unable to reject H0 and y2t ∼ I(1)

Which suggest we are unable to reject H0 and y3t ∼ I(1)

9
EC226 (Term 2: Handout 4) A EXAMPLE OF COINTEGRATION ANALYSIS

Which suggest we are unable to reject H0 and y4t ∼ I(1).


Now we look for cointegration between pairs of variable to see whether they are cointegrated.
Here we look at y2t ∼ I(1) and y1t ∼ I(0), so they are integrated of different orders and therefore
cointegration make no sense.

There is a very significant and positive relationship between the two, but if we undertake a unit root
test on the residuals (denoted, res y2):

The critical value comes from MacKinnon’s tables with n = 2 (see Appendix 2) and at the 5%
significance level this is approximately -3.34 and we are unable to reject H0 . This is not surprising as
the stochastic trend in y2t cannot be cancelled by anything in the stationary series, y1t , which does
not have a stochastic trend – by definition.
Now we look for cointegration between y1t and y2t .

10
EC226 (Term 2: Handout 4) A EXAMPLE OF COINTEGRATION ANALYSIS

There is a very significant and positive relationship between the two, but if we undertake a unit root
test on the residuals (denoted, res y1):

The critical value comes from MacKinnon’s tables with n = 2 and at the 5% significance level this
is approximately -3.34. Therefore we are able to reject H0 . However, this test makes no sense as
the dependent variable y1t is stationary and therefore any residuals from this equation MUST be
stationary – but this has nothing to do with cointegration. Now we look for cointegration between
y3t and y2t .

There is no real relationship between the two series and if we undertake a unit root test on the
residuals (denoted, res y3):

11
EC226 (Term 2: Handout 4) A EXAMPLE OF COINTEGRATION ANALYSIS

The critical value comes from MacKinnon’s tables with n = 2 and at the 5% significance level this
is approximately -3.34 we are unable to reject H0 there is no cointegrating equation and so there
is no cointegration, but there is no evidence of a spurious regression either as the coefficient in the
long-run equation is insignificant.
Now we look for cointegration between y4t and y2t .

There is a very significant and positive relationship between the two, but if we undertake a unit root
test on the residuals (denoted, res y4)

The critical value comes from MacKinnon’s tables with n = 2 and at the 5% significance level this
is approximately -3.34. Therefore we are able to reject H0 and this implies we have a cointegrating
equation between the two series.
Given a cointegrating equation, we now look at building an ECM and the form of the ECM should
be:

12
EC226 (Term 2: Handout 4) A EXAMPLE OF COINTEGRATION ANALYSIS

∆y4t = β0 + β1 ∆y4t−1 + β2 ∆y4t−2 + β3 ∆y2t−1 + β4 ∆y2t−2 + β5 ût−1 + εt


Where ût = res y4t = y4t − 8.211 − 0.3251y2t

The model might be over-parameterised as the coefficients of the lag 2 variables are insignificantly
different from zero. However, the term on the lagged residuals (res y4) is -0.31 suggesting that around
one-third of the disequilibrium is corrected for within one quarter. Diagnostic testing of the residuals
gives:

13
EC226 (Term 2: Handout 4) B CRITICAL VALUES FOR THE ADF TEST

B Critical values for the ADF test


Extract of MacKinnon’s Critical Values
n Model Point(%) ϕ∞ SE ϕ1 ϕ2
1 No Constant 1 -2.5658 (0.0023) -1.960 -10.04
no Trend 5 -1.9393 (0.0008) -0.398 -0.00
10 -1.6156 (0.0007) -0.181 -0.00
1 Constant, 1 -3.4336 (0.0024) -5.999 -29.25
no trend 5 -2.8621 (0.0011) -2.738 -8.36
10 -2.5671 (0.0009) -1.438 -4.48
1 Constant 1 -3.9638 (0.0019) -8.353 -47.44
+ trend 5 -3.4126 (0.0012) -4.039 -17.83
10 -3.1279 (0.0009) -2.418 -7.58
2 Constant, 1 -3.9001 (0.0022) -10.534 -30.03
no trend 5 -3.3377 (0.0012) -5.967 -8.98
10 -3.0462 (0.0009) -4.069 -5.73
2 Constant 1 -4.3266 (0.0022) -15.531 -34.03
+ trend 5 -3.7809 (0.0013) -9.421 -15.06
10 -3.4959 (0.0009) -7.203 -4.01
3 Constant, 1 -4.2981 (0.0023) -13.790 -46.37
no trend 5 -3.7429 (0.0012) -8.352 -13.41
10 -3.4518 (0.0010) -6.241 -2.79
3 Constant 1 -4.6676 (0.0022) -18.492 -49.35
+ trend 5 -4.1193 (0.0011) -12.024 -13.13
10 -3.8344 (0.0009) -9.188 -4.85
4 Constant, 1 -4.6493 (0.0023) -17.188 -59.20
no trend 5 -4.1000 (0.0012) -10.745 -21.57
10 -3.8110 (0.0009) -8.317 -5.19
4 Constant 1 -4.9695 (0.0021) -22.504 -50.22
+ trend 5 -4.4294 (0.0012) -14.501 -19.54
10 -4.1474 (0.0010) -11.165 -9.88

C(p) = ϕ∞ + ϕ1 T −1 + ϕ2 T −2

Source: MacKinnon (1991). Reproduced by permission of Oxford University Press.

14
EC226 (Term 2: Handout 4) C STATA COMMANDS FOR COINTEGRATION

C Stata Commands for cointegration


/* Importing an excel dataset */
import excel "Z:\Downloads\danish_money_demand.xlsx", */
*/ sheet("Sheet1") firstrow
/* var1 has entry like var1=73:1 so split this as 73 and 1 and then construct a
date series */
gen yr1=substr(var1,1,2)
gen year=yr1+1900
gen q=substr(var1,4,1)
encode q, g(quarter)
gen time=yq(year, quarter)
format time %tq
drop var1 yr yr1 year q quarter
tsset time
/* Plot log of real money (lrm), as level and 1st difference also ACF and PACF of level
and 1st difference */
twoway (tsline lrm) (tsline d.lrm, yaxis(2))
ac lrm
pac lrm
ac d.lrm
pac d.lrm
/* Plot log of real real output (lry), as level and 1st difference also ACF and PACF of
level and 1st difference */
twoway (tsline lry) (tsline d.lry, yaxis(2))
ac lry
pac lry
ac d.lry
pac d.lry
/* Plot bond rate (ib), as level and 1st difference also ACF and PACF of level and
1st difference */
twoway (tsline ib) (tsline d.ib, yaxis(2))
ac ib
pac ib
ac d.ib
pac d.ib
/* Plot deposit rate (id), as level and 1st difference also ACF and PACF of level and
1st difference */
twoway (tsline id) (tsline d.id, yaxis(2))
ac id
pac id
ac d.id
pac d.id
/* Plot lrm vs lry ib and id */
twoway (tsline lrm) (tsline lry, yaxis(2))

15
EC226 (Term 2: Handout 4) C STATA COMMANDS FOR COINTEGRATION

twoway (tsline lrm) (tsline ib, yaxis(2))


twoway (tsline lrm) (tsline id, yaxis(2))
/* ADF test for the series using Model C for lrm and lry and model B and C for ib and id */
dfuller lrm, trend lags(2) regress
dfuller lry, trend lags(1) regress
dfuller ib, lags(1) regress
dfuller ib, trend lags(1) regress
dfuller id, lags(1) regress
dfuller id, trend lags(1) regress
/* Long-run equation for lry and saving residuals */
reg lrm lry ib id
predict res, resid
/* plotting ACF and PACF of residuals */
ac d.res
pac d.res
/* Unit root test for residuals */
dfuller res, lags(1)
/* Dropping id from equation */
reg lrm lry ib
predict res1, resid
ac d.res1
pac d.res1
dfuller res1, lags(1)
/* Dynamic model for and solving for long-run residuals */
reg lrm lry ib id l.lrm l.lry
gen lrres=lrm-(_b[_cons]+(_b[lry]+_b[l.lry])*lry+_b[ib]*ib+_b[id]*id)/(1-_b[l.lrm])
ac d.lrres
pac d.lrres
dfuller lrres
/* ECM using long-run residuals */
reg d.lrm d.l.lrm d.lry d.l.lry d.ib d.l.ib d.id d.l.id l.lrres
/* Testing zero coefficients on a series of variables */
test d.l.lry d.l.ib d.id d.l.id
/* A restricted ECM model */
reg d.lrm d.l.lrm d.lry d.ib l.lrres
/* diagnostic tests for ECM */
estat bgodfrey, lag(1)
estat hettest

16
EC226 (Term 2: Handout 4) D R COMMANDS FOR COINTEGRATION

D R Commands for cointegration


# Importing an excel dataset
danish <- read_excel("C:/Downloads/danish_money_demand.xlsx")
# Dropping the date variable from the dataset
danish <- danish %>%
select(-c(date))
# Create a new date variable
date3 <- seq(as.Date("1974-1-1"), as.Date("1987-7-1"), by = "quarters")
danish_tsq <- xts(danish, order.by=date3)
# Plot log of real money (lrm), as level and 1st difference also ACF and PACF of level
and 1st difference
# Create the differenced series for each of our series
danish_tsq$dlrm <- 100*diff(danish_tsq$lrm)
danish_tsq$dlry <- 100*diff(danish_tsq$lry)
danish_tsq$dib <- diff(danish_tsq$ib)
danish_tsq$did <- diff(danish_tsq$id)
# As the plot has to be done with ggplot as other options do not permit two graphs
# with different scales. You need to convert the xts dataset back to a data frame
danish1 <- fortify(danish_tsq)
# Plot both lrm and dlrm - you must scale dlrm to have similar units to lrm and
# then invert the formula for the 2nd axis (need to divide by 20 and add 11.6)
ggplot(danish1, aes(x = Index, y = lrm)) +
geom_line(aes(color = "lrm")) +
geom_line(aes(y = dlry/20+11.6, color = "d.lrm")) +
scale_y_continuous(sec.axis = sec_axis(~.*20-11.6*20, name="d.lrm")) +
labs(x = "Date", y = "lrm", color = "") +
scale_color_manual(values = c("red", "blue")) +
theme(legend.position="bottom") +
ggtitle("Plot of lrm and d.lrm")
# Plot the ACF and PACF of lrm
acf_lrm <- acf(danish_tsq$lrm)
pacf_lrm <- pacf(danish_tsq$lrm)
# Plot the ACF and PACF of d.lrm, adjust the sample to remove missing observation
acf_dlrm <- acf(subset(diff(danish_tsq$lrm), date3>=as.Date(’1974-04-01’)))
pacf_dlrm <- pacf(subset(diff(danish_tsq$lrm), date3>=as.Date(’1974-04-01’)))
# Plot log of real real output (lry), as level and 1st difference
ggplot(danish1, aes(x = Index, y = lry)) +
geom_line(aes(color = "lry")) +
geom_line(aes(y = dlry/50+6, color = "d.lry")) +
scale_y_continuous(sec.axis = sec_axis(~.*50-6*50, name="d.lry")) +
labs(x = "Date", y = "lry", color = "") +
scale_color_manual(values = c("red", "blue")) +
theme(legend.position="bottom") +
ggtitle("Plot of lry and d.lry")

17
EC226 (Term 2: Handout 4) D R COMMANDS FOR COINTEGRATION

# Plot the ACF and PACF of lry


acf_lry <- acf(danish_tsq$lry)
pacf_lry <- pacf(danish_tsq$lry)
# Plot the ACF and PACF of d.lry, adjust the sample to remove missing observation
acf_dlry <- acf(subset(diff(danish_tsq$lry), date3>=as.Date(’1974-04-01’)))
pacf_dlry <- pacf(subset(diff(danish_tsq$lry), date3>=as.Date(’1974-04-01’)))
# Plot bond rate (ib), as level and 1st difference
ggplot(danish1, aes(x = Index, y = ib)) +
geom_line(aes(color = "ib")) +
geom_line(aes(y = dib+0.15, color = "d.ib")) +
scale_y_continuous(sec.axis = sec_axis(~.-0.15, name="d.ib")) +
labs(x = "Date", y = "ib", color = "") +
scale_color_manual(values = c("red", "blue")) +
theme(legend.position="bottom") +
ggtitle("Plot of ib and d.ib")
# Plot the ACF and PACF of ib
acf_ib <- acf(danish_tsq$ib)
pacf_ib <- pacf(danish_tsq$ib)
# Plot the ACF and PACF of d.ib, adjust the sample to remove missing observation
acf_dib <- acf(subset(diff(danish_tsq$ib), date3>=as.Date(’1974-04-01’)))
pacf_dib <- pacf(subset(diff(danish_tsq$ib), date3>=as.Date(’1974-04-01’)))
# Plot deposit rate (id), as level and 1st difference
ggplot(danish1, aes(x = Index, y = id)) +
geom_line(aes(color = "id")) +
geom_line(aes(y = did+0.1, color = "d.id")) +
scale_y_continuous(sec.axis = sec_axis(~.-0.1, name="d.id")) +
labs(x = "Date", y = "id", color = "") +
scale_color_manual(values = c("red", "blue")) +
theme(legend.position="bottom")
# Plot the ACF and PACF of id
acf_id <- acf(danish_tsq$id)
pacf_id <- pacf(danish_tsq$id)
# Plot the ACF and PACF of d.id, adjust the sample to remove missing observation
acf_did <- acf(subset(diff(danish_tsq$id), date3>=as.Date(’1974-04-01’)))
pacf_did <- pacf(subset(diff(danish_tsq$id), date3>=as.Date(’1974-04-01’)))
# Plot lrm vs lry
ggplot(danish1, aes(x = Index, y = lrm)) +
geom_line(aes(color = "lrm")) +
geom_line(aes(y = lry*2, color = "lry")) +
scale_y_continuous(sec.axis = sec_axis(~./2, name="lry")) +
labs(x = "Date", y = "lrm", color = "") +
scale_color_manual(values = c("red", "blue")) +
theme(legend.position="bottom") +
ggtitle("Plot of lrm and lry")
# Plot lrm vs ib

18
EC226 (Term 2: Handout 4) D R COMMANDS FOR COINTEGRATION

ggplot(danish1, aes(x = Index, y = lrm)) +


geom_line(aes(color = "lrm")) +
geom_line(aes(y = ib*5+11, color = "ib")) +
scale_y_continuous(sec.axis = sec_axis(~./5-11/5, name="ib")) +
labs(x = "Date", y = "lrm", color = "") +
scale_color_manual(values = c("red", "blue")) +
theme(legend.position="bottom") +
ggtitle("Plot of lrm and ib")
# Plot lrm vs id
ggplot(danish1, aes(x = Index, y = lrm)) +
geom_line(aes(color = "lrm")) +
geom_line(aes(y = id*10+11, color = "id")) +
scale_y_continuous(sec.axis = sec_axis(~./10-11/10, name="id")) +
labs(x = "Date", y = "lrm", color = "") +
scale_color_manual(values = c("red", "blue")) +
theme(legend.position="bottom") +
ggtitle("Plot of lrm and id")
# ADF test for the series using Model C for lrm and lry and model B and C for ib and id
# In all cases using BIC to set lag length
summary(ur.df(danish_tsq$lrm, type="trend", selectlags = "BIC"))
summary(ur.df(danish_tsq$lry, type="trend", selectlags = "BIC"))
summary(ur.df(danish_tsq$ib, type="trend", selectlags = "BIC"))
summary(ur.df(danish_tsq$ib, type="drift", selectlags = "BIC"))
summary(ur.df(danish_tsq$id, type="trend", selectlags = "BIC"))
summary(ur.df(danish_tsq$id, type="drift", selectlags = "BIC"))
/* Long-run equation for lry and saving residuals */
eg_f1 <- dyn$lm(lrm ~ lry + ib + id, data=danish_tsq)
danish_tsq$eg_res1<-resid(eg_f1)
# plotting ACF and PACF of residuals
acf(danish_tsq$eg_res1)
pacf(danish_tsq$eg_res1)
# Unit root test for residuals
ur.df(danish_tsq$eg_res1, type="drift", selectlags = "BIC")
# Dropping id from equation
eg_f2 <- dyn$lm(lrm ~ lry + ib, data=danish_tsq)
danish_tsq$eg_res2<-resid(eg_f2)
# plotting ACF and PACF of residuals
acf(danish_tsq$eg_res2)
pacf(danish_tsq$eg_res2)
# Unit root test for residuals
ur.df(danish_tsq$eg_res2, type="drift", selectlags = "BIC")
# Dynamic model for and solving for long-run residuals
eg_f3 <- dyn$lm(lrm ~ lry + ib + id + lag(lry, 1) + lag(lrm, 1), data=danish_tsq)
# Saving th vector of coefficients
b_eg_f3 <- coef(eg_f3)

19
EC226 (Term 2: Handout 4) D R COMMANDS FOR COINTEGRATION

# Genrating the long-run residuals


danish_tsq$eg_res3 <- danish_tsq$lrm-(b_eg_f3[1]+(b_eg_f3[2]+b_eg_f3[5])*danish_tsq$lry +
b_eg_f3[3]*danish_tsq$ib + b_eg_f3[4]*danish_tsq$id)/(1-b_eg_f3[6])
# Plotting the residuals and the ACF and the PACF
autoplot(danish_tsq$eg_res3)
acf(danish_tsq$eg_res3)
pacf(danish_tsq$eg_res3)
# Unit root test on the residuals
ur.df(danish_tsq$eg_res3, type="drift", selectlags = "BIC")
# Estimating an ECM using eg_res3
eg_f4 <- dyn$lm(dlrm ~ dlry + lag(dlry, 1) + dib + lag(did, 1) + did +
lag(did, 1) + lag(dlrm, 1) + lag(eg_res3, 1),
data = danish_tsq)
# As the model looks overparameteriserd we remove some variables
eg_f5 <- dyn$lm(dlrm ~ dlry + dib + lag(dlrm, 1) + lag(eg_res3, 1),
data = danish_tsq)
# Breush-Godfrey test
bgtest(eg_f5, order=1, data=danish_tsq)
# Breush-Pagan test
bptest(eg_f5)

20
EC226 (Term 2: Handout 4) REFERENCES

References
Dougherty, C. (2016). Introduction to Econometrics. OUP Catalogue. Oxford University Press.

Engle, R. F. and Granger, C. W. J. (1987). Co-integration and error correction: Representation,


estimation, and testing. Econometrica, 55(2):251–276.

Johansen, S. (1988). Statistical analysis of cointegration vectors. Journal of Economic Dynamics


and Control, 12(2):231–254.

MacKinnon, J. (1991). ”critical values for cointegration test. In Engle, R. F. and Granger, C. W. J.,
editors, Long-Run Economic Relationships, chapter 13. Oxford University Press, Oxford.

Stock, J. and Watson, M. W. (2003). Introduction to Econometrics. Prentice Hall, New York.

Wooldridge, J. M. (2013). Introduction to Econometrics. Cengage.

21

You might also like