Bookmark and Share

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   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: egen rowtotal
Date   Sun, 15 Jul 2012 18:48:26 +0100

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index