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
Esttab / Estout / Outreg Drop All CoefficientsIs there a way to drop all coefficients from a regression and just report R-Squared and number of ob…
Error using -xtdpdml- package: T value is too smallI am creating a cross-lagged panel data model using the user-contributed package -xtdpdml-. My model…
How to read the result of anticipation effect assumption test?Regarding Difference-in-Difference, the main assumption is the parallel trend satisfication. Regardi…
MergeI try to merge a file in cross-sectional format containing a certain variable with a master file whi…
how to combine two graphs into one?Hello, I would like to combine the below two graphs into one. The first one shows observed data, and…
Subscribe to:
Post Comments (Atom)
0 Response to Replace value by max of previous values
Post a Comment