Hi, I have a data set that displayed long. I am doing study on prevalence of this medicines among thousands of indviduals,
Each participant has many drug prescriptions. I want to know the first date for each drug for the each indvidual.
I used bysort id (Edate):gen firstdate=Edate[1] to know the first date of prescription. Now I want to keep only the first date for these drugs. I tried to use this command bysort id (firstdate):gen want=_n
then
drop if want >1
but it drop the repeated ids. Could you please help me to keep only the first date of exposure to only one of these drugs.
Thanks in advance!
Each participant has many drug prescriptions. I want to know the first date for each drug for the each indvidual.
I used bysort id (Edate):gen firstdate=Edate[1] to know the first date of prescription. Now I want to keep only the first date for these drugs. I tried to use this command bysort id (firstdate):gen want=_n
then
drop if want >1
but it drop the repeated ids. Could you please help me to keep only the first date of exposure to only one of these drugs.
Thanks in advance!
id | gender | Edate | year | age_5g | Asprin | Other anti- inflamatory | analgesic | corticosteriods | sedatives | firstdate | ||
1256 | 2 | 60221 | 2006 | 30-40 | 16-Jan-06 | |||||||
1256 | 2 | 60406 | 2006 | 30-40 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 16-Jan-06 |
1256 | 2 | 60602 | 2006 | 30-40 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 16-Jan-06 |
1256 | 2 | 60725 | 2006 | 30-40 | 16-Jan-06 | |||||||
1256 | 2 | 60808 | 2006 | 30-40 | 16-Jan-06 | |||||||
1256 | 2 | 60811 | 2006 | 30-40 | 16-Jan-06 | |||||||
1256 | 2 | 61027 | 2006 | 30-40 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 16-Jan-06 |
1257 | 2 | 60116 | 2006 | 30-40 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 16-Jan-06 |
1257 | 2 | 60116 | 2006 | 30-40 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 16-Jan-06 |
1257 | 2 | 60116 | 2006 | 30- | 16-Jan-06 | |||||||
1257 | 2 | 60116 | 2006 | 25-30 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 16-Jan-06 |
1257 | 2 | 60523 | 2006 | 25-30 | 16-Jan-06 | |||||||
1257 | 2 | 61101 | 2006 | 25-30 | 16-Jan-06 | |||||||
1257 | 2 | 61107 | 2006 | 25-30 | 16-Jan-06 | |||||||
1257 | 2 | 61230 | 2006 | 25-30 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 16-Jan-06 |
Comment