st: RE: RE: No need for loops?

 From "Nick Cox" To Subject st: RE: RE: No need for loops? Date Thu, 4 Dec 2003 20:34:59 -0000

```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,
> too)?

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".
http://info.astrian.net/jargon/terms/f/fencepost_error.html

>
> Also, below you wrote:
>
> > by country: replace next12 = . if pronext12 | _n < 12
>
> This should be
>
>   by country: replace next12 = . if pronext12 > 0 | _n < 12
>
> right?

Same thing in this context as -pronext12- is never
negative. See
http://www.stata.com/support/faqs/data/trueorfalse.html
or the article in SJ 2(1) 2002.

Nick
n.j.cox@durham.ac.uk

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:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```