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)
Related Posts with Replace value by max of previous values
Linux distribution for Stata?I am considering to leave the Windows operating system behind and to switch to Linux. However, I fin…
Heckman two step modelDear Stata Users, I am attempting to apply the two step Heckman model, with a Tobit regression as f…
Reshape - variable names currently as valuesI have problems with data structure and would like to reshape into wide. Currently I have the name o…
power usermethodHi, Does anyone know if I can use the -power usermethod- in Stata14.2? I just tried, but I get err…
Licensing material incorporated in Java pluginsI've been wading into the world of Java plugins, which has involved wading into the world of Java (i…
Subscribe to:
Post Comments (Atom)
0 Response to Replace value by max of previous values
Post a Comment