David wrote:
Suppose I have list of variables as follows:
diag3201
diag4201
diag8203
diag9201
diag9202
diag9203
diag9204
diag10214
diag10218
diag11201
...
The last three digits for each variable are the same; starts with 201
and end with 222 for some of them. The first digits indicate a
diagnosis. For instance, for diagnosis 98 we have variables diag98201
till diag98207, for diagnosis 9 we have variables diag9201-diag9204. I
want to generate new variables for the diagnoses that equal to the sum
of the variables that relate to this diagnosis. For example I want to
generate diag98=diag98201+ diag98202+ …+ diag98207 or diag9=diag9201+
diag9202+..diag9207.
I know how to do it for one diagnosis at a time, I use egen diag98=
rsum(diag98201-diag98207), but I need to do it for a large number of
diagnoses so how can I do it for all of them?
----------------------------------------------------------------
Write:
egen diag98 = rsum(diag98*)
In Stata 9 the name changed to the more telling -rowsum()-, but -rsum()-
still works.
Svend
__________________________________________
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C, Denmark
Phone: +45 8942 6090
Home: +45 8693 7796
Email: [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/