Hello,

I have panel data with 1 to 10 events per patid. The eventdate is the date of the stroke and the stroke type is 0 if unspecified or 1 or 2 for specific types. I have ordered the data by patid and eventdate and generated strokeseq to put the events in time order for each patid.

My question is: For each patid where the first eventdate (strokeseq == 1) is zero (i.e. unspecified type) how do I calculate the number of days to the first stroke_type that is 1 or 2?

I am new to Stata so there may be an obvious answer but I have been unable to find one after extensive searching of the help files and previous questions. I can work the time difference out if stroke_type 1 or 2 is strokeseq == 2 but not if there are more unspecified events before (e.g. strokeseq 1 = 0, strokeseq 2 = 0, strokeseq3 = 1, strokeseq4 = 1), in this example I'm interested in the time between strokeseq1 and 3 only.

Many Thanks, Anneka

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long patid float eventdate2 byte stroke_type float strokeseq
342409 17338 0 1
342409 17351 0 2
342409 18327 2 3
343512 18431 1 1
343512 18431 1 2
344285 17721 1 1
344528 19131 0 1
344528 19215 1 2
349540 15762 0 1
349540 15762 1 2
end
format %td eventdate2
label values stroke_type lbl_stroketype
label def lbl_stroketype 0 "Unspecified", modify
label def lbl_stroketype 1 "Ischaemic", modify
label def lbl_stroketype 2 "Haemorrhagic", modify