It is unclear whether your visit date is a string or number. If it is
a string it requires some additional processing. For example, if your
date look like the following:
id visit_date
1 Feb. 1, 2007
1 Jan. 1, 2007
1 Mar. 1, 2007
2 Feb. 7, 2007
2 Jan. 7, 2007
2 Mar. 7, 2007
3 Feb. 14, 2007
3 Jan. 14, 2007
3 Mar. 14, 2007
where is is the patient id number and visit_date is the date of the
patient visit. What you can do is sort by the patient and within that
by the visit date and create a new variable using _n to sequentially
number visits.
This could fails using string dates--sorting by visit_date can put the
records in the wrong order. To convince yourself sort these data by
visit_date by itself and you will see th eproblem. You need to first
convert the dates as strings to numbers and then sort.
The following code works for these sample data:
generate visit_date1=date(visit_date,"mdy")
bysort id (visit_date1): generate visit=_n
list
Best,
Alan
On 1/26/07, Ziad Khatib <[email protected]> wrote:
Hi,
I am using Stata 9, and I have data for patients who came to the
clinic on seperate occasions.
I am trying to create new variable, called "visit" and to mark the
"visit number" per patient.
For example:
Patient 1, came on Jan,1, 2007, Feb.1, 2007, March 1, 2007 etc..
How to code "visit" variable to have "1" for Jan.1
"2" for Feb1
"3" for March 1?
etc..
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/