Hello,

I am having an issue getting my data coded properly. I have a dataset of patients with encounter dates. Each patient can have many rows of encounters and one or more encounters per date(long). I am trying to create a variable that indicates the order of the encoutners by date and labels each unqiue date 1,2,3.... The issue I cannot resolve is that for patients who have mulitple rows(encounters) for the same date, I want this indicated with the same number. This dataset is quite large and many vairables other than displayed.

So far i have done (which is not working):

bysort ID visit_date: generate datevisit_count1 = _n
bysort ID visit_date: generate datevisit_count2 = _N
bysort ID : generate datevisit_count3 = _N

I am trying to get the data to display such as i have input for column 6 (What I am trying to accomplish).

Any help would be appreciated.

Thank you,

Maggie

ID visit_date datevisit_count1 datevisit_count2 datevisit_count3 What I am trying to accomplish
1 11/23/2015 1 1 23 1
1 1/3/2016 2 1 23 2
1 1/4/2016 3 1 23 3
1 1/14/2016 4 1 23 4
1 1/23/2016 5 1 23 5
1 1/27/2016 6 1 23 6
1 1/29/2016 7 1 23 7
1 2/2/2016 8 2 23 8
1 2/2/2016 9 2 23 8
1 2/16/2016 10 1 23 9
1 2/25/2016 11 1 23 10
1 5/7/2016 12 1 23 11
1 5/15/2016 13 1 23 12
1 6/2/2016 14 1 23 13
1 6/13/2016 15 1 23 14
1 6/14/2016 16 1 23 15
1 6/17/2016 17 1 23 16
1 6/28/2016 18 1 23 17
1 7/5/2016 19 1 23 18
1 7/13/2016 20 1 23 19
1 7/27/2016 21 1 23 20
1 8/2/2016 22 1 23 21
1 11/14/2016 23 1 23 22