I am using Stata 12 on Windows 8.1. I would like to create the variable seq in the sample data below. For each date, the sequence should be the same, 1 for the first date, 2 for the second date, etc for each ptid. The sequence should start over with each new ptid. i have tried generating seq with egen and grouping ptid and date, but the sequence does not start over with ptid and by can't be used with egen in version 12. What would be the best way to create seq?
ptid date seq
1 01/01/2016 1
1 01/01/2016 1
1 01/02/2016 2
1 01/02/2016 2
2 02/01/2016 1
2 02/01/2016 1
2 02/02/2016 2
2 02/02/2016 2
2 03/01/2016 3
2 03/01/2016 3
2 03/01/2016 3
3 04/01/2016 1
3 04/02/2016 1
ptid date seq
1 01/01/2016 1
1 01/01/2016 1
1 01/02/2016 2
1 01/02/2016 2
2 02/01/2016 1
2 02/01/2016 1
2 02/02/2016 2
2 02/02/2016 2
2 03/01/2016 3
2 03/01/2016 3
2 03/01/2016 3
3 04/01/2016 1
3 04/02/2016 1
Comment