Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: How to sum group of variables to a single variable in a large data set?


From   "Svend Juul" <SJ@SOCI.AU.DK>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: How to sum group of variables to a single variable in a large data set?
Date   Mon, 5 Mar 2007 13:09:52 +0100

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: sj@soci.au.dk
__________________________________________ 

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index