Page 1 of 1

### Portmanteau for VAR(p)

Posted: Fri Aug 25, 2017 5:02 pm
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}.makeresidsgroup residsfor !i=1 to {%var}.@neqn   if !i<10 then      resids.add resid0!i   else      resids.add resid!i   endifnextstom(resids,U)U=@transpose(U)'Var-cov-aut error matrixfor !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}.@regobsnext'Q and adjusted Q vector(!h) Q=0vector(!h) Qa=0for !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)   nextnextvector Qsa={%var}.@regobs*Q 'Tvector Qa=({%var}.@regobs)^2*Qa 'T^2/T-ivector(!h) pvaloresQsa=0vector(!h) pvaloresQa=0for !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))   endifnextfreeze(resultado) var01.qstats(!h)`