Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: how to (elegantly) take max of next five observations


From   Caleb Southworth <[email protected]>
To   [email protected]
Subject   st: how to (elegantly) take max of next five observations
Date   Sun, 10 Dec 2006 11:22:46 -0800 (PST)

I'm looking for a quick way to check the next five values in panel
dataset.

Data are
. tsset
       panel variable:  id (strongly balanced)
        time variable:  year, 1888 to 2005, but with gaps

This works:

bysort id (year): gen for5=max(mem, mem[_n+1], mem[_n+2], mem[_n+3],
mem[_n+4], mem[_n+5])

but involves the messy indexing. I would like something like this:

. egen for5=rowmax(F(1/5).mem_data)
time-series operators not allowed
r(101);

Thanks!

Caleb
[email protected]
University of Oregon Sociology
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index