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]

From |
Scott Simpson <simpsons@uw.edu> |

To |
statalist@hsphsun2.harvard.edu |

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/

**Follow-Ups**:**Re: st: Counting a population given start/end times***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**Re: st: Double loop over unbalanced panel** - Next by Date:
**st: interpretation of sureg with no significant results** - Previous by thread:
**st: sigma_u is zero -xtregar-** - Next by thread:
**Re: st: Counting a population given start/end times** - Index(es):