Statalist The Stata Listserver


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

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


From   "Nuno Soares" <[email protected]>
To   <[email protected]>
Subject   st: RE: how to (elegantly) take max of next five observations
Date   Sun, 10 Dec 2006 18:38:02 -0000

Have you tried this:

tsset id year,year
gen for5=max(mem,f.mem,f2.mem,f3.mem,f4.mem)

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Caleb Southworth
Sent: domingo, 10 de Dezembro de 2006 19:23
To: [email protected]
Subject: st: how to (elegantly) take max of next five observations

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/

*
*   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