Hello,
I have a strange problem. I am using the following code to count the unique visits of an insurant/patient (via DispensingDate). InsurantNumber is unique to a patient and to a doctor, meaning one patient attending two doctors will have two InsurantNumbers.
After that I want to generate a new variable which contains the number of unique visits by doctor. I do that via
Now I have run this a couple of times and I get slightly different results almost every time. I tried various versions of doing this (bysort and egen in one command; foreach loop for seperate calc per doctor) and always get different results per doctor (+- 4) while the total amount of visits stays the same.
Perhaps an important note: If I run the same command multiple times the calculations are equal, but if I for example run my whole file another time the results vary. I even traced this down to the point where I ran a random command between every execution of the same countprocedure, just out of curiosity, and as I feared then again the results varied.
I simply dont get it.
I hope someone can help me.
Regards,
Karl
I have a strange problem. I am using the following code to count the unique visits of an insurant/patient (via DispensingDate). InsurantNumber is unique to a patient and to a doctor, meaning one patient attending two doctors will have two InsurantNumbers.
Code:
sort InsurantNumber DispensingDate by InsurantNumber: gen id_ = _n == 1 by InsurantNumber: replace id_ = id_[_n]+1 if _n > 1 & DispensingDate != DispensingDate[_n-1]
Code:
sort doctor by doctor: egen visits=total(id_)
Perhaps an important note: If I run the same command multiple times the calculations are equal, but if I for example run my whole file another time the results vary. I even traced this down to the point where I ran a random command between every execution of the same countprocedure, just out of curiosity, and as I feared then again the results varied.
I simply dont get it.
I hope someone can help me.
Regards,
Karl
Comment