Hello everybody, I have a hospital list (ik) doing several surgeries (haupt_op).
Now I want create a new variable (n_patients1), which counts the number of Haupt_op by ik, but only if all Haupt_op contain 1 or 2 or 3 or 4.

Code:
 ik   haupt_op    n_patients1
    
  1.          1              
  2.          2             3
  2.          3              
  2.          7
  3.          8             3

  3.          3
  3.          4             
  4.          2             2
  4.          3
  5.          7

 6.           7
 7.           7             3
 7.           9
 7.           4

 7.           8
 8.           4            1
 9.           4             3
 9.           2
 9.           8
Code:
bysort ik: gen n_patients1 = _N if _n == 1 & haupt_op==1 | haupt_op==2  | haupt_op==3  | haupt_op==4
.
As you can see my code counts every ik containing haupt_op 1 to 4. How can I tell stata, to only generate the new variable if haupt_op is 1/2/3/4 and nothing else?