Hi,
I propose to overload the lags() function to accept not only a scalar
lag value, but alternatively a vector/matrix where the elements specify
which lags we want in the returned list.
Here's a hansl function that does what I have in mind:
<hansl>
function list getCertainLags( matrix idx, const list inp, bool bylag[0])
# returns a list with those lags of 'inp' specified by 'idx' elements
idx = vec(idx) # ensure col vector
list out = null
loop i=1..rows(idx)
lag = idx[i]
list temp = lags(lag, inp, bylag)
# watch out for the special case of lag 1
list templess1 = lag==1 ? null : lags( lag - 1, inp, bylag)
list out = out || (temp - templess1)
endloop
return out
end function
</hansl>
And then I also have an unrelated and more fundamental feature
suggestion: How about extending the foreach loop to also cover matrices
and perhaps even arrays? So instead of the common thing:
loop i=1..rows(inputvector)
v = inputvector[i]
...
one would do:
loop foreach v inputvector
...
and similarly for arrays.
This is of course pure syntactic sugar -- and I also admit that this
feels very pythonic, but I think it's not only present in Python.
Don't know how difficult it would be to implement. After all, currently
foreach is only for internal gretl strings.
thanks,
sven