Dear stata list,
I'm trying to use sankey diagram to show the flow of treatment sequence in a large population of patients. The issue I'm struggling with is that not all patients would switch from treatment A to tratment B, some of them would remain on treatment A. In the example data I provided below, individual 1 remained on same treatment i.e. source is A and destination is A . I created a binary variable to indicate whether an individual switch to another line of treatment (nswitch=0) or remain on treatment (nswitch=1) i.e. for individual 1, nswitch=1. I added this variable (nswitch) as an option to include only those who switched. Clinically, it doesn't make sense to show that a patient switch to the same treatment but it is impoortant to show how many individuals remain on a particular treatment as well as when they switched to different treatment. Below is an example of data in which "value" represents the total number of individuals on a particular drug for each line of therapy.
// create example data
clear
input studyno drugid layer value str20 source str20 destination nswitch
1 1 1 1458 "A" "A" 1
2 4 1 5443 "B" "C" 0
2 52 2 1033 "C" "D" 0
2 1449 3 420 "D" "D" 1
3 4 1 5443 "B" "E" 0
3 53 2 759 "E" "E" 1
4 1449 1 3625 "D" "F" 0
4 1449 2 860 "F" "F" 1
5 4 1 5443 "B" "D" 0
5 1449 2 1672 "D" "F" 0
5 41 3 500 "F" "F" 1
5 41 3 500 "F" "F" 1
6 4 1 5443 "B" "B" 1
6 4 1 5443 "B" "F" 0
6 41 2 860 "F" "F" 1
6 41 2 860 "F" "F" 1
end
label variable layer "Line of therapy"
label variable value "number of individuals per each layer"
label variable source "starting on treatment"
label variable destination "switching to treatment"
label variable nswitch "switchers; 0=switched to another treatment 1=remained on treatment"
ssc install sankey, replace
net install sankey, from("https://raw.githubusercontent.com/asjadnaqvi/stata-sankey/main/installation/") replace
ssc install palettes, replace
ssc install colrspace, replace
ssc install schemepack, replace
set scheme white_tableau
graph set window fontface "Arial Narrow"
sankey value if nswitch==0, ///
from(source) to(destination) by(layer) sortby(value) colorby(layer) ///
smooth(6) gap(40) recenter(top) novalues boxwid(5) ///
xsize(1.0) ysize(1) labs(1.6) laba(0) labpos(3) lc(white) lw(0.1) offset(5) ///
subtitle("", size(3))
Any help/advice oh how to deal with those who remained on treatment would be much appreciated. Thank you
I'm trying to use sankey diagram to show the flow of treatment sequence in a large population of patients. The issue I'm struggling with is that not all patients would switch from treatment A to tratment B, some of them would remain on treatment A. In the example data I provided below, individual 1 remained on same treatment i.e. source is A and destination is A . I created a binary variable to indicate whether an individual switch to another line of treatment (nswitch=0) or remain on treatment (nswitch=1) i.e. for individual 1, nswitch=1. I added this variable (nswitch) as an option to include only those who switched. Clinically, it doesn't make sense to show that a patient switch to the same treatment but it is impoortant to show how many individuals remain on a particular treatment as well as when they switched to different treatment. Below is an example of data in which "value" represents the total number of individuals on a particular drug for each line of therapy.
// create example data
clear
input studyno drugid layer value str20 source str20 destination nswitch
1 1 1 1458 "A" "A" 1
2 4 1 5443 "B" "C" 0
2 52 2 1033 "C" "D" 0
2 1449 3 420 "D" "D" 1
3 4 1 5443 "B" "E" 0
3 53 2 759 "E" "E" 1
4 1449 1 3625 "D" "F" 0
4 1449 2 860 "F" "F" 1
5 4 1 5443 "B" "D" 0
5 1449 2 1672 "D" "F" 0
5 41 3 500 "F" "F" 1
5 41 3 500 "F" "F" 1
6 4 1 5443 "B" "B" 1
6 4 1 5443 "B" "F" 0
6 41 2 860 "F" "F" 1
6 41 2 860 "F" "F" 1
end
label variable layer "Line of therapy"
label variable value "number of individuals per each layer"
label variable source "starting on treatment"
label variable destination "switching to treatment"
label variable nswitch "switchers; 0=switched to another treatment 1=remained on treatment"
ssc install sankey, replace
net install sankey, from("https://raw.githubusercontent.com/asjadnaqvi/stata-sankey/main/installation/") replace
ssc install palettes, replace
ssc install colrspace, replace
ssc install schemepack, replace
set scheme white_tableau
graph set window fontface "Arial Narrow"
sankey value if nswitch==0, ///
from(source) to(destination) by(layer) sortby(value) colorby(layer) ///
smooth(6) gap(40) recenter(top) novalues boxwid(5) ///
xsize(1.0) ysize(1) labs(1.6) laba(0) labpos(3) lc(white) lw(0.1) offset(5) ///
subtitle("", size(3))
Any help/advice oh how to deal with those who remained on treatment would be much appreciated. Thank you
Comment