[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Problem with group operation and looping

From   "Gao Liu" <>
Subject   st: Problem with group operation and looping
Date   Tue, 16 Oct 2007 09:17:23 -0400

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.


*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index