Hi there, I am new to Stata and hope to seek advice from you. My dataset looks like below. For ID1, it has three consecutive epi=1, so does ID2. ID3 has 4 consecutive epi=1. ID4 in total has 4 epi=1 but they are interrupted by 0, ie the four 1s are not consecutively appeared. I want to keep ID 1, 2, 3 as they have consecutive at least three epi=1. Could you please help me out of this? what should be the stata codes to deal with my needs? NB: I need to keep all the observations, e.g. ID has two epi=0 and three epi=3, in the end, I need to keep this five ID1 not only the three epi=1
ID epi
1 0
1 0
1 1
1 1
1 1
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 1
2 1
2 1
3 0
3 0
3 1
3 1
3 1
3 1
4 0
4 1
4 1
4 0
4 0
4 0
4 1
4 1
What I expect for the cleaned dataset is like below:
ID epi
1 0
1 0
1 1
1 1
1 1
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 1
2 1
2 1
3 0
3 0
3 1
3 1
3 1
3 1
Thank you very much!
ID epi
1 0
1 0
1 1
1 1
1 1
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 1
2 1
2 1
3 0
3 0
3 1
3 1
3 1
3 1
4 0
4 1
4 1
4 0
4 0
4 0
4 1
4 1
What I expect for the cleaned dataset is like below:
ID epi
1 0
1 0
1 1
1 1
1 1
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 1
2 1
2 1
3 0
3 0
3 1
3 1
3 1
3 1
Thank you very much!
Comment