Hi, Statalist,
I think I am still quite confused with group operations using var[i]
and looping, so I am struggling with the following problem. I would
really appreciate if somebody can give me a hand.
I have a dataset containing following variables: ID, day_of_service,
drug_name, in which day_of service is the first day when the ID is
treated with the drug. The dataset contains data from 2003 to 2006.
Each ID may be treated for many times, and each time may be treated
with a different drug. In other word, they might switch from one drug
to another. But they would not switch back to a previously used drug.
I need to prepare two things for further analysis using the dataset.
First, I want to keep the observations with an entry. All
IDs with the first day_of service starting after 2004 will be kept.
For IDs with services before 2004, there are two situations: (the
first service day in 2004)- (the last service day in 2003)>45 or <45.
If <45, all observations of the ID would be dropped. If ID with >45,
observations after 2004 will be kept, but 2003 observations for the
same ID will be dropped.
Second, I need to figure out that for each drug (6 drugs totally), how
long an ID stuck with the drug before he/her switched to another drug
or exit. It is considered an exit if there is no new treatment 45 days
after the last treatment.
Thank you very much. Any input would be really appreciated.
Best
Gao
*
* 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/