Hi all I have this data:
newid = Patientid
admindate = Date admitted into hospital
Procedureid = The code for the surgery
indexno = If a patient had a procedure (found in procedureid) then this would be = 1 otherwise missing
Aim: To sort the data according to the Patient Id + Episode No + Admission date.
(note episode no - which I generate later is a sequential no given to any patient admitted into hospital)
Therefore I would like to view the Group of Patients In order of admission date in ascending order, so the earlier admission comes first, thus of course the patient would be younger.
To help you understand, this is what I would like to see (for demonstation purposes)
Patient A - Date of Admission 1 Mar 1980 - Episode 1 (n=1)
Patient A - Date of Admission 1 Jun 1990 - Episode 2 (n=2)
Patient B - Date of Admission 1 Apr 1981 - Episode 1 (n=1)
Patient B - Date of Admission 4 Mar 1985 - Episode 2 (n=2)
Code used
Step 1: Converted to stata dates and then into readable form
gen admindate = date(AdmissionDate, "DMY")
format admindate %td
Step 2:
Generate a _n number for each time the patient (newid) was admitted into hospital
sort newid
bys newid (Procedureid indexno admindate): gen episodeno = _n
The issue is, it is not sorting my admindate as you can see 5 Apr 1960 is before 1 Apr 1960
Can you explain to me why this is happening?
I have tried looking at several posts to understand this. I have checked my data several time.
I can not understand.
newid = Patientid
admindate = Date admitted into hospital
Procedureid = The code for the surgery
indexno = If a patient had a procedure (found in procedureid) then this would be = 1 otherwise missing
Aim: To sort the data according to the Patient Id + Episode No + Admission date.
(note episode no - which I generate later is a sequential no given to any patient admitted into hospital)
Therefore I would like to view the Group of Patients In order of admission date in ascending order, so the earlier admission comes first, thus of course the patient would be younger.
To help you understand, this is what I would like to see (for demonstation purposes)
Patient A - Date of Admission 1 Mar 1980 - Episode 1 (n=1)
Patient A - Date of Admission 1 Jun 1990 - Episode 2 (n=2)
Patient B - Date of Admission 1 Apr 1981 - Episode 1 (n=1)
Patient B - Date of Admission 4 Mar 1985 - Episode 2 (n=2)
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str10(AdmissionDate ReleaseDate) str3 newid float(admindate Procedureid indexno episodeno) "5 Apr 1960" "7 Apr 1960" "A1" 95 123 1 1 "1 Apr 1960" "5 Apr 1960" "A1" 91 . . 2 "1 Nov 1960" "1 Nov 1960" "M22" 305 124 1 1 "1 Feb 1960" "4 Feb 1960" "N1" 31 125 1 1 "1 Jan 1960" "4 Jan 1960" "Z2" 0 126 . 1 end format %td admindate
Code used
Step 1: Converted to stata dates and then into readable form
gen admindate = date(AdmissionDate, "DMY")
format admindate %td
Step 2:
Generate a _n number for each time the patient (newid) was admitted into hospital
sort newid
bys newid (Procedureid indexno admindate): gen episodeno = _n
The issue is, it is not sorting my admindate as you can see 5 Apr 1960 is before 1 Apr 1960
Can you explain to me why this is happening?
I have tried looking at several posts to understand this. I have checked my data several time.
I can not understand.
Comment