[Gretl-users] indexes in loops

Ignacio Díaz-Emparanza Ignacio.Diaz-Emparanza at ehu.es
Thu Sep 7 06:00:49 EDT 2006


El Jueves, 7 de Septiembre de 2006 11:33, Arnaud Bervas escribió:
>...
> Furthermore, is there a simple way, in a loop, to refer to a variable with
> a shifted index (for example refer to X$i+1 rather than X$i), like in
> Eviews (in which you only write !j =!i+1). I didn't manage to do something
> similar with Gretl.
>
>     Thanks
>     Arnaud

Looking at Jack's script gmmstart.inp, published recently in this list (I 
attach the file) may be the solution is to write a previous line "j = i+1"
and use the index j (but I have no very clear whether j is now an scalar or an 
integer as "i")

>loop i=2..11 --quiet
>   j = i - 1
>    matrix tmp[,$i] = (X[,j] - X[,11]) .* elmrs
>  end loop

I suspect that "j = i -1" is an alias of "scalar j = i - 1",
Do we have a command as "integer j = i - 1"?


-- 
Ignacio Díaz-Emparanza
Dpto. de Economía Aplicada III (Econometría y Estadística)
UPV-EHU
-------------- next part --------------
function OCfun (matrix theta, matrix X)
  set echo off
  set messages off
  
  scalar gam = theta[2]
  scalar delta = theta[1]
  scalar T = rows(X)
  scalar j = 0
  matrix elmrs = exp(log(delta) - gam*log(X[,12]))
  matrix tmp = zeros(T, 11)
  matrix tmp[,1] = (X[,11] + 1) .* elmrs - 1
  loop i=2..11 --quiet
    j = i - 1
    matrix tmp[,$i] = (X[,j] - X[,11]) .* elmrs
  end loop
  return matrix tmp
end function

open pricing.gdt
matrix X = { dataset }
matrix theta = { 1, 100 }
matrix tmp = OCfun (theta, X)
matrix tmp print






More information about the Gretl-users mailing list