Bookmark and Share

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: Generating a Count Variable of Number of Obs in a Time Interval Preceding the Current Obs


From   David Feinswog <[email protected]>
To   [email protected]
Subject   st: Generating a Count Variable of Number of Obs in a Time Interval Preceding the Current Obs
Date   Tue, 19 Nov 2013 12:27:03 +0000

I am working with Emergency Medical Services (EMS) ambulance call data
using Stata/IC 12.  The variables of consequence are:

1. timecreate: the time when the 911 dispatcher first received the 911
call
2. timedispatch: the time when the 911 dispatcher sent an EMS resource
(i.e. ambulance) to the location
3. timeclose: the time when the EMS resource cleared from the call and
returned to service
* if it matters, times are formatted %tc

I am trying to capture a measure of EMS system use load.
Specifically, I need to generate a count of all open calls when a call
came in.  For simplicity, I am going to keep things simple for now and
disregard "timeclose".  I will try to capture ALL CALLS DISPATCHED IN
THE 53 MINUTES (average call duration) PRIOR TO EACH "timecreate" OBS.


The simple attempt using egen:

egen countcall= count(timedispatch<= timecreate[_n] & timedispatch
+53<= timecreate[_n])

This returned _N for each observation.


Attempt using foreach loops:

gen countcall=o

*using a limited numlist (1/20 vs 1/_N) to speed things up while I
figure out the appropriate coding

foreach obs of numlist 1/20 {
sum timecreate if _n==`obs'
local time1=r(mean)
gen dum1=1 if timedispatch<= `time1' & timedispatch<= `time1'-53
egen dum2=total(dum1)
replace countcall=dum2 if _n==`obs'
drop dum*
}

This returned _n for each obs in the specified numlist 1/20

Please let me know if there is any additional information that could
help.

Best,
David Feinswog
Economics, Tulane University
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index