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