Hi Statalist
I want to generate a variable that give the date for when you experience an event (q*dates*) and that this results in an inclusion (q*inclus* = 1). It is important that is the first date it happens in within a given range. My code that does not work completely is and does not encompass that they also have to be included on the day they experience an event:
I have 6 different variables named q*dates* and q*inclus*. Only included 2 down below.
I want to generate a variable that give the date for when you experience an event (q*dates*) and that this results in an inclusion (q*inclus* = 1). It is important that is the first date it happens in within a given range. My code that does not work completely is and does not encompass that they also have to be included on the day they experience an event:
Code:
gen green = .
forval j = 1/6 {
forval i = 1/6 {
replace green = min(gren, q`i'dates`j') if inrange(q`i'dates`j', mdy(1,11,2016), mdy(6,30,2017))
}
}
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input double q1dates1 long q1inclus1 double q2dates2 long q2inclus2
. . . .
20849 3 20850 1
20850 1 . .
20118 1 . .
20849 1 . .
20849 . . .
20849 1 . .
20849 . 20850 .
20849 1 . .
21579 1 . .
20849 1 . .
20849 . 20963 .
20849 . 20963 .
20483 1 . .
20850 1 . .
20849 . 20850 3
20850 . 20963 1
20849 . 20850 .
21214 1 . .
20850 1 . .
end
format %td_DD-NN-CCYY q1dates1
format %td_DD-NN-CCYY q2dates2

Comment