I have a dataset like this,
clear
input byte (id state)
1 0
1 0
1 0
2 0
2 1
2 0
3 0
3 .
3 0
4 0
4 .
4 1
4 .
4 0
end
I want to create a new variable "fail", which should satisfy the rule below,
1) when all values of the variable state=0 within id, then all values of the variable fail==0;
2) as long as there is a value of state=1 within id, then all values of the variable fail==1;
3) when the state variable takes on the value of "0" and "missing value" within id, then all values of the variable fail==missing value
In sum, the resulting data should look like this,
clear
input byte (id state fail)
1 0 0
1 0 0
1 0 0
2 0 1
2 1 1
2 0 1
3 0 .
3 . .
3 0 .
4 0 1
4 . 1
4 1 1
4 . 1
4 0 1
end
Can someone help me with Stata Code?
Thank you!
clear
input byte (id state)
1 0
1 0
1 0
2 0
2 1
2 0
3 0
3 .
3 0
4 0
4 .
4 1
4 .
4 0
end
I want to create a new variable "fail", which should satisfy the rule below,
1) when all values of the variable state=0 within id, then all values of the variable fail==0;
2) as long as there is a value of state=1 within id, then all values of the variable fail==1;
3) when the state variable takes on the value of "0" and "missing value" within id, then all values of the variable fail==missing value
In sum, the resulting data should look like this,
clear
input byte (id state fail)
1 0 0
1 0 0
1 0 0
2 0 1
2 1 1
2 0 1
3 0 .
3 . .
3 0 .
4 0 1
4 . 1
4 1 1
4 . 1
4 0 1
end
Can someone help me with Stata Code?
Thank you!

Comment