Hi All
Currently working with a longitudinal dataset, where a subject may have several clinic visits in a given clander year. Additionally, the subject maybe have several clinic visits over several years:
Above, ID is the id number assigned to each subject. j is the visit/observatio number for a particular subject in the dataset, whereas N indicates the total number of visits or observations a subject has.
for j:
for N:
However, I would like to create a variable j2 that indicates the visit numbers for each subject but by calender year (and its corresponding N) like below:
How would go about creating j2 and N2?
Thanks!
/Amal
Currently working with a longitudinal dataset, where a subject may have several clinic visits in a given clander year. Additionally, the subject maybe have several clinic visits over several years:
Code:
ID j N clinicdate 1 1 9 23jan2006 1 2 9 23jan2006 1 3 9 23jan2006 1 4 9 23jan2006 1 5 9 23jan2007 1 6 9 23jan2007 1 7 9 23jan2007 1 8 9 23jan2008 1 9 9 23jan2008 2 1 7 23jan2006 2 2 7 23jan2006 2 3 7 23jan2006 2 4 7 23jan2007 2 5 7 23jan2008 2 6 7 23jan2008 2 7 7 23jan2008
for j:
Code:
bysort id (clinicdate): gen j= _n
Code:
bysort id: gen N= _N
Code:
ID j N clinicdate j2 N2 1 1 9 23jan2006 1 4 1 2 9 23jan2006 2 4 1 3 9 23jan2006 3 4 1 4 9 23jan2006 4 4 1 5 9 23jan2007 1 3 1 6 9 23jan2007 2 3 1 7 9 23jan2007 3 3 1 8 9 23jan2008 1 2 1 9 9 23jan2008 2 2 2 1 7 23jan2006 1 3 2 2 7 23jan2006 2 3 2 3 7 23jan2006 3 3 2 4 7 23jan2007 1 1 2 5 7 23jan2008 1 3 2 6 7 23jan2008 2 3 2 7 7 23jan2008 3 3
Thanks!
/Amal

Comment