' VAR lag order selection
' replicates Lutkepohl (1991) 
' Table 4.4 (p.127) and Table 4.5 (p.130)
' version 4 beta
' 1/10/2000 h
' last checked 10/27/2000 h

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

' load workfile
load lut1

' estimate VAR
smpl 1960:1 1978:4
var1.ls 1 2 y1 y2 y3 @ c

' lag length criteria
freeze(tab45) var1.laglen(4,vname=vlag,mname=mlag)
show tab45

!pi = @acos(-1)
!c = var1.@neqn*(1+log(2*!pi))

' unmodified LR test (exactly replicate Table 4.4, p.127)
' 1st column: (unmodified) LR statistic
' 2nd column: p-value

!m = @rows(mlag)-2
matrix(!m,2) tab44
!df = var1.@neqn * var1.@neqn	' degrees of freedom of test
for !r=!m to 1 step -1
	tab44(!r,1) = 2*(mlag(!r+1,1) - mlag(!r,1))
	tab44(!r,2) = 1 - @cchisq(tab44(!r,1),!df)
next
show tab44

