I have a dataset
~2000 patients are sampled weekly for 18 months and get a positive or negative results (or something indeterminate)
each patient has a single row the columns are the results or test at each week
I would like a column at the end that contains the column when the test result first goes from positive to negative
e.g. week 1 2 3 4 5 6 7 8 ......
patient 1 pos pos pos neg neg pos neg neg ...
Patient 2 pos pos pos pos pos pos neg neg ...
so the column at the end would say patient 1 became negative at week 4 patient 2 became negative at week 7
I would then like another column which states when a patient has two consecutive negative tests, e.g. patient 1 has 2 negatives from week 4, so the value in the column would be week 4, and patient 2 would be week 7
I will then use this to create Kaplan Meier plots
Can anyone help?