On Sun, 24 Oct 2010, Sergei B wrote:
I'm a new user to GRETL and maybe the question I'm going to
ask
is somehow obvious, but I was unable to find the answer so far
(searched also through the archive of this mailing list).
No, your question is not that obvious, and in fact you seem to
have exposed a bug.
I have a set of daily stock prices for a certain period
(1970-2007). Some daily data is missing and the missing
observations are marked as NA. What I would like to do is to
compact the data from daily to monthly by summing the log
returns of daily data. When I try to do that, months, for which
daily data wasn't available, get 0 instead of NA. Is there a way
to avoid this from happening?
If all the daily values for a given month are NA, then clearly the
monthly summation should also be NA. This bug will be fixed
shortly. In the meantime there are various work-arounds.
One possibility is to use gretl's zeromiss() function, which turns
zeros into missing values, on the compacted series:
x = zeromiss(x)
But obviously you'd want to do that only if you're confident that
a monthly value of 0 is never a valid value. An alternative is to
convert the NAs in the original daily data into some clearly
out-of-bounds value, on the basis of which you can then correct
the monthly series. Here is a complete script that illustrates
what I'm talking about:
# construct an artificial 3-month daily series
nulldata 91
setobs 7 2010/09/01 # 7-day daily data
series x = normal()
# simulate your situation by making all the
# October values into NAs
series oct = (t > 30 && t < 62)
x = oct ? NA : x
# now make the NAs into (for example) -9999
x = ok(x)? x : -9999
# compact the data to monthly by summation
dataset compact 12 sum
# finally, convert "big negative numbers" to NA
x = (x < -9000)? NA : x
# and inspect the results
print -o
If some months contain just a few NAs at the daily level while
others contain nothing but NAs, then you'd have to modify the
above approach slightly, but hopefully you get the general idea.
Allin Cottrell