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
Replacing column values with values of the same column by household idHi everyone, I have missing values in the variable "religion" for the year 2009. I want to copy the…
Obtaining milliseconds from -now()-According to the documentation: tc = now() where tc: number of milliseconds from 01jan1960 00…
Diagnostic Tests Panel DataDear all, I am working on my thesis using panel data in Stata but we never really discussed this in…
Using esttab to show both linear regression and logistic regression (odds ratio) outcomesHello, I'm trying to display 3 regression outcomes together by using Code: esttab command. Among t…
Using asdoc, acum to store values that I can write laterI am trying to use asdoc to create a table with the data I want. I first use: Code: sum XYZ if tin…
Subscribe to:
Post Comments (Atom)
0 Response to Replace value by max of previous values
Post a Comment