How to reach n-th element in a list in Gretl?

140 Views Asked by At

I want to write a small script in Gretl. But I have a problem with reaching elemets in list.

list X = dataset

list X print

With the first line I put all variables in X list, and with the second line I print out all my variables. I want like with the arrays for exemple: array[3] and to get the (second) third element. How can I do this in Gretl? I need one by one the variable names because I want with loops to use them in pairs. Thank for halping!

1

There are 1 best solutions below

0
On

not sure I fully understand your issue. But let's try to provide some answer.

Load an example data set, define a list of series and print its values:

open denmark.gdt --quiet
list L = LRM LRY IBO IDE
print L --byobs

Array items in gretl can be accessed through square brackets. Here the second series item of list L is printed:

print L[2] --byobs

You said you want to loop over a list. Make use of the foreach-loop:

loop foreach i L --quiet
    print $i --byobs
endloop

Hope that helps