clear all
set obs 3
gen x=3
replace x=2 in 2
replace x=5 in 3
mkmat x, mat(X)
gen ytemp=.
mkmat ytemp, mat(Y)
if _N==1 {
gen y=x
drop ytemp
}
local num=_N
else{
mat Y[1,1]=X[1,1]
forvalues i = 2(1)`num'{
if X[`i',1]>Y[`i'-1,1]{
mat Y[`i',1]=X[`i',1]
}
else mat Y[`i',1]=Y[`i'-1,1]
}
}
svmat Y, n(y)
drop ytemp
rename y1 y