Hi all,
If I have panel data and I want to create a new variable containing the maximum of another variable how would I do that?
The obvious answer would be bysort var: egen newvar=max(oldvar).
But, what if I want the value to appear only once for each id AND I want to replace the max of oldvar with the earliest date for ids that had an event?
Example:
id var1 var2 newvar
1 3 0
1 4 0
1 7 0 7
2 13 1 13
2 50 0
2 100 1
3 15 0
3 20 1 20
3 23 1
If I have panel data and I want to create a new variable containing the maximum of another variable how would I do that?
The obvious answer would be bysort var: egen newvar=max(oldvar).
But, what if I want the value to appear only once for each id AND I want to replace the max of oldvar with the earliest date for ids that had an event?
Example:
id var1 var2 newvar
1 3 0
1 4 0
1 7 0 7
2 13 1 13
2 50 0
2 100 1
3 15 0
3 20 1 20
3 23 1
Comment