Am 18.05.2022 um 14:13 schrieb Sven Schreiber:
I think I've diagnosed the problem to be that $nvars is much much
than the number of elements in the list Xw (+1 for the dependent
variable), and that varname(i) at some point throws an error because of
If I replace the if-line above with the following two lines, then
everything seemingly runs OK:
catch string vname = varname(i)
if !$error && vname == arg
Thanks, Allin, I saw that you put this fix already in the latest snapshot.
I'm not sure if the use of $nvars in outer_series_id is a bug on
regls side, or if there's a bug with gretl concerning which sub-parts of
the dataset (which series) are available in a nested function call here.
OK, so let me get this straight:
- $nvars is fine, because it is documented to refer to the whole (outer)
dataset, it is not confined to any function scope.
- What's a bit surprising is that varname() also has access to the
outermost scope, so calling varname(1) inside a (user-defined hansl)
function actually gives you the name of the first variable in the
dataset, even if no data was passed to the function. To me this seems to
go a bit against the spirit of hansl functions. I'm not saying that it
should necessarily be changed, but I guess it should be mentioned more
explicitly in the documentation.
- What you're doing with the outer_series_id() function in regls
basically seems to be the same thing that the built-in function varnum()
exists for. However, my testing showed that varnum() _is_ strictly
confined to the function scope, and so it cannot be used here. (Inside a
function it returns NA when called with a string arg that corresponds to
a variable name in the outer scope.) But this somehow seems to suggest
that a more elegant solution should exist for this use case, instead of
having to write a 11-line function just for that. Maybe varnum() should
also be enabled for the outer scope just like varname()? Or only
optionally with an extra switch argument?
- [Side remark: The error thrown by varname(i) for i too large is simply
"invalid arg", whereas varnames(deflist(i)) yields the more informative
"out of bounds" error.]