Hey Allin,
thanks for replying. But it is not exactly what I need. In your example 'sprintf astr$i "%s", varname(i)' generates a string with the name of a variable with the ID 'i' from the loaded dataset. But I need a string with the name of the i'th variable in a list.
For example, the following returns a string containing the names of the variables in the list in each round, but I need in the first round the name of the first variable in ttt, in the second round the name of the second variable in ttt and so on...
<hansl>
list ttt = LRM LRY
scalar vars = nelem(ttt)
loop i=1..vars
print "$i"
sprintf astr$i "%s", varname(ttt)
printf "%s\n", astr$i
endloop
<hansl>
Artur
On Tue, 12 Jun 2012, artur tarassow wrote:[Wide comments stripped out of script: it's helpful if you don't
> I am struggling with the following problem:
assume that people are reading mail in a window that's hundreds of
columns wide.]
> print "$i"
> <hansl>
> set echo off
> set messages off
> open denmark
> list ttt = LRM LRY
> scalar vars = nelem(ttt)
> varnames = varname(ttt)
>
> loop i=1..vars
> sprintf astr$i "%s", varnames($i)
> printf "%s", @astr$iCorrected loop:
> endloop
> <\hansl>
loop i=1..vars
print "$i"
sprintf astr$i "%s", varname(i)
printf "%s\n", astr$i
endloop
There's no function "varnames()" but there is a "varname()".
Using "i" rather than "$i" as an argument to varname is not really a
correction, or only a stylistic one: no need to use string
substitution when it's a numerical value you want. And using
@astr$i instead of astr$i as an argument to printf is not
currently an error but arguably it should be one. In that position
you really want a string literal (in double quotes) or the name of a
string variable, and @astr$i is neither.
Off-topic, but "<\hansl>" would be an error if you were writing XML
rather than just pseudo-XML ;-)
Allin Cottrell
_______________________________________________
Gretl-users mailing list
Gretl-users@lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users