*
*  @DIVISIA   priceind  quantind  start  end
*  #  list of input price index series
*  #  list of input quantity index series
*
*  Computes a Divisia index
*
*  Parameters:
*     priceind    (Output) Series for the computed price index
*     quantind    (Output) Series for the computed quantity index
*     start end   Computation range [common range of input variables]
*
*  Options:
*     PERIOD=Normalization period for the price index [START by default]
*     VALUE=Normalization value [100.0 by default]
*
*     Written by Thomas Doan
*
procedure divisia priceind quantind start end
type series  *priceind  *quantind
type integer start  end
*
option real    value    100.0
option integer period
*
local vect[integer] pricelst quantlst
local integer startl endl periodl i ninputs
local series xxrev xxchnge
*
enter(varying,entries=ninputs) pricelst     ;* Enter list of prices
dim quantlst(ninputs)
enter quantlst                              ;* Enter list of quantities
inquire(reglist) startl<<start endl<<end
# pricelst quantlst

if %defined(period)
   compute periodl=period
else
   compute periodl=startl

set xxrev   startl endl = 0.0
set xxchnge startl endl = 0.0
*
do i=1,ninputs
  set xxrev startl endl = xxrev + pricelst(i){0} * quantlst(i){0}
end
do i=1,ninputs
  set xxchnge startl+1 endl = xxchnge+$
      (pricelst(i){0} / pricelst(i){1}-1) * $
   .5*(pricelst(i){0} * quantlst(i){0}/xxrev{0}+ $
       pricelst(i){1} * quantlst(i){1}/xxrev{1})
end do i
set(first=1.0) priceind startl endl = priceind{1}*(1+xxchnge)
set(scratch)   priceind startl endl = value*priceind/priceind(period)
set            quantind startl endl = xxrev/priceind
end


