Hi Stata experts,
below is my dataset, what I am looking forward to is by ID, if duration=1 & duration[_n+1] ==0 & duration[_n+2] ==0, then replace the duration[_n+1] ==1 & duration[_n+2] ==1. Can you help me out of this? Thank you very much.
clear
input float(ID duration var3)
1 30 1
1 30 0
1 20 0
1 16 0
2 35 0
2 86 1
2 24 0
2 87 0
3 23 0
3 86 1
3 60 1
3 87 1
3 34 0
3 14 1
3 67 1
3 89 0
3 43 0
4 32 1
4 54 1
4 100 1
4 58 1
4 85 0
4 34 0
4 16 0
end
blow dataset is what I expect
clear
input float(ID duration var3)
1 30 1
1 30 1
1 20 1
1 16 0
2 35 0
2 86 1
2 24 1
2 87 1
3 23 0
3 86 1
3 60 1
3 87 1
3 34 0
3 14 1
3 67 1
3 89 1
3 43 1
4 32 1
4 54 1
4 100 1
4 58 1
4 85 1
4 34 1
4 16 0
end
below is my dataset, what I am looking forward to is by ID, if duration=1 & duration[_n+1] ==0 & duration[_n+2] ==0, then replace the duration[_n+1] ==1 & duration[_n+2] ==1. Can you help me out of this? Thank you very much.
clear
input float(ID duration var3)
1 30 1
1 30 0
1 20 0
1 16 0
2 35 0
2 86 1
2 24 0
2 87 0
3 23 0
3 86 1
3 60 1
3 87 1
3 34 0
3 14 1
3 67 1
3 89 0
3 43 0
4 32 1
4 54 1
4 100 1
4 58 1
4 85 0
4 34 0
4 16 0
end
blow dataset is what I expect
clear
input float(ID duration var3)
1 30 1
1 30 1
1 20 1
1 16 0
2 35 0
2 86 1
2 24 1
2 87 1
3 23 0
3 86 1
3 60 1
3 87 1
3 34 0
3 14 1
3 67 1
3 89 1
3 43 1
4 32 1
4 54 1
4 100 1
4 58 1
4 85 1
4 34 1
4 16 0
end
Comment