-----Original Message-----
From: gretl-users-bounces(a)lists.wfu.edu [mailto:gretl-users-
bounces(a)lists.wfu.edu] On Behalf Of Riccardo (Jack) Lucchetti
Sent: Monday, July 29, 2013 3:33 AM
To: Gretl list
Subject: Re: [Gretl-users] Passing a list of series to a function
On Mon, 29 Jul 2013, Logan Kelly wrote:
> Hello,
>
> I am using Gretl 1.9.12cvs on WIN 8. Is there a way to pass a list
> series to a function? I used the following function declaration:
>
> function void dplot(list lstDIV, string filetype, string strTitle[null], string
strDisc[null])
> string ddat = varname(lstDIV[1])
> sprintf send "%s", date(firstobs(@ddat)) end function
>
> but get this error
>
> The symbol 'DQ_us' is undefined
> *** error in function dplot, line 24
>> sprintf send "%s", date(firstobs(DQ_us))
>
> So I am able to pass the list but the individual series are not
> accessible? Anyway around this?
Using series names from a list within a function may be tricky, because of
possible name collisions. If I understood correctly what you want to do, I
suppose you can get some inspiration from the following small script:
<hansl>
function void myfunc(list X, scalar i)
names = strsub(varname(X),","," ")
printf "The %d-th series in %s is %s\n", i, argname(X),
strsplit(names, i)
end function
open AWM -q
list A = 7 8 9 10 11
myfunc(A, 4)
</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
-------------------------------------------------------
Thanks Jack,
This is not quite the problem I am having. string ddat = varname(lstDIV[1]) works fine.
lstDIV[1] returns the series ID # of the first element on lstDIV. So I have no problem
getting the name of the series. I am having trouble getting series within the scope of the
function. I can approach the problem another way, namely by using bundles, but I was
hoping to keep this function as simple as possible.
What I am doing is passing a list of series to be included in a multiplot figure.
Thanks,
Logan