I have panel data with an id variable for each person, I want to generate a subgroup identifier based on consecutive number of days. Based on the dataex given at the end, I'd like to have a variable that gives:
id drug day period
1 1 1 1
1 1 2 1
1 1 3 1
1 1 4 1
1 1 5 1
1 1 8 2
1 1 9 2
1 1 10 2
1 1 13 3
1 1 14 3

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int id byte drug float days
1 1 1
1 1 2
1 1 3
1 1 4
1 1 5
1 1 8
1 1 9
1 1 10
1 1 13
1 1 14
1 1 15
1 1 16
2 1 1
2 1 2
2 1 3
2 1 4
2 1 5
2 1 6
2 1 7
2 1 8
2 1 24
2 1 25
2 1 26
2 1 31
2 1 32
2 1 33
2 1 34
2 1 41
2 1 42
2 1 44
2 1 45
2 1 46
2 1 47
2 1 48
2 1 49
2 1 50
2 1 51
2 1 52
2 1 53
2 1 54
2 1 55
2 1 56
2 1 57
2 1 60
2 1 61
2 1 62
3 1 1
3 1 2
3 1 3
3 1 4
3 1 5
3 1 6
3 1 7
3 1 8
3 1 9
3 1 10
3 1 11
3 1 12
3 1 13
3 1 14
3 1 15
3 1 16
3 1 21
3 1 22
4 1 1
4 1 2
4 1 3
4 1 4
5 1 1
7 1 1
7 1 2
7 1 3
7 1 4
7 1 5
7 1 6
7 1 7
7 1 8
7 1 9
7 1 10
7 1 45
7 1 46
7 1 47
7 1 48
7 1 49
7 1 50
7 1 51
7 1 52
7 1 53
7 1 54
7 1 65
7 1 66
7 1 71
7 1 72
7 1 73
7 1 74
7 1 75
7 1 76
7 1 77
7 1 78
9 1 1
end