Hi everyone,
I have a dataset in long formate showing patients with their date of surgery and pain scores taken at postoperative visits (in no strict intervals). Then I got a variable (by the help of this forum) for pain remission which is == 1 if patients report a pain score of <=3 for any timeframe of >= 91.3125 days during their postoperative followup. Now I would like to know which patients are able to sustain that pain remission for the whole time of their follow up and which have a rebound to pain >3.
For that I tried creating variables which show the beginning and the end of that timeframe of pain remission and next I would try to combine them with the date of the last pain score reported (end of follow up) and then try to find out if there is anything >3 in between their timeframe of remission and the end of their followup. That is the code I started writing to find out the beginning and the end of that timeframe:
by record_number (time_surgerytopainscore), sort: ///
gen rem_start = time_surgerytopainscore[_N-1] if time_surgerytopainscore[_N] - time_surgerytopainscore[_N-1] >= 91.3125 & pain_remission == 1 & low_pain_score == 1 & score_pain_ <= 3
by record_number (time_surgerytopainscore), sort: ///
gen rem_stop = time_surgerytopainscore[_N] if time_surgerytopainscore[_N] - time_surgerytopainscore[_N-1] >= 91.3125 & pain_remission == 1 & low_pain_score == 1 & score_pain_ <= 3
I'm sure there is an easier way to do this, so I would appreciate any help!
Here is the post for the original detection of pain remission: https://www.statalist.org/forums/for...ions-in-a-loop
Example data:
I have a dataset in long formate showing patients with their date of surgery and pain scores taken at postoperative visits (in no strict intervals). Then I got a variable (by the help of this forum) for pain remission which is == 1 if patients report a pain score of <=3 for any timeframe of >= 91.3125 days during their postoperative followup. Now I would like to know which patients are able to sustain that pain remission for the whole time of their follow up and which have a rebound to pain >3.
For that I tried creating variables which show the beginning and the end of that timeframe of pain remission and next I would try to combine them with the date of the last pain score reported (end of follow up) and then try to find out if there is anything >3 in between their timeframe of remission and the end of their followup. That is the code I started writing to find out the beginning and the end of that timeframe:
by record_number (time_surgerytopainscore), sort: ///
gen rem_start = time_surgerytopainscore[_N-1] if time_surgerytopainscore[_N] - time_surgerytopainscore[_N-1] >= 91.3125 & pain_remission == 1 & low_pain_score == 1 & score_pain_ <= 3
by record_number (time_surgerytopainscore), sort: ///
gen rem_stop = time_surgerytopainscore[_N] if time_surgerytopainscore[_N] - time_surgerytopainscore[_N-1] >= 91.3125 & pain_remission == 1 & low_pain_score == 1 & score_pain_ <= 3
I'm sure there is an easier way to do this, so I would appreciate any help!
Here is the post for the original detection of pain remission: https://www.statalist.org/forums/for...ions-in-a-loop
Example data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int record_number str5 no_painscore byte score_pain_ float time_surgerytopainscore byte low_pain_score int run_num byte long_run float(pain_remission rem_start rem_stop) 113 "1" 3 1 1 1 0 1 9 106 113 "2" 2 2 1 1 0 1 9 106 113 "3" 2 3 1 1 0 1 9 106 113 "4" 2 4 1 1 0 1 9 106 113 "5" 3 5 1 1 0 1 9 106 113 "6" 4 6 0 2 0 1 . . 113 "7" 4 7 0 2 0 1 . . 113 "8" 1 8 1 3 1 1 9 106 113 "9" 2 9 1 3 1 1 9 106 113 "10" 3 106 1 3 1 1 9 106 834 "1" 7 1 0 1 0 1 . . 834 "2" 5 2 0 1 0 1 . . 834 "3" 7 3 0 1 0 1 . . 834 "4" 6 4 0 1 0 1 . . 834 "5" 6 5 0 1 0 1 . . 834 "6" 6 6 0 1 0 1 . . 834 "7" 5 7 0 1 0 1 . . 834 "8" 4 8 0 1 0 1 . . 834 "9" 6 17 0 1 0 1 . . 834 "10" 4 62 0 1 0 1 . . 834 "11" 0 83 1 2 1 1 83 216 834 "12" 1 216 1 2 1 1 83 216 920 "1" 7 1 0 1 1 0 . . 920 "2" 6 2 0 1 1 0 . . 920 "3" 6 1270 0 1 1 0 . . 911 "1" 4 1 0 1 0 0 . . 911 "2" 0 27 1 2 0 0 . . 911 "3" 1 69 1 2 0 0 . . 221 "1" 7 1 0 1 0 1 . . 221 "2" 8 6 0 1 0 1 . . 221 "3" 3 34 1 2 1 1 34 174 221 "4" 3 174 1 2 1 1 34 174 102 "1" 2 1 1 1 1 1 482 649 102 "2" 0 77 1 1 1 1 482 649 102 "3" 0 146 1 1 1 1 482 649 102 "4" 0 181 1 1 1 1 482 649 102 "5" 4 228 0 2 0 1 . . 102 "6" 0 229 1 3 1 1 482 649 102 "7" 0 230 1 3 1 1 482 649 102 "8" 1 231 1 3 1 1 482 649 102 "9" 2 232 1 3 1 1 482 649 102 "10" 0 233 1 3 1 1 482 649 102 "11" 0 234 1 3 1 1 482 649 102 "12" 0 235 1 3 1 1 482 649 102 "13" 0 236 1 3 1 1 482 649 102 "14" 0 286 1 3 1 1 482 649 102 "15" 1 391 1 3 1 1 482 649 102 "16" 0 482 1 3 1 1 482 649 102 "17" 6 649 0 4 0 1 . . 123 "1" 7 1 0 1 0 1 . . 123 "3" 8 3 0 1 0 1 . . 123 "4" 0 4 1 2 1 1 367 598 123 "5" 2 5 1 2 1 1 367 598 123 "6" 0 6 1 2 1 1 367 598 123 "7" 0 7 1 2 1 1 367 598 123 "8" 0 8 1 2 1 1 367 598 123 "9" 0 9 1 2 1 1 367 598 123 "10" 0 10 1 2 1 1 367 598 123 "11" 1 67 1 2 1 1 367 598 123 "13" 0 134 1 2 1 1 367 598 123 "12" 1 158 1 2 1 1 367 598 123 "2" 7 367 0 3 0 1 . . 123 "14" 1 598 1 4 0 1 367 598 end

Comment