Dear Statalisters,


I intend to analyse panel data (long format) on the effects of individuals taking a particular food item containing "FO" over time on blood sugar as part
of my dissertation.

I am interested in computing the incidence rates of the second occurrence of a high fasting blood sugar [FBS_cat =3 (>126mg/dl)]. Of note is that a series of FBS tests were
done in clients at different times. However I would like to restrict my analysis to individuals with first high FBS followed by a normal FBS [ FBS_cat ==1(<100mg/dl)] .

My aim and to conduct survival analysis for clients with a second high FBS (rebound) from the time it was recorded as normal [ FBS_cat ==1(<100mg/dl)] .


Step 1:
WITHIN A PANEL:
1. How do I only keep individuals who had a first high FBS [FBS_cat =3 (>126mg/dl)] followed by a normal FBS [ FBS_cat ==1(<100mg/dl)] ?
2 How do I exclude observations with subsequent high FBS [FBS_cat =3 (>126mg/dl)] in those with high FBS after the second?

Step 2:
WITHIN A PANEL:
3. How do I also keep the highest FBS lab test date if normal FBS [ FBS_cat ==1(<100mg/dl)] is maintained after first high FBS?
4. How do I also keep the FBS lab test date for the second high FBS for those with rebound?


My goal is to clean the dataset to achieve censoring dates for each client and this would help me calculate the pyrs of follow-up. also i intend to generate a
dichotomous outcome variable of high FBS rebound (yes/no). With this I can conduct Kaplan meir survival analysis )including cox proportional hazard regression modelling)

Information on the start date and end dates are given for food item "FO" for each individual. However,
the a series of lab tests (FBS_cat) were taken between each start and end of each food item.And the FBS test date


Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str12 id_patient str6 Food_item long(Food_start_date Food_end_date) float FBS_cat long FBS_test_date "05-602075" "FO" 20108 21202 1 20248 "05-602075" "FO" 20108 21202 1 20615 "05-602075" "FO" 20108 21202 2 21062 "05-602075" "FO" 20108 21202 2 21090 "05-602075" "FO" 20108 21202 1 21146 "05-603889" "FO" 20370 21434 1 20496 "05-603889" "FO" 20370 21434 1 21077 "05-603889" "FO" 20370 21434 1 21406 "05-61271" "FO" 20418 20905 2 20613 "05-61271" "FO" 20418 20905 1 20761 "05-61271" "FO" 20418 20905 1 20873 "05-61788" "FO" 20360 21419 3 20360 "05-61788" "FO" 20360 21419 1 20472 "05-61788" "FO" 20360 21419 3 20668 "05-61788" "FO" 20360 21419 1 20836 "05-61788" "FO" 20360 21419 1 20948 "05-61788" "FO" 20360 21419 1 21335 "05-619584" "FO" 20214 . 1 20289 "05-619584" "FO" 20214 . 3 20660 "05-619584" "FO" 20214 . 1 20772 "05-619584" "FO" 20214 . 1 21094 "05-619584" "FO" 20214 . 1 21447 "05-620831" "FO" 20426 21452 3 20426 "05-620831" "FO" 20426 21452 1 20499 "05-620831" "FO" 20426 21452 1 20779 "05-620831" "FO" 20426 21452 1 21143 "05-620831" "FO" 20426 21452 1 21423 "05-626996" "FO" 20270 20382 1 20326 "05-628103" "FO" 20380 20492 3 20380 "05-629098" "FO" 20303 . 1 20471 "05-629098" "FO" 20303 . 1 20835 "05-629098" "FO" 20303 . 1 21199 "05-629675" "FO" 20340 20741 1 20482 "05-629675" "FO" 20340 20741 1 20692 "05-633221" "FO" 20116 20118 . . "05-633221" "FO" 20118 20285 1 20250 "05-633221" "FO" 20285 20369 . . "05-633649" "FO" 20243 20250 . . "05-633649" "FO" 20271 21453 1 20404 "05-633649" "FO" 20271 21453 3 20768 "05-633649" "FO" 20271 21453 1 20907 "05-633649" "FO" 20271 21453 1 21132 "05-637006" "FO" 20209 21441 1 20209 "05-637006" "FO" 20209 21441 1 20485 "05-637006" "FO" 20209 21441 1 20629 "05-637006" "FO" 20209 21441 1 20776 "05-637006" "FO" 20209 21441 1 21048 "05-637006" "FO" 20209 21441 1 21378 "05-638065" "FO" 20151 20172 1 20151 "05-638065" "FO" 20172 . 1 20261 "05-638065" "FO" 20172 . 1 20500 "05-638065" "FO" 20172 . 1 20744 "05-638065" "FO" 20172 . 3 20856 "05-638065" "FO" 20172 . 1 20983 "05-638065" "FO" 20172 . 1 21222 "05-643474" "FO" 20368 . 1 20396 "05-643474" "FO" 20368 . 3 20737 "05-643474" "FO" 20368 . 1 20782 "05-643474" "FO" 20368 . 1 21136 "05-643702" "FO" 20234 21353 1 20395 "05-643702" "FO" 20234 21353 2 20779 "05-643702" "FO" 20234 21353 1 20975 "05-643702" "FO" 20234 21353 1 21129 "05-644578" "FO" 20220 . 1 20388 "05-644578" "FO" 20220 . 1 20724 "05-644578" "FO" 20220 . 1 21088 "05-644578" "FO" 20220 . 3 21446 "05-645074" "FO" 20171 20178 . . "05-650681" "FO" 20194 20195 . . "05-650681" "FO" 20195 20223 3 20223 "05-650681" "FO" 20223 20635 3 20223 "05-650681" "FO" 20223 20635 3 20384 "05-650681" "FO" 20223 20635 3 20461 "05-650681" "FO" 20223 20635 3 20489 "05-650681" "FO" 20223 20635 3 20517 "05-652122" "FO" 20312 20395 . . "05-65390" "FO" 20163 20311 1 20254 "05-65390" "FO" 20311 . 2 20339 "05-65390" "FO" 20311 . 1 20473 "05-65390" "FO" 20311 . 1 20718 "05-65390" "FO" 20311 . 2 20886 "05-65390" "FO" 20311 . 1 20998 "05-65390" "FO" 20311 . 2 21306 "05-65390" "FO" 20311 . 2 21425 "05-654580" "FO" 20142 20870 1 20282 "05-654580" "FO" 20142 20870 1 20646 "05-654580" "FO" 20870 . 1 21013 "05-654580" "FO" 20870 . 1 21374 "05-654657" "FO" 20404 20516 1 20488 "05-654657" "FO" 20516 . 1 20712 "05-654657" "FO" 20516 . 1 21076 "05-654657" "FO" 20516 . 1 21195 "05-654657" "FO" 20516 . 1 21468 "05-65706" "FO" 20135 20285 3 20163 "05-65706" "FO" 20135 20285 1 20256 "05-65706" "FO" 20285 20849 3 20677 "05-65706" "FO" 20285 20849 1 20761 "05-663008" "FO" 20333 20494 . . "05-666606" "FO" 20117 . 1 20179 "05-666606" "FO" 20117 . 1 20179 end format %d Food_start_date format %d Food_end_date format %d test_date label values FBS_cat FBS_cat label def FBS_cat 1 "<100 mg/dl", modify label def FBS_cat 2 "100-125 mg/dl", modify label def FBS_cat 3 ">126 mg/dl", modify [/CODE]