*
* @McLeodLi( options)  x start end
* Performs a McLeod-Li test for 2nd order dependence
*
* Parameters:
*   x           series to analyze
*   start end   range to analyze [defaults to full range of x]
*
* Options:
*   NUMBER=number of autocorrelations on the squares [10]
*   DFC=degrees of freedom correction [0]. For residuals from a GARCH model, this
*    should be the number of estimated "GARCH" parameters (those on lagged variance
*    and lagged squared residuals).
*   [PRINT]/NOPRINT
*
* Variables Defined:
*   %CDSTAT  Test statistic
*   %SIGNIF  Significance level of %CDSTAT as a chi-squared with degrees of freedom
*            NUMBER-DFC.
*   %NOBS    Number of observations
*
* Reference:
*   McLeod and Li(1993), "Diagnostic Checking of ARMA Time Series Models Using
*    Squared Residual Autocorrelations", J. of Time Series Analysis, vol 4, pp
*    269-273.
*
* Revision Schedule:
*   05/2008 Written by Tom Doan, Estima
*
procedure McLeodLi x start end
type series x
type integer start end
*
option integer number 10
option integer dfc    0
option switch  print  1
*
local integer startl endl
local series xsq
*
if .not.%defined(x) {
   display "Syntax: @McLeodLi(options) >>x<< start end"
   return
}
inquire(series=x) startl<<start endl<<end
set xsq startl endl = x**2
corr(number=number,method=yule,noprint,qstats,dfc=dfc) xsq startl endl
compute %cdstat=%qstat,%signif=%qsignif
*
if .not.print
   return

report(action=define)
report(row=new,atcol=1,span) "McLeod-Li Test for Series "+%l(x)
report(row=new,atcol=1,span) "Using "+%nobs+" Observations from "+%datelabel(startl)+" to "+%datelabel(endl)
report(row=new,atcol=1) "McLeod-Li("+number+"-"+dfc+")" %cdstat %signif
report(action=format,atcol=2,width=10)
report(action=format,atcol=3,picture='#.#####')
report(action=show)
end


