Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: egen rowtotal
From 
 
Nikolaos Pandis <[email protected]> 
To 
 
"[email protected]" <[email protected]> 
Subject 
 
Re: st: egen rowtotal 
Date 
 
Sun, 15 Jul 2012 12:43:38 -0700 (PDT) 
Thank you all for your help
 
I ended up using the following:
**************************************
foreach myvar of varlist  structured- reg_num{
  recode `myvar' 99=0 
}
egen sum = rowtotal(structured- reg_num )
********************************************
the results make sense (the value of zero is not a problem as I am calculating a score from the sum of 1s, 2s and 3s)
From: Nick Cox <[email protected]>
To: [email protected] 
Sent: Sunday, July 15, 2012 8:48 PM
Subject: Re: st: egen rowtotal
I think that if you choose the -egen- turning then the road ahead is
blocked, short of an enormously complicated -if- condition. But it  is
easy enough to work this out from first principles.
gen sum = 0
qui foreach v of var structured-reg_num {
    replace sum = sum + `v' if inlist(`v', 1, 2, 3)
}
replace sum = . if sum == 0
For a more systematic discussion, see
SJ-9-1  pr0046  . . . . . . . . . . . . . . . . . . .  Speaking Stata: Rowwise
        (help rowsort, rowranks if installed) . . . . . . . . . . .  N. J. Cox
        Q1/09  SJ 9(1):137--157
        shows how to exploit functions, egen functions, and Mata
        for working rowwise; rowsort and rowranks are introduced
Nick
On Sun, Jul 15, 2012 at 6:08 PM, Nikolaos Pandis <[email protected]> wrote:
> I am using the following command to get a row total for 16 variables:
>
> egen sum = rowtotal(structured- reg_num )
>
> the possible values per variable are 1, 2, 3 or 99  and I would like the row total by adding only the 1s, the 2s and the 3s and to excluded the 99s.
*
*  For searches and help try:
*  http://www.stata.com/help.cgi?search
*  http://www.stata.com/support/statalist/faq
*  http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/