This is not quite what was asked.
Scott is flagging here that missing values
of -invest- are problematic, but with
this code fewer than 5 values will
be identified whenever -invest- is missing.
My posting indicates another way.
Nick
[email protected]
Scott Merryman
> Here is one way, using the "grunfeld.dta" data set with
> investment as the
> variable of interest:
>
> . webuse grunfeld
>
> . sort year invest
>
> . gen top5 = .
> (200 missing values generated)
>
> . by year: replace top5 = 1 if _n >_N-5 & invest <.
> (100 real changes made)
>
> . replace top = 0 if top ==.
> (100 real changes made)
>
> . egen total = sum(invest) if top == 1 , by(year)
> (100 missing values generated)
*
* 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/