I have a small dataset and the "lep" variable has some errors. I want to fix the errors with the rule below,
Within ID, if the consecutive zeros occur in the lep variable, then the zeros before the consecutive zeros should be equal 0.
For instance, when ID=1 and position=8, and 9, lep=0 for these 2 positions, which is completely correct.
However, the lep variable equal 0 when position=4 and position=6, respectively, which is wrong.
They should be corrected as 1, respectively. For other IDs, the similar situation should be changed as well----like ID=4, when the position=7, the lep=0 should be changed 1.
*Simulated data for illustrative purpose.
clear
input byte (id lep position)
1 1 1
1 1 2
1 1 3
1 0 4
1 1 5
1 0 6
1 1 7
1 0 8
1 0 9
2 1 1
2 1 2
2 0 3
2 1 4
2 0 5
2 0 6
2 0 7
3 1 1
3 0 2
3 1 3
3 0 4
3 0 5
4 1 6
4 0 7
4 1 8
4 0 9
end
Thank you!
Within ID, if the consecutive zeros occur in the lep variable, then the zeros before the consecutive zeros should be equal 0.
For instance, when ID=1 and position=8, and 9, lep=0 for these 2 positions, which is completely correct.
However, the lep variable equal 0 when position=4 and position=6, respectively, which is wrong.
They should be corrected as 1, respectively. For other IDs, the similar situation should be changed as well----like ID=4, when the position=7, the lep=0 should be changed 1.
*Simulated data for illustrative purpose.
clear
input byte (id lep position)
1 1 1
1 1 2
1 1 3
1 0 4
1 1 5
1 0 6
1 1 7
1 0 8
1 0 9
2 1 1
2 1 2
2 0 3
2 1 4
2 0 5
2 0 6
2 0 7
3 1 1
3 0 2
3 1 3
3 0 4
3 0 5
4 1 6
4 0 7
4 1 8
4 0 9
end
Thank you!
Comment