Hi all
I have a panel dataset that looks like:
Id date Var1 Var2
1 1 0 2
1 2 0 2
1 3 1 3
1 4 0 5
1 5 0 4
1 6 1 4
1 7 0 8
1 8 0 10
I would like to create a new variable, say Var3, that captures, within each id, the maximum value of Var2 from when var1=1 until the previous time Var1=1. So in this case it would be:
Id date Var1 Var2 Var3
1 1 0 2 .
1 2 0 2 .
1 3 1 3 max(3,5,9)=9
1 4 0 5 .
1 5 0 9 .
1 6 1 11 12
1 7 0 12 .
1 8 0 10 .
I have multiple id's in the dataset so this should be within each id.
Any help with this would be much appreciated.
best wishes to all
Costas
I have a panel dataset that looks like:
Id date Var1 Var2
1 1 0 2
1 2 0 2
1 3 1 3
1 4 0 5
1 5 0 4
1 6 1 4
1 7 0 8
1 8 0 10
I would like to create a new variable, say Var3, that captures, within each id, the maximum value of Var2 from when var1=1 until the previous time Var1=1. So in this case it would be:
Id date Var1 Var2 Var3
1 1 0 2 .
1 2 0 2 .
1 3 1 3 max(3,5,9)=9
1 4 0 5 .
1 5 0 9 .
1 6 1 11 12
1 7 0 12 .
1 8 0 10 .
I have multiple id's in the dataset so this should be within each id.
Any help with this would be much appreciated.
best wishes to all
Costas

Comment