Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Counting a population given start/end times
From
Scott Simpson <[email protected]>
To
[email protected]
Subject
st: Counting a population given start/end times
Date
Sat, 3 Nov 2012 12:51:20 -0700 (PDT)
Hi all-
First time posting, any help appreciated.
I have a data set that lists patients' clinic visits. Given each inidividual's time into the clinica and time out of the clinic, I am trying to create a variable that tells me how many patients are in the clinic at a given time. In essence, the clinic population at a given point in time, really, the clinic population at the point the patient arrives.
I thought I had it by counting the # of pts who had arrived before, then substracting those who left before--
sort DateandTimeIN;
gen inorder = _n;
gen inbefore = inorder - 1;
sort DateandTimeOUT;
gen outorder = _n if !missing(DateandTimeOUT);
gen leftbefore = outorder - 1;
sort DateandTimeIN;
gen currentpop = inbefore + 1 - leftbefore;
(Admittedly, there are some unaccounted patients already in clinic before my data starts, will have to manually figure that out and correct.) The output of the above, however, gives me a lot of negative numbers for currentpop, which does not make intuitive sense to me unless the recorded time is incorrect.
This seems as though would be a common programming question but am not finding answers among local experts or online. Must be a .do file out there for this?
best,
scott
Scott Simpson MD MPH
University of Washington School of Medicine
Seattle, WA
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/