I need some help (code) finding a solution for the following problem:
I have a longitudinal dataset with a variable number of visits for each patient (id). I want to compare different outcomes the first time an event occurs (kostvejl == 1) with the patient’s previous visit. How do I generate a variable that identifies (tags) the first observation where the event occurs (ie “after”) AND the previous observation (ie “before”) for each id - no matter if the event occurs again or not?
Thanks in advance!
id kostvejl visit
2 0 1
2 0 0
2 0 2
2 1 3
5 0 1
5 0 2
5 0 3
5 0 0
5 1 4
6 0 0
6 0 1
6 1 2
8 0 3
8 0 1
8 0 0
8 1 2
I have a longitudinal dataset with a variable number of visits for each patient (id). I want to compare different outcomes the first time an event occurs (kostvejl == 1) with the patient’s previous visit. How do I generate a variable that identifies (tags) the first observation where the event occurs (ie “after”) AND the previous observation (ie “before”) for each id - no matter if the event occurs again or not?
Thanks in advance!
id kostvejl visit
2 0 1
2 0 0
2 0 2
2 1 3
5 0 1
5 0 2
5 0 3
5 0 0
5 1 4
6 0 0
6 0 1
6 1 2
8 0 3
8 0 1
8 0 0
8 1 2
Comment