Hi Peter,
Thanks for following this up. Here's the deal:
First, you got a misleading error message, "Bad character
'b' in date string". That is fixed in my source tree and
wll be fixed in CVS as soon as sourceforge CVS is up again
(unfortunately it's broken right now). However, the other
part of the error message, namely
error in new starting obs
was quite correct: your function tried to push the start of
the sample range outside of the range passed in by the
caller, which is not allowed.
This is because of the way that firstobs() and lastobs()
work at present -- as noted in the Function Reference.
That is, firstobs() gives the observation number for the
first non-missing value of its series argument, but this
may occur before the start of the current sample range.
There's a case for changing that, so that firstobs() and
lastobs() do not return values outside of the current
sample, but that would be backward incompatible so I'm
not going to make the change uniterally; I'll raise the
question on the devel list.
I'm attaching a modified (skeletal) version of your script
that shows how to deal with sampling inside a function.
If we decide to change firstobs() and lastobs() this will
still work, although the conditional stuff with the '?'
operator would become redundant.
Allin