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
Steve Samuels <[email protected]>
To
[email protected]
Subject
Re: st: egen rowtotal
Date
Sun, 15 Jul 2012 14:37:36 -0400
Another approach is to convert the 99's to missing values, which they are, before running -egen rowtotal-. This modifies the original data, but in many studies would be an acceptable, even desirable, step in data editing.
****************************************
mvdecode structured-reg_num, mvdecode(99)
****************************************
Steve
[email protected]
On Jul 15, 2012, at 1:48 PM, Nick Cox wrote:
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/