Hi Everyone,

I am working with a datset that has following variables:

1) mrn: unique identifier
2) l1 : treatment line
3) combo_name: unique combination of drugs

I am interested in generating a patient flow diagram if possible from this data.

To clarify, a patient (mrn) moves from one line of treatment to another. So an mrn moves from l1 == 3 to l1 ==4 to l1==5. For example, mrn 513168 moved from combo_17 to combo_80 when it moved from l1==3 to l1 ==4.

I would like to know the frequency of patients that moves from combo_x to combo_y when they moved down a treatment line. So I will like to generate a table like following:
L1 == 3 Frequency L1 == 4 Frequency L1 == 5 Frequency L1 ==6 Frequency L1 ==7
17 80 90 17 80
74 66 21 35 68
21 33 61 99 104
I would like to do so for any flow possible across lines. Any help would be great. Thanks!
Anindit Chhibber

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long mrn byte l1 float combo_name
 513168 3  17
 513168 4  80
1094887 3  74
1248087 3  74
1978535 3  80
1978535 4  72
1978535 5  37
1978535 6  50
2167534 3  14
2167534 4  31
2167534 5  80
2414191 3  74
2547115 3  10
2547115 4  50
2547115 5  47
2547115 6  55
3190469 3  80
3756996 3  38
3756996 4  17
3756996 5  80
3877198 3  73
3877198 4  80
3877198 5  87
3877198 6  60
3936622 3  78
4160321 3  72
4231270 3  83
4272878 3  80
4272878 4  17
4272878 5  60
4272878 6  31
4272878 7  50
4299731 3  63
4733234 3  10
4733234 4  17
4733234 5  72
4983425 3  43
4983425 4  74
4983425 5  60
4983425 6  50
4983425 7   6
4983425 8  35
5041702 3  17
5041702 4  90
5041702 5  72
5041702 6  59
5157409 3  11
5746698 1   .
5783717 3  55
6321418 3  10
6321418 4  50
6565014 3  25
6565014 4  74
6565014 5  65
6662902 3  65
6662902 4  59
6670822 3  19
6699946 3  17
6699946 4  72
6733562 3  80
6733562 4  72
6733562 5  60
6733562 6  18
6733562 7  50
7383193 3  74
7388762 3  50
7388762 4  47
7388762 5  31
7388762 6  16
7536212 1   .
7857667 3  42
7898976 3  75
7898976 4  56
7970247 3  10
8015810 3  89
8015810 4  65
8088858 3  10
8162430 3  10
8162430 4  80
8495798 3  20
8598344 3  74
8598344 4  50
8845307 3  10
8845307 4  76
8849788 3  82
9179607 3  81
9179607 4  50
9281544 3 100
9281544 4 103
9281544 5 101
9281544 6 104
9342528 1   .
9441395 3  45
9441395 4  84
9555525 3  10
9555525 4  50
9569427 3  44
9653205 3  90
9653205 4  31
9653205 5  49
end