Dear all
I have a set of data in which the same patient may feature 1 or more times (blood tests done over the course of a year). What I want to do is to create a column of episode numbers gives each patient episode a unique number. After much headbanging I have come up with this:
egen id =group(whatever identifies the patients)
and then
egen episodeno =group(id labno) (the laboratory code number for the sample.)
this gets you so far except that doesn't seem possible to go much further using the same method, and the resulting episodeno doesn't cycle back to 1 with each new patient
The way forward would therefore appear to be to generate something like mod(episodeno, smallest value of episodeno for patient n)
STATA doesn't seem to be very keen to let you do things like this (i.e. using [1]) and the only way I could find to do it was
by id : egen episodeno1 =min(episodeno)
gen episodeno2 =mod(episodeno,episodeno1) + 1 (unlikely to cycle back to 1 for the same patient unless they spend the whole year having blood taken)
or alternatively put a -1 in the first of these two statements
Does anyone know a better way to do this? !!
have just scrolled down egen again and found that rank might work... (except it doesnt quite do it..)
I have a set of data in which the same patient may feature 1 or more times (blood tests done over the course of a year). What I want to do is to create a column of episode numbers gives each patient episode a unique number. After much headbanging I have come up with this:
egen id =group(whatever identifies the patients)
and then
egen episodeno =group(id labno) (the laboratory code number for the sample.)
this gets you so far except that doesn't seem possible to go much further using the same method, and the resulting episodeno doesn't cycle back to 1 with each new patient
The way forward would therefore appear to be to generate something like mod(episodeno, smallest value of episodeno for patient n)
STATA doesn't seem to be very keen to let you do things like this (i.e. using [1]) and the only way I could find to do it was
by id : egen episodeno1 =min(episodeno)
gen episodeno2 =mod(episodeno,episodeno1) + 1 (unlikely to cycle back to 1 for the same patient unless they spend the whole year having blood taken)
or alternatively put a -1 in the first of these two statements
Does anyone know a better way to do this? !!
have just scrolled down egen again and found that rank might work... (except it doesnt quite do it..)
Comment