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 | Tue, 7 Jan 2014 09:27:31 +0000 |
<> You already know the basics here. Irregularity of dates does not bite for this problem. bysort id location (visitdate) : gen when_2_1 = visitdate[1] if location == 2 bysort id location (visitdate) : gen when_2_2 = visitdate[2] if location == 2 Nick njcoxstata@gmail.com On 7 January 2014 07:00, Michael Stewart <michaelstewartresearch@gmail.com> > I have a question regarding lists and have read Nick's paper on lists > and counting irregularly spaced intervals. > > I posted a similar, but different question > http://www.stata.com/statalist/archive/2013-11/msg00882.html > previously. > > My dataset is as follows > > ***********DATASET-BEGIN************************** > ID VISITDATE EVENT LOCATION > 1 Jan_1 May_1 1 > 1 Jan_4 May_1 2 > 1 Jan_6 May_1 1 > 1 May_5 May_1 1 > 1 May_8 May_1 2 > 2 Feb_2 Feb_9 2 > 2 Feb_6 Feb_9 2 > 2 Feb_15 Feb_9 1 > 2 Feb_27 Feb_9 2 > 2 Mar_30 Feb_9 2 > > ***********DATASET_END**************************** > > > MY NEED: I am trying to generate the following two variables and > looking to see if the programmers in the statalist may help me. > > 1) ***** for this variable, can you suggest an shorter/more elegant ******** > > VAR_1: this varaible shows VISITDATE when the LOCATION was the first > "2" [this is somewhat easier] > Ex: > For patient 1(ID=1), visit date corresponding to first 2 (in location) > would be Jan 4 > For patient 2(ID=2), visit date corresponding to first 2 (in location) > would be Feb 2 > > *************code begin******************* > bysort ID (VISITDATE): gen VAR_1=VISITDATE if LOCATION==2 > bysort ID (VAR_1): gen LOCATION_FIRST2=VAR_1[1] > ************code end************************ > > 2)**********I do not know how to generate the following variable > ****************** > > VAR_2: this variable shows VISITDATE when the LOCATION is the second 2 > > Ex: > For patient 1(ID=1), visit date corresponding to second 2 (in > location) would be May 8 > For patient 2(ID=2), visit date corresponding to second 2 (in > location) would be Feb 6 * * 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/