Hi,

Data at hand: patient visit start and end dates/times, with each line representing a unique visit. A sample is below. The visits span from several hours to several days.

Question we're looking to answer: for each day, what proportion of patients who were there in the morning (0800) had left by the end of the day (2359).

The only set of steps that I can sketch in my brain (though not yet sure how to code it) would be to create two variables for each day to create flags to identify whether each observation was present at 0800 then if they had left by 2359, then somehow calculate proportions for each of these variables. Is there an easier way?

Thanks!

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(id obsbegin obsend)
 1 1.8619213e+12  1.861961e+12
 2  1.861922e+12 1.8620786e+12
 3  1.861923e+12 1.8619218e+12
 4 1.8619246e+12  1.861973e+12
 5  1.861929e+12  1.861966e+12
 6 1.8619295e+12 1.8619564e+12
 7 1.8619327e+12 1.8620413e+12
 8 1.8619335e+12 1.8619677e+12
 9  1.861934e+12 1.8619636e+12
10 1.8619395e+12 1.8619865e+12
11 1.8619415e+12 1.8619577e+12
12 1.8619433e+12 1.8619715e+12
13  1.861949e+12  1.861985e+12
14  1.861961e+12 1.8620724e+12
15  1.861965e+12 1.8619995e+12
16 1.8619742e+12 1.8619744e+12
17  1.861979e+12 1.8620514e+12
18  1.861987e+12  1.862078e+12
19 1.8619886e+12 1.8620075e+12
20  1.861995e+12  1.862071e+12
21 1.8619962e+12  1.862055e+12
22 1.8620012e+12  1.862016e+12
23 1.8620025e+12 1.8620584e+12
24  1.862021e+12 1.8620544e+12
25 1.8620255e+12 1.8620362e+12
end
format %tc obsbegin
format %tc obsend