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

st: RE: algebraic with missings

From   "Nick Cox" <>
To   <>
Subject   st: RE: algebraic with missings
Date   Tue, 18 Nov 2003 13:48:35 -0000

With -egen, rsum()- missings are ignored, 
which evidently is what you want here. 

If you go 

. which _grsum 

and fire up your favourite text editor
to look at the code, you can see how 
it is done, by using 

cond(mi(varname), 0, varname) 

(In fact, what is there is an older 
way of saying this; under version control, 
that's OK.) 

Another way of doing this is 
to exploit the fact that max(0, <missing>) 
is 0 -- but that's not so good if any 
of your values is negative. 

You want 

gen q = cond(mi(a), 0, a) + cond(mi(b), 0, b) - cond(mi(b), 0, c) 

Can that be written more concisely? 


Roberto De Miguel
> To solve an equation of the type:  
> p = a + b + c  
> where a, b or c can be missing,  
> I use the following sentence:  
> egen p = rsum (a b c)  
> But now I want to solve:  
> q = a + b - c  
> How can I do that?

*   For searches and help try:

© Copyright 1996–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index