'Johansen cointegration restrictions
'replicate example 7.3.1 (pp.112-116)
'Johansen (1995) Likelihood-based Inference in Cointegrated
'Vector Auto-regressive Models, Oxford University Press
'
'version 4
' last checked 10/27/2000 h

'change path to program path
%path = @runpath
cd "{%path}"

'create workfile
workfile denmark q 1974:1 1987:3

'fetch data from database
'data downloaded from johansen's website at
'http://www.math.ku.dk/~sjo/data/data.html
fetch(d=var_dat) lrm lry ibo ide

'create centered seasonal dummies
for !i=1 to 3
	series d{!i} = @seas(!i) - 0.25
next

'estimate VEC with intercept restricted in cointegrating relation
var vec1.ec(b,1) 1 1 lrm lry ibo ide @ d1 d2 d3

'show cointegration test results
'replicates Tables 7.1 (p.113), 7.2 (p.113), 7.3 (p.114)
'note that EViews uses slightly different critical values
'note also that EViews reports *transpose* of Table 7.2
freeze(tab71) vec1.coint(b,1)
show tab71

'show unrestricted cointegrating relation
'replicate Fig 7.1 (left graph)
vec1.makecoint gcoint
freeze(fig71) gcoint.line
fig71.draw(dashline,left) 0.0
show fig71

'-------------------------------------------------------------------------------
'test b1+b2=0
'-------------------------------------------------------------------------------
vec1.cleartext(coint)
vec1.append(coint) b(1,1) + b(1,2) = 0

freeze(test1) vec1.coint(b,1,restrict,c=1e-5,m=100)
show test1

'-------------------------------------------------------------------------------
'test b1+b2=0 and b3+b4=0
'note that this test is different from the test reported in Johansen (p.115)
'which is a test of b3+b4=0 conditional on b1+b2=0
'-------------------------------------------------------------------------------

vec1.append(coint) b(1,3) + b(1,4) = 0
vec1.append(coint) b(1,1) = 1.0

'save restricted logl in mat2 for later use
freeze(test2) vec1.coint(b,1,restrict,c=1e-5,m=100,save=mat2)
show test2

'get restricted cointegrating vector
vec1.ec(b,1,restrict,c=1e-5,m=100) 1 1 lrm lry ibo ide @ d1 d2 d3
matrix cv1 = vec1.@cointvec
show cv1

'-------------------------------------------------------------------------------
'test weak exogeneity a3=a4=0 conditional on b1+b2=0 and b3+b4=0
'-------------------------------------------------------------------------------

vec1.append(coint) a(3,1) = 0
vec1.append(coint) a(4,1) = 0

'joint test on b and a
'save restricted logl of joint test in mat3
freeze(test3) vec1.coint(b,1,restrict,c=1e-5,m=100,save=mat3)
show test3

'compute manually LR statistic for testing a3=a4=0
'conditional on b1+b2=b3+b4=0
'replicates first paragraph of p.116
table out
out(1,1) = "Weak exogeneity test (a3=a4=0) conditional on b1+b2=b3+b4=0"
out(2,1) = "LR statistic = "
!lr = 2.0*(mat2(1,4) - mat3(1,4))
out(2,2) = !lr
out(2,3) = "p-value = "
out(2,4) = 1.0 - @cchisq(!lr,2)

show out

