' Tutorial 4:
' NF Katzke (nfkatzke@gmail.com)
'==========================
' Test for cointegration using Engel-Granger approach:
equation engel_g_eq.ls bond03 c bond10
' Now we can use the residuals to test for cointegration using Engel Granger's method (see class notes). First save it:
engel_g_eq.makeresids eg_resids
freeze(Resid_plot) eg_resids.line
eg_resids.uroot ' Note that the combination yields I(0) resids... So it can be argued that the series are cointegrated (as their levels are I(1)...)
' EG Cointegration equation then:
equation EG_coint.ls d(bond03) c d(bond10) eg_resids
' Speed of adjustment (MAL statistic):
scalar MAL = (1-c(2)) / c(3) ' see slide 34 of class notes on VECMs
' Interpret this value. Hint - argue that a value close to 1 imples that deviations are extremely slow (i.e. slow to arrive back at a LR level), whereas if the value is close to 0, the adjustment process is quick....
equation engel_g_eq2.ls bond03 c bond10 bond35 bond510
engel_g_eq2.makeresids eg_resids2
' Now check the root of the residuals using a structural break robust approach yourself...
' Plot and consider all four bond series:
group all_bonds bond03 bond10 bond35 bond510
freeze(all_bond_graph) all_bonds.line
all_bond_graph.draw(line, bottom, color = "red") 1986m05 ' All bonds only have data after this, so let's contract the page:
pagestruct(start=1986m05)
' let's rerun the figure now:
delete all_bond_graph
freeze(all_bond_graph) all_bonds.line
' To determine the cointegrating structure of the CE of these stocks, let's graph the residuals first:
freeze(asfasf) bond03.uroot(pp)
for %var bond03 bond10 bond35 bond510
%name = "UR_" + %var
freeze({%name}) {%var}.uroot(pp)
next
matrix (4,1) p_vals ' empty matrix to store p-values...
p_vals(1,1) = @val(UR_bond03(7,5))
p_vals(2,1) = @val(UR_bond10(7,5))
p_vals(3,1) = @val(UR_bond35(7,5))
p_vals(4,1) = @val(UR_bond510(7,5))
' Now you can make a table with the above values, or wrap this call in a function simply to make a table of unit root outputs - we won't get to this in this tutorial...
' Let's plot the bonds:
all_bonds.line
' Note: visually it seems as though there is a downward trend in the levels data (keep this in mind for the CE specs..).
' The residual series of the linear regression of these variables look as follows:
equation allbonds_eq.ls bond03 c bond10 bond35 bond510
allbonds_eq.makeresids eg_resids_full
eg_resids_full.line
' from the graph, it seems appropriate not to include an intercept or a trend component in the CE..
' Let's now conduct a Johansen test to check the rank of the pi matrix.. which will guide how many CE equations to use:
all_bonds.coint(s, 1 4)
' From the no intercept / trend in CE it seems as though there is only one linear combination of the series of interest that yields a I(0) residual series... hence rank(pi) = 1.
' Let's proceed to fit a single CE VECM.
' But first, let's find the optimal lag criteria - this is done by specifying a VAR model, and finding the optimal lags, and then subtracting 1.
var temp_var.ls 1 2 bond03 bond10 bond35 bond510
freeze(opt_lags_VECM) temp_var.laglen(8)
delete temp_var
' From opt_lags_VECM we can see that the optimal lag structure is 2, so for the VECM this will be 1:
var vecm_allbonds.ec(c,1) 1 1 bond03 bond10 bond35 bond510
' For a VECM with 2 CE's, we would specify it as:
' var VECM.ec(c,2) 1 2 bond03 bond10 bond35 bond510
' Now, to add the restrictions from the tut question, do the following (first try and do so by hand, not memorise below) - do so by clicking on Esimate and then restrictions. Then add the restrictions given in the tut. The following code then appears in the capture tab:
var vecm_allbonds_restricted.ec(c,1) 1 1 bond03 bond10 bond35 bond510
vecm_allbonds_restricted.append(coint) b(1,3)=0, b(1,4)=0
' Thus we append to existing
vecm_allbonds_restricted.ec(c,1, restrict) 1 1 bond03 bond10 bond35 bond510
' Do the rest of the tutorial as above, and send me your completed code sheet by Wednesday 23 May.