Gareth, If I'm interpreting correctly, I think the original question was a bit more complicated, as the poster wanted the historical max at a each point in time. (If that interpretation is correct, the answer is only a tiny bit more complicated than your answer -- if I'm wrong, you all can just ignore me).
Suppose we have a dated panel structured workfile with the series F of interest.
We are going to write a recursion to identify the historical maximum for the cross-section at a given point in time. First, we seed the recursion.
Code: Select all
smpl @first @first
series cummax = f
Next, for the remaining periods we compute the historical maximum by comparing the current value to the lagged historical maximum.
Code: Select all
smpl @first+1 @last
cummax = @recode(f>cummax(-1), f, cummax(-1))
Note that in since this is a dated panel workfile, the by-cross-section part of the calculation is handled naturally via the sample and recursion.
Lastly, we do the recoding to NAs.
Code: Select all
smpl @all
series mymaxes = @recode(cummax=f, cummax, na)