Hi All,
I suspect I can't do what I am trying to do but thought it best to ask before I give up.
I am trying to track peoples status over time. Each person has date1 (their starting date), date2 (an event) and date3 (their stop date) end (a cut off date).
I want to create a longitudinal plot that shows how much data we have before the "cut off".
For some people, they will leave before the "cut off", for some they will leave after and I would like to colour code the time before and after the "cut off" accordingly.
I have attached some example code for what I have tried so far.
EXAMPLE CODE 1
Visually, the shape is what I am looking for, however rather than have each line a different colour, I would want the following:
between date1 & date2 (green)
between date2 & date3 (yellow)
unless anything after the "cut off" (red)
EXAMPLE CODE 2
To achieve the above I have reformatted the time points so that they can be reliably colour coded [(time1-time2(green), time2-time3(yellow), time3-time4(red)], however I am unsure where to go from here!
Any help is appreciated!
Best wishes,
Cydney
I suspect I can't do what I am trying to do but thought it best to ask before I give up.
I am trying to track peoples status over time. Each person has date1 (their starting date), date2 (an event) and date3 (their stop date) end (a cut off date).
I want to create a longitudinal plot that shows how much data we have before the "cut off".
For some people, they will leave before the "cut off", for some they will leave after and I would like to colour code the time before and after the "cut off" accordingly.
I have attached some example code for what I have tried so far.
EXAMPLE CODE 1
Visually, the shape is what I am looking for, however rather than have each line a different colour, I would want the following:
between date1 & date2 (green)
between date2 & date3 (yellow)
unless anything after the "cut off" (red)
EXAMPLE CODE 2
To achieve the above I have reformatted the time points so that they can be reliably colour coded [(time1-time2(green), time2-time3(yellow), time3-time4(red)], however I am unsure where to go from here!
Any help is appreciated!
Best wishes,
Cydney
Code:
/* EXAMPLE PART 1 */ clear set obs 500 gen date1 = floor((mdy(12,31,2006)-mdy(12,1,2000)+1)*runiform() + mdy(12,1,2000)) gen date2 = date1 + floor(runiform()*365) gen date3 = date1 + 365 gen end = td(01jun2005) sort date1 gen N = _n format date1 date2 date3 end %td preserve reshape long date, i(N) j(time) xtline N, i(N) t(date) overlay legend(off) addplot(line N end) /* EXAMPLE PART 2 */ restore gen time1 = date1 gen time2 = . replace time2 = date2 if date2 < end replace time2 = end if date2 > end gen time3 = . replace time3 = date3 if date3 < end replace time3 = end if date3 > end gen time4 = . replace time4 = date3 if date3 < end replace time4 = date3 if date3 > end format time* %td
Comment