Dear Statalist members,
I have monthly data listing case id, month, and incidence of an event. Sometimes an event spans across two months, as in events 1 and 3 below:
I would like to create a variable like -back- below, which indicates the number of months it takes for the value of -score- to be greater than or equal to the value recorded in the month before each event. Worth noting is the fact that sometimes the lower value only happens in the second month of an event that spans across two months (eg id == 2 & event == 3).
Thanks in advance for any help you can provide!
I have monthly data listing case id, month, and incidence of an event. Sometimes an event spans across two months, as in events 1 and 3 below:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(id month) float event int score 1 1 . 100 1 2 . 100 1 3 1 90 1 4 1 90 1 5 . 110 1 6 . 120 1 7 . 140 1 8 2 140 1 9 . 150 1 10 3 160 1 11 3 170 1 12 . 160 2 1 . 90 2 2 . 100 2 3 1 90 2 4 1 100 2 5 . 110 2 6 . 110 2 7 . 120 2 8 2 110 2 9 . 100 2 10 3 120 2 11 3 90 2 12 . 100 3 1 . 100 3 2 . 120 3 3 1 100 3 4 1 90 3 5 . 80 3 6 . 120 3 7 . 130 3 8 2 120 3 9 . 130 3 10 3 140 3 11 3 130 3 12 . 140 end
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(id month) float event int score byte back 1 1 . 100 . 1 2 . 100 . 1 3 1 90 3 1 4 1 90 3 1 5 . 110 . 1 6 . 120 . 1 7 . 140 . 1 8 2 140 0 1 9 . 150 . 1 10 3 160 0 1 11 3 170 0 1 12 . 160 . 2 1 . 90 . 2 2 . 100 . 2 3 1 90 2 2 4 1 100 2 2 5 . 110 . 2 6 . 110 . 2 7 . 120 . 2 8 2 110 3 2 9 . 100 . 2 10 3 120 3 2 11 3 90 3 2 12 . 100 . 3 1 . 100 . 3 2 . 120 . 3 3 1 100 4 3 4 1 90 4 3 5 . 80 . 3 6 . 120 . 3 7 . 130 . 3 8 2 120 2 3 9 . 130 . 3 10 3 140 0 3 11 3 130 0 3 12 . 140 . end

Comment