[Gretl-users] passing a series name to a function
Ignacio Diaz-Emparanza
ignacio.diaz-emparanza at ehu.es
Tue Jun 19 04:28:59 EDT 2007
On Saturday 16 June 2007 17:32:17 Allin Cottrell wrote:
>
> I may be missing something, but I think the answer is that you'll
> have to pass a list to achieve what you want here.
I want a unique series as input and a list (with, for example, three series)
as output, and I want the output series be named in accordance with the
series input.
>
> The trouble is that when a single series is passed to a function,
> this series is known inside the function by the name of the
> corresponding function parameter, _not_ by the name it has in the
> calling script.
>
> function foo (series y)
> <create list of variables based on y>
> return list modlist
> end function
>
> list foolist = foo(myvar)
>
> In the above, function foo has no way of knowing that the series
> it sees as "y" is known as "myvar" in the caller.
>
> One way around this would be to allow string arguments to
> user-defined functions.
Yes I think so. I would like something like this could be possible in gretl:
function foo(string name)
series y=@name
#some calculation here
series @name_out=y^2 #for example
return series @name_out
end function
or alternatively, if we had a function to obtain the "external" name of a
variable, for example "sername(y)":
function foo(series y)
string name= sername(y)
series @name_out=y^2 #for example
return series @name_out
end function
--
Ignacio Diaz-Emparanza
DEPARTAMENTO DE ECONOMÍA APLICADA III (ECONOMETRÍA Y ESTADÍSTICA)
UPV/EHU
Avda. Lehendakari Aguirre, 83 | 48015 BILBAO
T.: +34 946013732 | F.: +34 946013754
www.et.bs.ehu.es
More information about the Gretl-users
mailing list