aine dooley wrote:
> I'm sure there is a more elegant way to do this, however ...
>
indeed, there is. Any a much easier and faster (both typing and
computing time) way!
egen age1_sum=sum(exposure_time) if age<=50
egen age2_sum=sum(exposure_time) if age>50 & age <=75
egen age3_sum=sum(exposure_time) if age>75 & age <=90
egen age4_sum=sum(exposure_time) if age>90 & !mi(age)
creates a new variable for every "age group" which contains the
cummulative exposure_time of that group if the patient belongs to that
group and is missing otherwise, whereas
recode age (min/50=1) (51/75=2) (76/90=3) (90/max=4), gen (age_c)
bysort age_c: egen age_sum=sum(exposure_time)
creates one variable age_sum that contains the cummulative exposure_time
of each patient's age group. (it works on the assumption that your age
variable is integer)