source bjfore.src
*
*  @BJTHEIL( options )  series  start  end
*     Computes Theil U statistics for a Box-Jenkins model
*
*  Parameters:
*     series      : Series to be forecast
*     start  end  : Range of entries for Theil Us
*
*  Options:
*     DIFFS    =Number of regular differences [0]
*     SDIFFS   =Number of seasonal differences [0]
*     ARS      =Number of autoregressives[0]
*     MAS      =Number of moving averages[0]
*     SAR      =Number of seasonal autoregressives[0]
*     SMA      =Number of seasonal moving averages[0]
*     STEPS    =Number of forecast steps to evaluate [year's worth]
*     TRANS=[NONE]/LOG/ROOT
*     [CONSTANT]/NOCONSTANT
*

procedure bjtheil  series  start  end
type series  series
type integer start end

option  int     steps
options int     diffs  0
options int     sdiffs 0
options int     sma    0
options int     sar    0
options switch  const  1
options int     ars    0
option  int     mas    0
option  choice  trans  1  none log root

local integer  stepsl  startl i
local series   eetheil
local equation eqtheil

if .not.%defined(series).or..not.%defined(start).or..not.%defined(end) {
   display 'Syntax: @BJTHEIL series start end'
   return
   }

inquire(seasonal) stepsl>>steps
inquire(series=series)  startl

clear eetheil
equation eqtheil series
# eetheil
associate eqtheil
#  1.0
theil(setup) 1 stepsl end
# eqtheil
do i=start,end
   if stepsl+i-1 > end
      compute stepsl=stepsl-1
   @bjfore(diffs=diffs,sdiffs=sdiffs,ars=ars,mas=mas,sma=sma,sar=sar, $
    const=const,trans=trans) series  i i+stepsl-1 eetheil
   theil i
end do i
theil(dump)
end

