Hi Riccardo and Allin,

Thank you very much for your responses and ideas. This was exactly what I was looking for!! ;-)

I've got only one problem - maybe it is a bug or so. I modified the function like this:
------
function series paasche_index (list P, int base)
   matrix MP = {P}
   matrix Num = sumr(MP)
   matrix Den = sumr(MP[base,])
   series ret = 100 * (Num ./ Den)
   return ret
end function
-----

I've got obs. from 1947:1 to 2010:2 and before running the function for a variable I restrict the sample by "smpl --no-missing x". For some reason I obtain an error for some variables saying:
"? smpl --no-missing q
Full data range: 1947:1 - 2010:2 (n = 254)
Current sample: 1952:1 - 2008:4 (n = 228)

? series q_indx = paasche_index(q, 2005:1)
Index value 233 is out of bounds
error in function paasche_index
> matrix Den = sumr(MP[base,])

Error executing script: halting
> series q_indx = paasche_index(q, 2005:1)"

This is weird because the current sample has only 228 obs  and not 233, isn't it?

Best,
Artur



Am 13.07.2010 14:59, schrieb Riccardo (Jack) Lucchetti:
On Tue, 13 Jul 2010, Artur T. wrote:

Hi gretl community,

is there a simple way to generate a index series of a variable, e.g.
Lapeyres (year x =100) or Paasche??
At the moment I use a spreadsheet to construct it easily but this
requires the ex- and import of the series of interest every time...

Something like this?

<script>
function series laspeyres(list Prices, list Quantities, scalar base)
    genr time
    scalar ndx = time[base]
    qbase = {Quantities}[ndx,]'
    series ret = lincomb(Prices, qbase)
    return ret*100/ret[base]
end function

function series paasche(list Prices, list Quantities, scalar base)
    genr time
    scalar ndx = time[base]
    pbase = {Prices}[ndx,]'
    series ret = sumr({Quantities} .* {Prices})
    return ret*100/lincomb(Quantities, pbase)
end function

# --- example with fake data ----------------------------------------

nulldata 40
setobs 4 2000:1

price1 = uniform()
price2 = uniform()
price3 = uniform()

q1 = uniform()
q2 = uniform()
q3 = uniform()

list P = price1 price2 price3
list Q = q1 q2 q3

series LPI = laspeyres(P, Q, 2002:1)
series PPI = paasche(P, Q, 2002:1)
series FPI = sqrt(LPI*PPI)
</script>


Riccardo (Jack) Lucchetti
Dipartimento di Economia
Universitą Politecnica delle Marche

r.lucchetti@univpm.it
http://www.econ.univpm.it/lucchetti
_______________________________________________ Gretl-users mailing list Gretl-users@lists.wfu.edu http://lists.wfu.edu/mailman/listinfo/gretl-users