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: Need Help with Stata Programming
From
Michael Stewart <[email protected]>
To
statalist <[email protected]>
Subject
st: Need Help with Stata Programming
Date
Tue, 7 Jan 2014 02:00:26 -0500
Hello ,
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
Thank you very much for your time and consideration.
--
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/