I've just discovered something that I think is a bug, though it can
also be a convenience in some cases. I'd be interested to hear what
people think about it.
Simplest case:
series u = normal()
u = 0.5 * u(-1)
The thing is that after the second line is executed, the first value
of u is not NA, it's just the original value. More generally, in this
sort of case we skip any initial NAs resulting from the expression on
the right before starting our rewrite of the original series.
I noticed this when generating an AR error in a panel dataset: for
individual 1 there was no initial NA, but for all subsequent
individuals the first observation was NA, as I think it ought to be.
The convenient case: if you're generating forecast errors based on an
AR process, you may well want to initialize the series to zero and
have pre-sample values assumed to be zero. You can do that cleanly
with the filter() function, but it seems more transparent to do it "by
formula". As things stand a zero initialization carries over into the
output from an autoregressive formula, but if we decide to "fix" the
issue that will no longer be the case, one will have to do something
like
u = rho*u(-1) + ...
u[1] = 0 # scrub the initial NA
Allin