Statalist


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

Re: st: Adding variables containing empty values


From   Svend Juul <[email protected]>
To   [email protected]
Subject   Re: st: Adding variables containing empty values
Date   Wed, 2 Apr 2008 16:09:19 +0200

Ziad wrote:

Any tips how to add (summation) 3 variables when one has empty value
(example below)
I did not want to use replace var=0 if var==. because i want to know
when all the 3 variables (ndrug1,ndrug2 and ndrug3 have empty values
at the same time)

id      visitn      ndrug1      ndrug2      ndrug3      total
------------------------------------------------------------------------
-----
1      2              .                2             1             3
1      4              2                .             3             5
1      8              2                3            3             8
1      12            .                 .            .              .
2      2              .                 .            2             2
2      4              1                1            .              2

===================================================================


   . egen nonmiss = rownonmiss(ndrug*)
   . egen total = rowtotal(ndrug*) if nonmiss>0
   . list, clean

          id   visitn   ndrug1   ndrug2   ndrug3   nonmiss   total  
     1.    1        2        .        2        1         2       3  
     2.    1        4        2        .        3         2       5  
     3.    1        8        2        3        3         3       8  
     4.    1       12        .        .        .         0       .  
     5.    2        2        .        .        2         1       2  
     6.    2        4        1        1        .         2       2  

Hope this helps
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/



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