# st: RE: RE: algebraic with missings

 From "Nick Cox" <[email protected]> To <[email protected]> Subject st: RE: RE: algebraic with missings Date Tue, 18 Nov 2003 14:00:08 -0000

```Alternatively

gen negc = -c
egen q = rsum(a b negc)

Nick
[email protected]

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Nick Cox
> Sent: 18 November 2003 13:49
> To: [email protected]
> Subject: st: RE: algebraic with missings
>
>
> 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?
>
> Nick
> [email protected]
>
> 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:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
*
*   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/
```