It wouldn't be -egen, rowmax()- even if that obeyed your
syntax, as this is a column operation.
I don't think this is (much (more)) elegant,
but it's another way:
webuse grunfeld, clear
gen maxin5 = mvalue
qui forval i = 1/5 {
replace maxin5 = max(maxin5, F`i'.mvalue)
}
l company mvalue maxin5
I wouldn't call this the maximum of the next five,
but that's a boundary call. Also, this behaves
differently at the end of the panel. Finally, time series
operators and expressions based on _n won't agree
if there are gaps. The operators are always preferable.
Nick
[email protected]
Caleb Southworth
> 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);
>
*
* 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/