From | David Kantor <[email protected]> |
To | [email protected] |
Subject | Re: st: Using -egen- with existing variable |
Date | Fri, 03 Jun 2005 13:06:00 -0400 |
At 06:18 PM 6/2/2005 -0600, Mike Lacey wrote:
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 runningWhat you did is fine, putting aside minor grammatical and typographic missteps. I also don't know about rowtotal. You may have intended rsum instead -- unless there is a rowtotal egen function in Stata 9, which I don't have yet.
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
© Copyright 1996–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |