I take it the typical observation (case, record) is for
a patient's visit and includes -arrdt- and -dcdt-.
I think a loop may be needed _with this data structure_.
gen already = .
qui forval i = 1/`= _N' {
count if arrdt < arrdt[`i'] & dcdt > dcdt[`i']
replace already = r(N) in `i'
}
It is easier in a different data structure which
has two observations for every patient visit. Then
you create a score +1 for an arrival and -1 for a departure
and use -sum()- to get the number in the queue.
Subtract 1 to get -already-.
This different data structure could be got via
-reshape long-.
Other questions about timing would I think
always be easier in that data structure.
-search count- to find a reference to Stata Journal tutorials on
how useful -count- can be.
Nick
[email protected]
Steve Pitts
> I'm trying to work out how many patients are already present
> in an emergency
> department (a variable called "how_busy") for each member in
> a list of
> patients that includes the variables "arrival datetime" and
> "discharge
> datetime", i.e. I'd like to know how many patients preceding
> the index
> patient have dcdt > current arrdt in a list of visits sorted
> by arrdt. I'm
> no programmer and fairly new to Stata, and haven't been able
> to make it work
> using -forval- and -while- loops with explicit subscripting.
> Maybe there's a
> clever way to do this using -egen-?
>
> An alternative "how_busy" measure might be a count of all
> patients who were
> in the ED during any part of the index patient's visit (maybe
> it got busy
> later). I think this would need to be divided by length of
> stay. In any case
> for me: equally impossible, but maybe this is easy for someone else.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/