Sorry for the lengthy series of comments/questions, but writing and
testing moderately complicated functions really highlights the
interaction of various commands.
In this particular case, the issue is generated by the following script
function panel_foo(series y, list X)
series lunit=$unit
genr time
genr ltime=time
setobs 1 1 --cross-section
# Define sample to exclude missing values for either y or X
list vars = y X
smpl ok(vars) --restrict
...
smpl full
setobs lunit ltime --panel-vars
return matrix result
end function
This seemed to work fine, until I tried the following test
smpl id < 10 --restrict
matrix res=panel_foo(y, X)
at which point the function fell over at the final setobs, reporting
missing values for the panel variables.
Now I understand what has happened. The "smpl full" command in the
function has overridden the restricted sample that was given to the
function and reverted to the full sample of data that gretl has been
given. As a result, lunit and ltime, which were created within the
function, have missing values for observations that were not given to
the sample. I can get round this in part by defining lunit & ltime
as arguments of the function and changing the calling script, but the
sample restriction would still be overridden.
It seems to me that the operation of "smpl full" is contrary to the
principle that all operations within a function are - or should be -
local. In other words, issuing the "smpl full" command within a
function should do no more than revert to the data that was supplied
to the function.
Gordon