I have a wide format dataset like this,
clear
input byte (id state1 state2 state3)
1 0 0 1
2 0 1 1
3 1 1 1
4 0 0 0
5 1 0 1
end
I want to remove some data with rule below,
for any person, as long as the 1st 1 appeared on the state variable, for example,
when id==3, state1==1, then state2=1 and state3==1 should be dropped instead of missing values.
when id==5, state1==1, then state2=0 and state3==1 should be dropped instead of missing values.
when id==2, state1==0 & state2=1, then state3==1 should be dropped instead of missing values.
As for the data with id==1 and id==4, they should be kept without any change.
I can reshape the data from wide to long to do this, but I want to do it directly in wide format data.
Thank you!
clear
input byte (id state1 state2 state3)
1 0 0 1
2 0 1 1
3 1 1 1
4 0 0 0
5 1 0 1
end
I want to remove some data with rule below,
for any person, as long as the 1st 1 appeared on the state variable, for example,
when id==3, state1==1, then state2=1 and state3==1 should be dropped instead of missing values.
when id==5, state1==1, then state2=0 and state3==1 should be dropped instead of missing values.
when id==2, state1==0 & state2=1, then state3==1 should be dropped instead of missing values.
As for the data with id==1 and id==4, they should be kept without any change.
I can reshape the data from wide to long to do this, but I want to do it directly in wide format data.
Thank you!

Comment