I have longitudinal data (see dataex below). I need to censor each id according to a few conditions.
Condition 1: if within the same id, treatment = 2 occurs on the same date as treatment = 1, I need to use that treat_date as the censoring date.
Condition 2: if within the same id, there is a delay between treat_date >= x days for the same treatment, I need to censor at that date plus a specified add-on duration (say 10 days)
How do I look within each id to determine if these conditions occur?
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int id byte treatment float treat_date 11 1 20054 11 1 20102 11 1 20176 11 1 20209 11 1 20247 11 1 20332 11 2 20391 11 2 20519 11 2 20576 11 3 20434 11 3 20450 11 5 20585 11 5 20618 11 5 20630 11 5 20675 11 5 20746 12 1 19401 12 1 19403 12 1 19460 12 1 19797 12 2 19686 12 2 19716 12 3 19529 12 3 19539 12 3 19567 12 3 19627 12 3 19787 12 4 19849 12 4 19915 12 4 19922 12 4 19954 12 4 19973 12 4 20025 12 4 20112 12 4 20197 12 4 20225 12 4 20235 12 4 20278 12 4 20332 12 4 20352 12 4 20365 12 4 20401 12 4 20474 12 4 20546 12 4 20636 12 4 20709 12 4 20759 12 4 20761 12 5 19683 12 5 19749 12 5 19754 13 1 20420 13 1 20432 13 1 20496 13 1 20547 13 1 20577 13 1 20664 13 1 20695 13 1 20752 14 2 17348 14 2 17368 14 2 17828 14 2 17902 14 2 17916 14 2 18228 14 2 18270 14 2 18318 14 2 18377 14 2 18440 14 2 18467 14 2 18490 14 2 18542 14 3 17262 14 3 17319 14 3 17448 14 3 17453 14 3 17461 14 3 17494 14 3 17521 14 3 17598 14 3 17602 14 3 17663 14 3 17694 14 3 17732 14 3 17759 14 3 17918 14 3 18091 14 3 18169 14 4 18598 14 4 18688 14 4 18701 14 4 18746 14 4 18820 14 4 18899 14 4 18977 14 4 19064 14 4 19126 14 5 17990 14 5 18031 15 1 18241 end format %td treat_date
0 Response to Longitudinal data - generating variables dependent on observations within each subject
Post a Comment