Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



gen long obsno = _n
expand 2
bysort obsno : gen Time = cond(_n == 1, DateandTimeIN, DateandTimeOUT)
by obsno : gen Change = cond(_n == 1, 1, -1) if !missing(Time)
sort Time
gen sumChange = sum(Change)

On Sat, Nov 3, 2012 at 7:51 PM, Scott Simpson <simpsons@uw.edu> wrote:

> 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?
>

*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index