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

Re: st: creating a cumulative variable


From   Sarah Mustillo <[email protected]>
To   [email protected]
Subject   Re: st: creating a cumulative variable
Date   Thu, 11 Jul 2002 14:11:33 -0400

Nick and Nick -

I implemented your solution to my cumulative variable problem, which worked very nicely, thank you very much. Beyond that, however, I wanted to thank you for pointing me towards the "foreach" command. I can't believe I have never used this before! Already it has simplified my life tremendously. Thank you.

Sincerely,

Sarah















foreach v of var <varlist> {
	by id : gen C`v' = sum(`v')
}

You must plug in your <varlist>. It can be in abbreviated form,
using * ? and/or -, etc.

Naturally, you can use your own naming convention, but
this is usually easiest with just some short prefix or suffix
added to the original variable name to give a new name.

This particular problem can also be done with -for-.
My main reservation about -for- is that it doesn't
grow gracefully when extended to more complicated
problems, whereas -foreach- typically does.

Nick
[email protected]

*
*   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/



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

*
*   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/



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