I have a dataset in Stata in which an ID can have a maximum of two different records. I am trying to restrict my dataset so that the second record is removed if the result for test A is positive. I have provided an example of a sample dataset below. In my desired output I would like to keep both records for ID 1, the first record for ID 2 (test A record), and the record for ID 3 and ID 4.
ID | Test Type Result
------------+-----------------------------------
1 | A -ve
1 | B +ve
2 | A +ve
2 | B +ve
3 | A +ve
4 | A -ve
------------+-----------------------------------
Currently my dataset is sorted by ID, but I am unable to figure out how to restrict the dataset based on my desired criteria described above.
Create a new dataset which has only ID and Test Type A's result.
Merge the new dataset with original data, then drop observations in which result_a is positive and Test Type is B.
I haven't tested the code because I don't have Stata on my pc, but this should work.