[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: RE: No need for loops?
de la Garza, Adrian
> I don't understand, however, what the _n<12
> does. Can you please clarify? I don't know why, for
> instance, if for a
> country my -ratio- variable is not populated (all missing
> values) but
> -program- does have 1s now and then, why -prev12- gets a
> missing value
> when -program- = 1 but -next12- gets a 0 (when it should be missing,
When we construct an "average" as "sum" / 12,
that "average" is biased downwards if in fact
"sum" is the sum of fewer than 12 values.
Hence it is not comparable with the other averages.
This applies at the beginning of a series if looking
backwards and at the end if looking forwards.
I didn't test my code on missing ratios, just the
block of data in your previous post.
P.S. check my code for "fencepost errors".
> Also, below you wrote:
> > by country: replace next12 = . if pronext12 | _n < 12
> This should be
> by country: replace next12 = . if pronext12 > 0 | _n < 12
Same thing in this context as -pronext12- is never
or the article in SJ 2(1) 2002.
Incidentally, the reversal of time in my previous
post is not essential. You can do things like
bysort country (date) : gen sumratio = sum(ratio)
by country : gen next12 = (sumratio[_n+12] - sumratio) / 12
but I think an extra variable is essential for
each calculation (here -sumratio-). I find
reversing time easier to think with.
* For searches and help try: