Hello, I have the following panel dataset:

clear
input country_code year value
1 1990 2
1 1991 5
1 1992 1
1 1993 6
1 1994 7
1 1995 2
2 1990 1
2 1991 3
2 1992 2
2 1993 4
2 1994 5
2 1995 1
end

I would like to create a new variable ("value_prev_max") based on the maximum of all previous "value". The result would look like this:

clear
input country_code year value value_prev_max
1 1990 2 .
1 1991 5 2
1 1992 1 5
1 1993 6 5
1 1994 7 6
1 1995 2 7
2 1990 1 .
2 1991 3 1
2 1992 2 3
2 1993 4 3
2 1994 5 4
2 1995 1 5
end

As a starting point, I have tried to work with the egen command below but this does not work...

bys country_code: egen value_prev_max = max(value)