## Portmanteau for VAR(p)

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

NicolasR
Posts: 86
Joined: Mon Nov 04, 2013 6:22 pm
Location: Here

### Portmanteau for VAR(p)

Just as an academic exercise the following code performs the estimation of the multivariate Ljung Box test for VAR already available in eviews.

Best regards,

Code: Select all

'Nicolás Ronderos Pulido - Time series analysis
'Test: Portmanteau for VAR(p)
'Lutkepohl (2005)
'H0: no autocorrelation until lag h
'-------------------------------------------------------
!h=12 'Max h
%var="var01" 'Estimated VAR(P)
'-------------------------------------------------------
{%var}.makeresids
group resids
for !i=1 to {%var}.@neqn
if !i<10 then
else
endif
next
stom(resids,U)
U=@transpose(U)
'Var-cov-aut error matrix
for !i=0 to !h
matrix(@rows(U),@rows(U)) C!i=0
for !t=1 to @columns(U)
if !i+!t<=@columns(U) then
matrix(@rows(U),@rows(U)) C!i=C!i+@columnextract(U,!i+!t)*@transpose(@columnextract(U,!t))
statusline !t
endif
next
C!i=C!i/{%var}.@regobs
next
vector(!h) Q=0
vector(!h) Qa=0
for !j=1 to !h
for !i=1 to !j
Q(!j)=Q(!j)+@trace(@transpose(C!i)*@inverse(C0)*C!i*@inverse(C0))
Qa(!j)=Qa(!j)+@trace(@transpose(C!i)*@inverse(C0)*C!i*@inverse(C0))/({%var}.@regobs-!i)
next
next
vector Qsa={%var}.@regobs*Q 'T
vector Qa=({%var}.@regobs)^2*Qa 'T^2/T-i
vector(!h) pvaloresQsa=0
vector(!h) pvaloresQa=0
for !i=1 to !h
if !h>2 then
pvaloresQsa(!i)=@chisq(Qsa(!i),(@rows(U)^2)*(!h-2))
pvaloresQa(!i)=@chisq(Qa(!i),(@rows(U)^2)*(!h-2))
endif
next