hello! I am trying to write a loop to flag two criteria. First if the difference between lag(timeperiod) - timeperiod >=4 and then to compare if diag codes between time periods is the same of different. I want to run the loop over each patientID until one of these criteria's are met. TIA! E.g. data patientID, timeperiod, combined wh7,1, diag1_diag2_diag3 wh7, 4, diag1_diag2_diag3_diag4 wh7, 10, diag1_diag2 wh7 15, diag4_diag10 wh4, 2, diag5_diag11_diag16 wh4, 4, diag5_diag11
... View more