st: historical maximum

You can get the running/cumulative maximum using subscripting, such as

gen cummax=x in 1
replace cummax=max(x,cummax[_n-1]) in 2/l

If you have panel data or missing data/gaps, you may want to check
out using
time series operators by using tsset.

The egen function record (think of setting a record...) handles the
nitty-gritty details quite nicely. It is available in the egenmore
package from ssc. It will deal with panel data and missing values.