Hello

I am working with a large dataset in Stata with 40,000 stroke patients admitted to a hospital, and I could really use some help regarding duplicates.

Some patients in my dataset have been admitted several times during the study period, and I want to keep only first visits, but it appears, that some patients were registered twice during the hospital stay with the same stroke - i.e. they were actually registered twice during the first visit (due to transfer between hospitals). In that case I want to keep both first and second entry of this patient, because it is in fact the same stroke, that is being treated.

For each observation I have a:
Personal identification number “pnr”
I have generated a variable “visit_n” (1 for first, 2 for second, 3 for third visit and so on).
I have the admission date “acutedate” (days after 1st Jan 1960).

I want to keep visit 1 for all patients and delete all visits with a value >1, except if visit 2 is within the first 2 days after visit 1.

I hope this is understandable, and that you can help me, thanks in advance!

Kind regards
Sine Mette Buus