Can you help me program this algorithm that is giving me trouble?
I have a dataset (as the one I've attached) with patient ID and the difference in days between two dates, with a range of -21 to +7.
I need to identify patients who have two consecutive values of flag_KPI = 1 within the range [-21, 0).
If they have only one in the range [-21, 0), then I consider the case where they have two consecutive values of flag_KPI = 1, one in the window [-21, 0) and the other in the window [0, 7].