Hello,
I'm using Stata 18 with the following data:
My PI is asking me to make a figure with these data that I can't figure out how to make (I'm not sure it is even possible to make). Specifically, she is asking for a spaghetti plot that would look something like what is generated with
But, she would like the sections of the lines for each individual color-coded according to the variable pre_therapy, and then she would like a marker to appear on the line for each individual to indicate where they began therapy (age_therapy_start). Pre_therapy is coded 1 if the visit/outcome measure was completed pre_therapy, and coded 0 if after initiating therapy.
I'm not sure how to even attempt to go about coloring different sections of the same line according to a binary variable, and I ran into trouble trying to overlay a scatter on a twoway line plot because my x variables aren't the same.
Any help would be greatly appreciated! Or if anyone can tell me that this is impossible, so I can tell her that..
Thanks,
Meghan
I'm using Stata 18 with the following data:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(pid VISIT age outcome pre_therapy age_therapy_start) 1 1 4.5863013 .2691433 1 6.02601 1 3 5.99726 -.13580847 1 6.02601 1 4 6.967124 -.5588566 0 6.02601 1 5 7.972678 -.29172885 0 6.02601 2 3 3.5561645 1.0334456 1 3.6084874 2 4 4.6748633 .13152725 0 3.6084874 3 1 4.210959 .5987669 1 5.68104 3 2 5.158904 .6081526 1 5.68104 3 3 5.621918 .7302112 1 5.68104 4 3 4.060109 .024490165 1 4.1122518 5 3 3.432877 1.504983 1 3.520876 6 2 3.238356 . 1 4.073922 6 3 4.0273223 -.972908 1 4.073922 6 4 5.00274 -1.3019816 0 4.073922 7 1 4.783562 .4694017 1 6.06434 7 2 5.780822 .07471675 1 6.06434 7 3 5.994521 .26519963 1 6.06434 7 4 7.013661 .23719777 0 6.06434 7 5 7.986339 .005793178 0 6.06434 8 1 4.783562 1.251511 1 6.06434 8 2 5.780822 .5124904 1 6.06434 8 3 5.994521 .7227523 1 6.06434 8 4 7.013661 .8358337 0 6.06434 8 5 7.986339 .5839239 0 6.06434 9 3 5.361644 -.4420079 1 5.423682 9 4 6.434426 -.7953085 0 5.423682 10 3 3.204918 -1.5974298 1 3.233402 10 4 4.347945 -.8368508 0 3.233402 11 1 3.457534 1.2626574 1 . 11 2 4.5342464 . 1 . end
Code:
xtline outcome, t(age) i(pid) overlay legend(off)
I'm not sure how to even attempt to go about coloring different sections of the same line according to a binary variable, and I ran into trouble trying to overlay a scatter on a twoway line plot because my x variables aren't the same.
Any help would be greatly appreciated! Or if anyone can tell me that this is impossible, so I can tell her that..

Thanks,
Meghan
Comment