*
* @RRGQTest  resids  start end
*
* RRGQTest performs a Goldfeld-Quandt type (sample partition) test for
* heteroscedasticity, applied to a series (such as recursive residuals)
* that are already assumed to be independent.
*
* Parameters:
*   resids     Series of recursive residuals
*   start end  Range to use. By default, the defined range of <<resids>>
*
* Options:
*   N=number of data points in the partitions
*       [roughly 1/3 of number of observations]
*   [PRINT]/NOPRINT
*
* Description:
*   By design, this divides the sample range in three, comparing the
*   variance in the first to that in the last using a two-tailed F test.
*   The null is that the variances are the same against the alternative
*   that they are different.
*
* Revision Schedule:
*   09/2009 Written by Tom Doan, Estima
*
procedure RRGQTest resids start end
type series  resids
type integer start end
*
option integer n
option switch  print 1
*
local integer startl endl nuse
local real    ssq1 ssq2
*
if .not.%defined(resids) {
   disp "Syntax: @RRGQTest  RESIDS start end"
   return
}
inquire(series=resids) startl<<start endl<<end
*
if %defined(n)
   compute nuse=n
else
   compute nuse=(endl-startl)/3+1
sstats / %if(t>=startl.and.t<startl+nuse,resids^2,0.0)>>ssq1 $
         %if(t>endl-nuse.and.t<=endl,resids^2,0.0)>>ssq2
compute %cdstat=ssq2/ssq1
*
* Do two-tailed F test
*
compute %signif=2.0*%ftest(%max(%cdstat,1.0/%cdstat),nuse,nuse)
*
if print
   disp "H("+nuse+")=" %cdstat "Significance level" #.##### %signif
end

