-----Ursprüngliche Nachricht-----
Von: gretl-users-bounces(a)lists.wfu.edu [mailto:gretl-users-
bounces(a)lists.wfu.edu] Im Auftrag von Riccardo (Jack) Lucchetti
Gesendet: Donnerstag, 23. Februar 2017 15:05
An: Gretl list <gretl-users(a)lists.wfu.edu>
Betreff: Re: [Gretl-users] loop, string substitution and varname from list
On Thu, 23 Feb 2017, Sven Schreiber wrote:
> Am 23.02.2017 um 14:32 schrieb Schaff, Frederik:
>> Many thanks,
>>
>> I tried a slightly different version from yours: -------- .... (see
>> first comment) scalar j = 0 loop foreach i xs j++ print j $i <-
>> gnuplot $i ys[j] endloop -------- unfortunately it is not working.
>> Also, what if I wanted to combine the var names of both the items?
>> Your option would not allow this. Is there now way to simply access
>> the name of a var by means of the name of the var?
>
> Actually I was too cautios, the yy[i] trick does work in the foreach loop.
> Here's a tested example:
>
> <hansl>
> open denmark
>
> list xx = IBO IDE
> list yy = LRM LRY
>
> loop foreach i xx
> plot_$i <- gnuplot $i yy[i]
> endloop
> </hansl>
Something a little more general:
<hansl>
open AWM
list xx = YEN GCN STN
list yy = YER GCR LTN
k = 1
matrix my = yy
loop foreach i xx
string s = varname(my[k])
string plotname = sprintf("p%d_$i_vs_%s", k, s)
@plotname <- gnuplot $i yy[k]
k++
endloop
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------
Many thanks to both of you! The second, more general is working fine. Although it would be
a nice feature if one could directly access the name of a variable (something like
idname).
Regards,
Frederik