Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Need Help with Stata Programming |
Date | Thu, 21 Nov 2013 15:12:49 +0000 |
In that case, date of event for each patient is egen date_of_event = total(event * date), by(patientid) or egen date_of_event = mean(date / event), by(patientid) There are other ways to get it too, but two is more than you need. You may need to spread the information to all observations for each patient. Nick njcoxstata@gmail.com On 21 November 2013 15:04, Michael Stewart <michaelstewartresearch@gmail.com> wrote: > Hello Nick. > > I apologize that I missed your question. > Yes it is true that the event can only happen once for a patient. > Thanks , always for your help and useful articles/references. > > On Thu, Nov 21, 2013 at 9:59 AM, Nick Cox <njcoxstata@gmail.com> wrote: >> What you report as the difficulty is explained in detail in the paper >> already cited >> >> SJ-7-3 pr0033 . . . . . . . . . . . . . . Stata tip 51: Events in intervals >> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox >> Q3/07 SJ 7(3):440--443 (no commands) >> tip for counting or summarizing irregularly spaced >> events in intervals >> >> which is accessible at http://www.stata-journal.com/sjpdf.html?articlenum=pr0033 >> >> In short, you need an condition on the dates that enter in the >> calculation. It is convenient, but not essential, to use -inrange()-, >> e.g. >> >> ... inrange(date, <date of event> + 1, <date of event> + 60) >> >> ... inrange(date, <date of event> - 60, <date of event> - 1) >> >> where naturally you need to fill in <date of event>. >> >> You haven't answered my question about whether the event occurs at >> most once for each patient. Regardless, the date of the last event can >> always be found by >> >> gen date_of_event = date if event >> >> bysort patientid (date) : replace date_of_event = date_of_event[_n-1] >> if missing(date_of_event) >> >> and the date of the next event can be calculated using the time >> reversal method discussed in >> >> http://www.stata.com/support/faqs/data-management/replacing-missing-values/ >> >> Nick >> njcoxstata@gmail.com >> >> >> On 21 November 2013 03:38, Michael Stewart >> <michaelstewartresearch@gmail.com> wrote: >>> Dear Nick , >>> >>> Thank you very much for the advice .I looked at the prior code, your >>> reference(took a print out) and read it and tried to solve the problem >>> at hand. >>> >>> >>> My Goal : >>> 1)Count number of admissions(i.e., admit_type==IP) 60 days before the >>> event(i.e., event==1) OR 60 days after the event(i.e., event==1). >>> 2)Sum up the cost of the admissions (i.e., admit_type==IP) 60 days >>> before the event(i.e., event==1) OR 60 days after the event(i.e., >>> event==1). >>> >>> I am trying to solve the problem with hints amd have been stuck up here >>> >>> *************************************************************************** >>> gen NUM_IP_PRIOR=. >>> >>> qui forvalues i=1/`=_N'{ >>> sum admit_type if admit_type==IP & Pt_id==Pt_id[`i'] >>> replace NUM_IP_PRIOR=r(N) in `i' >>> } >>> ************************************************************************* >>> >>> I am able to get number of IP (inpatient admissions) for each patient >>> as a whole but not able to further break it down by >>> (i)before and after the event >>> (ii)60 days before the event(i.e., event==1) OR 60 days after the >>> event(i.e., event==1).[with a time component] >>> >>> How could I add the condition/stata pseudocode so as to get count of >>> IP before the event(variable-1) OR after the event(variable-2) >>> .Please help. >>> >>> >>> Thank you very much for your time >>> >>> On Wed, Nov 20, 2013 at 8:27 AM, Nick Cox <njcoxstata@gmail.com> wrote: >>>> A similar question was posted only yesterday >>>> >>>> http://www.stata.com/statalist/archive/2013-11/msg00745.html >>>> >>>> and advice included a reference >>>> >>>> SJ-7-3 pr0033 . . . . . . . . . . . . . . Stata tip 51: Events in intervals >>>> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox >>>> Q3/07 SJ 7(3):440--443 (no commands) >>>> tip for counting or summarizing irregularly spaced >>>> events in intervals >>>> >>>> which is accessible at http://www.stata-journal.com/sjpdf.html?articlenum=pr0033 >>>> >>>> >>>> Nick >>>> njcoxstata@gmail.com >>>> >>>> >>>> On 20 November 2013 13:11, Michael Stewart >>>> <michaelstewartresearch@gmail.com> wrote: >>>> >>>>> I am trying to measure number of visits/admissions before and after a >>>>> particular event and was hoping to get help from Stata programmers in >>>>> the Statalist >>>>> >>>>> My dataset is as follows . ED: stands for emergency department visit & >>>>> IP stands for Inpatient admission >>>>> >>>>> Patients are sorted chronologically (by date). >>>>> >>>>> My goal is >>>>> >>>>> 1)Count number of admissions(i.e., admit_type==IP) 60 days before the >>>>> event(i.e., event==1) OR 60 days after the event(i.e., event==1). >>>>> 2)Sum up the cost of the admissions (i.e., admit_type==IP) 60 days >>>>> before the event(i.e., event==1) OR 60 days after the event(i.e., >>>>> event==1). >>>> >>>> >>>>> 3 ED 0 date_1 USD xx >>>>> 3 IP 0 date_2 USD xx >>>>> 3 ED 0 date_3 USD xx >>>>> 3 IP 0 date_4 USD xx >>>>> 3 IP 1 date_5 USD xx >>>>> 3 ED 0 date_6 USD xx >>>>> 3 IP 0 date_7 USD xx >>>>> 3 ED 0 date_8 USD xx >>>> * >>>> * 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/ >>> >>> >>> >>> -- >>> Thank you , >>> Yours Sincerely, >>> Mike. >>> * >>> * 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/ >> * >> * 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/ > > > > -- > Thank you , > Yours Sincerely, > Mike. > * > * 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/ * * 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/