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/