*
* @ARCHTest(options)  series  start end
*
* Computes (F-test form) tests for ARCH effects by regressing squares of an input
* series (which will usually be residuals) on constant and lags of the squares
* and testing the lags.
*
* Parameters:
*   series      series to test
*   start end   range of series to use. By default the defined range of series
*
* Options:
*   LAGS=(maximum) number of lags [4]
*   SPAN=spacing between number of lags in a test sequence. SPAN=1 will give a table
*        of tests for all lags from 1 to the LAG option. The default is to test only
*        the value of the LAGS option.
*   DFC=degrees of freedom correction for tests. By default, 0. If <<series>> are
*       residuals from an ARCH or GARCH, DFC should be the number of ARCH/GARCH
*       parameters.
*
* Revision Schedule:
*   04/2008 Written by Tom Doan, Estima
*
procedure archtest series start end
type series         series
type integrer       start end
*
option integer      lags    4
option integer      dfc     0
option integer      span    0
*
local series        ressqr
local integer       startl endl spanl lagnum num jj
*
* Get the working value for the span. If it's zero (or out-of-range), make it equal to <<lags>>
* so we'll just do the one test.
*
if span<=0.or.span>lags
   compute spanl = lags
else
   compute spanl = span
*
* Figure out the range of the series to use
*
inquire(series=series)  startl>>start  endl>>end
*
set ressqr startl endl = series**2
*
display
display "F-test of no ARCH vs. ARCH in" %label(series)
display "Using Data from" %datelabel(startl) "to" %datelabel(endl)
*
* If the user gave a LAGS which isn't a multiple of SPAN, do all multiples of
* SPAN less than LAGS, and then LAGS at the end.
*
compute lagnum = 0
while lagnum<lags {
   compute lagnum = lagnum + spanl
   if lagnum>lags
      compute lagnum=lags
   linreg(noprint,dfc=dfc) ressqr startl+lagnum endl
   # constant ressqr{1 to lagnum}
   exclude(noprint)
   # ressqr{1 to lagnum}
   display "ARCH(" @-1 lagnum @-1 ")"  @10 "Test Statistic:" $
      @-1 ####.#### %cdstat  @40 "Significance Level:" $
      @-1 ####.##### %signif
}
end

