On Wed, February 8, 2006 12:31, Ignacio Díaz-Emparanza wrote:
--------
nulldata 20
# function definition
function corrAR2 (scalar phi1, scalar phi2)
series y = 1.0
scalar rho1 = phi1 / (1-phi2)
genr y[2] = rho1
genr y = phi1*y(-1)+phi2*y(-2)
genr y2 = y(1)
return series y2
end function
# function call
(y1) = corrAR2 0.4 0.5
--------
Which is the problem?
I see no big problem. Your script runs unmodified on my box. Here's the output:
jack@ec-4:~/Prove$ gretlcli Ignacio.inp
gretl version 1.5.0
Copyright Ramu Ramanathan and Allin Cottrell
This is free software with ABSOLUTELY NO WARRANTY
Current session: 2006/02/08 12:56
"help" gives a list of commands
run Ignacio.inp
/home/jack/Prove/Ignacio.inp opened OK
? nulldata 20
periodicity: 1, maxobs: 20,
observations range: 1-20
? function corrAR2 (scalar phi1, scalar phi2)
? (y1) = corrAR2 0.4 0.5
? series y = 1.0
Generated vector y (ID 4)
? scalar rho1 = phi1 / (1-phi2)
Generated scalar rho1 (ID 5) = 0.8
? genr y[2] = rho1
Modified vector y (ID 4)
? genr y = phi1*y(-1)+phi2*y(-2)
Replaced vector y (ID 4)
? genr y2 = y(1)
Generated vector y2 (ID 6)
?
and, to check that everything's ok, if I issue manually "print y1", I get
? print y1
print y1
Varname: y1
Full data range: 1 - 20 (n = 20)
Current sample: 1 - 20
0.800000 0.820000 0.728000 0.701200 0.644480 0.608392 0.565597
0.530435 0.494972 0.463206 0.432769 0.404711 0.378269 0.353663
0.330599 0.309071 0.288928 0.270107 0.252507 NA
Which is not, I presume, exactly what you expected to get, but at least it runs.
One thing I often overlook is the fact that, as things stand now, you can't
define a function twice; to be more explicit: suppose you have a file
func.inp, which contains a function, and a file main.inp, which calls the
function via an "include" command. The first time you run "main"
everything
should work. The next time, you get an error because the second call to
"include" makes gretl think you're defining a function whose name is
already
taken. The solution I use is to put a "clear" statement before the function
definition; example:
(contents of func.inp)
function foo clear
function foo(scalar x1, series x2)
...
so I can include func.inp as many times as I want.
Hope this helps,
--
Riccardo "Jack" Lucchetti
Dipartimento di Economia
Facoltà di Economia "G. Fuà"
Ancona