Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Using -egen- with existing variable


From   Mike Lacy <Michael.Lacy@colostate.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Using -egen- with existing variable
Date   Thu, 02 Jun 2005 18:18:58 -0600

I want to use -egen- to create a total out of a1, a2, a3 in one situation, b1, b2, b3 in another situation, etc., but am running
into problems about how to use egen on an existing variable.

For example:

*I would like to do something like:
egen tot = rowtotal(a1 a3 a3) if situation = 1
egen tot = rowtotal(b1 b2 b3) if situation = 2
... etc.
egen tot = rowtotal(z1 z3 z3) if situation = 10
*
This of course is syntactically invalid. So, the kludge I
came up with was:

egen tot1 = rowtotal(a1 a3 a3) if situation = 1
egen tot2 = rowtotal(b1 b2 b3) if situation = 2
...etc.
egen tot10 = rowtotal(z1 z3 z3) if situation = 10
generate total = rowtotal(tot1-tot10)
* Make total missing where appropriate
egen nmiss = rowmiss(tot1-tot10)
replace total = . if nmiss == 10
drop nmiss tot1=tot10


What would be a Stata-ish way to do this?


Thanks,

=-=-=-=-=-=-=-=-=-=-=-=-=
Mike Lacy
Fort Collins CO USA
(970) 491-6721 office





*
* 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