Hi there, Statalisters,

I have a question similar to one that was asked some years ago, and I am not sure if it was resolved: https://www.stata.com/statalist/arch.../msg00123.html

I have a variable identifying patients (pid) and a variable with the date each patient visited the clinic and received a diagnosis (date). Both are of the variable type "long" if that is relevant. The data is formatted as YYYY/MM/DD, in case it matters. Patients have multiple rows, both because they have multiple visits over time and because they might receive multiple diagnoses during the same visit. I would like to create an identifier for each visit for each person. This is "var1" in Mike Kim's post (link above).

I tried this:

Code:
bysort pid (date): generate int var1 = _n
But that gave me identifier numbers for each person from visit #1 to _n without assigning visits on the same date with the same number. Any advice would be much appreciated.

Thanks,
Robbie