[Gretl-devel] array indexing

Allin Cottrell cottrell at wfu.edu
Tue Aug 22 12:56:04 EDT 2006


On Tue, 22 Aug 2006, Riccardo Jack Lucchetti wrote:

>> Thanks.  Well then, we're not out of line with all other
>> programs.  (I suppose ox is really a programming language rather
>> than an "econometrics package" as such, and in programming
>> languages 0-base indexing is certainly the norm.)
>
> And even that, not always: IIRC, FORTRAN is 1-based too, and 
> so should be gauss and matlab. I think base 1 is ok, it's one 
> less thing for people without a C background to worry about if 
> they want to port their procedures into gretl scripts.

OK, agreed, we'll go with 1-based.

Attached: a little script that does the first, easy part of
the Verbeek GMM example.

Allin.
-------------- 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-devel mailing list