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
Graph title in different colors to replace legendHi, I am trying to use the graph title to replace the legend. In this example, I would like the wor…
How to plot a scatter graph with just a few dots around a fitted line?Hi just wondering how to plot a scatter graph with just a few dots around a fitted line like that in…
Data interpretationHelp please with interpretation. Code: xtpcse ta rank score b safety health human ict prioritizatio…
Plotting variable for 5th and 25th day each month for multi-month panel data Hello (new here so excuse if my jargon sounds odd) For my panel data (going from 1st Jan 2012 - 30 …
RESET testHi, How can I run the RESET test for a gravity model with pair-fixed effects?: ppmlhdfe TRADE RTA …
Subscribe to:
Post Comments (Atom)
0 Response to Replace value by max of previous values
Post a Comment