Hello,
I am trying to add vertical reference bars to a series of graphs plotted using xtline. I have a time-dependent variable, time_var, plotted versus day for individuals identified by id. I have been able to plot these in separate panels for each id using the following code:
xtline time_var, t(day) i(id)
I would like to add a vertical reference bar to each panel that is different for each id so that I can mark the time when an event occurs, event_day. For example, based on the data below, there should be a vertical line at x = 2 for id#2 and at x = 1 for id#3, but no vertical line for id#1.
I'm able to generate fixed reference lines that appear in all panels by using xline(), but I haven't been able to figure out how to set the placement of these lines equal to event_day. (xline(event_day) does not work...)
Should I reshape the data back to wide? Or is there a better command for what I'm trying to do?
Thank you!
I am trying to add vertical reference bars to a series of graphs plotted using xtline. I have a time-dependent variable, time_var, plotted versus day for individuals identified by id. I have been able to plot these in separate panels for each id using the following code:
xtline time_var, t(day) i(id)
I would like to add a vertical reference bar to each panel that is different for each id so that I can mark the time when an event occurs, event_day. For example, based on the data below, there should be a vertical line at x = 2 for id#2 and at x = 1 for id#3, but no vertical line for id#1.
I'm able to generate fixed reference lines that appear in all panels by using xline(), but I haven't been able to figure out how to set the placement of these lines equal to event_day. (xline(event_day) does not work...)
Should I reshape the data back to wide? Or is there a better command for what I'm trying to do?
Thank you!
id | time_var | day | event_day |
1 | 5 | 1 | . |
1 | 6 | 2 | . |
2 | 34 | 1 | 2 |
2 | 50 | 2 | 2 |
2 | 60 | 3 | 2 |
3 | 2 | 1 | 1 |
3 | 2 | 2 | 1 |
Comment