Dear community,
Note: I am using Stata14 on Mac (updated). I used dataex to show a small portion of my dataset below.
I am studying outcomes of eye surgery in sequential visits to the specialist. Each observation in the dataset is an eye that visited the hospital n times to be measured. The dates of such visits are recorded in vars date_postop_iop* , the measure acquired at each of those visits is in vars postop_iop*. I have also calculated the number of days elapsed from the surgery to the day of each visit is in vars postopdays*. Each of these variables corresponds to the others in their name and content (i.e. date_postop_iop1 is the date when the value in postop_iop1 was measured, and so on).
I need to find which value among vars postop_iop* are closest to 1 year from surgery or are within X days of being 1 year from surgery.
For this, I think I will need to generate a newvar named 1_year_iop that takes the value of whichever var postop_iop* is closest to 365 days or, is within n days of 365 after surgery.
I thought of using the command foreach to evaluate the condition, but I can‘t get it right.
I would welcome your suggestions of an appropriate way to do this.
Many thanks,
Alan Kastner.
Note: I am using Stata14 on Mac (updated). I used dataex to show a small portion of my dataset below.
I am studying outcomes of eye surgery in sequential visits to the specialist. Each observation in the dataset is an eye that visited the hospital n times to be measured. The dates of such visits are recorded in vars date_postop_iop* , the measure acquired at each of those visits is in vars postop_iop*. I have also calculated the number of days elapsed from the surgery to the day of each visit is in vars postopdays*. Each of these variables corresponds to the others in their name and content (i.e. date_postop_iop1 is the date when the value in postop_iop1 was measured, and so on).
I need to find which value among vars postop_iop* are closest to 1 year from surgery or are within X days of being 1 year from surgery.
For this, I think I will need to generate a newvar named 1_year_iop that takes the value of whichever var postop_iop* is closest to 365 days or, is within n days of 365 after surgery.
I thought of using the command foreach to evaluate the condition, but I can‘t get it right.
I would welcome your suggestions of an appropriate way to do this.
Many thanks,
Alan Kastner.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int(eye_id date_sx date_postop_iop1 date_postop_iop2 date_postop_iop3 date_postop_iop4 date_postop_iop5) byte(postop_iop1 postop_iop2 postop_iop3 postop_iop4 postop_iop5) float(postopdays1 postopdays2 postopdays3 postopdays4 postopdays5) 3 14927 14928 14935 14942 14949 14977 25 30 40 14 18 1 8 15 22 50 4 14941 14942 14943 14944 14949 14951 27 27 14 27 34 1 2 3 8 10 5 14941 14942 14956 14962 14993 15049 11 8 4 12 15 1 15 21 52 108 6 14955 14956 14962 14977 . . 24 12 8 . . 1 7 22 . . 7 14955 14956 14962 14983 15004 15032 10 6 4 8 8 1 7 28 49 77 8 14983 14984 14993 15005 15012 15025 10 17 20 12 12 1 10 22 29 42 9 14990 14991 14997 15011 15040 15091 7 4 9 8 10 1 7 21 50 101 11 14992 14993 14998 15026 15047 15082 21 10 5 8 9 1 6 34 55 90 15 15018 15019 15022 15023 15024 15025 30 32 21 19 20 1 4 5 6 7 16 15018 15019 15025 . . . 17 28 . . . 1 7 . . . end format %td date_sx format %td date_postop_iop1 format %td date_postop_iop2 format %td date_postop_iop3 format %td date_postop_iop4 format %td date_postop_iop5 label var eye_id "unique identifier" label var date_sx "date of surgery" label var date_postop_iop1 "date of visit 1" label var date_postop_iop2 "date of visit 2" label var date_postop_iop3 "date of visit 3" label var date_postop_iop4 "date of visit 4" label var date_postop_iop5 "date of visit 5" label var postop_iop1 "eye pressure value at visit 1" label var postop_iop2 "eye pressure value at visit 2" label var postop_iop3 "eye pressure value at visit 3" label var postop_iop4 "eye pressure value at visit 4" label var postop_iop5 "eye pressure value at visit 5" label var postopdays1 "days after surgery at visit 1" label var postopdays2 "days after surgery at visit 2" label var postopdays3 "days after surgery at visit 3" label var postopdays4 "days after surgery at visit 4" label var postopdays5 "days after surgery at visit 5"