Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: creating a cumulative variable

From   Sarah Mustillo <[email protected]>
To   [email protected]
Subject   st: creating a cumulative variable
Date   Tue, 09 Jul 2002 14:15:04 -0400

Hi -

 I have a longitudinal data set in long form with annual obs
for 6 years on 1450 kids. I am trying to create a cumulative variable
such that the
value for age 10 is the sum of the values at age 9 and age 10, the value
for age 11 is
the sum of the value for 9, 10, & 11 and so on. I can figure out
how to do this in wide form, but I am going to have to repeat it for
about 50
different variables. It would be much easier if I could just keep the
data in long form. I experimented with _n, and by id age, but
couldn't get what I wanted (e.g., for age 11 I could get the sum of age
10 (_n-1) and
age 11, but not age 9, 10, &11).

Once I create this new variable, is there an easy way to repeat the same
thing for 50 different variables? I usually just copy and paste in my do file, changing

variable names, but lately the do files have gotten rather long. It seems
there is probably an easy way to have it do the same thing over and over
different variables, but I can't figure it out.
Thank you in advance for any suggestions...


Sarah Mustillo, Ph.D
Center for Developmental Epidemiology
Department of Psychiatry and Behavioral Sciences
Duke University Medical Center

*   For searches and help try:

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