Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: simple question: generating variables using the if / or command


From   "Gauri Khanna" <[email protected]>
To   [email protected]
Subject   RE: st: simple question: generating variables using the if / or command
Date   Thu, 27 Apr 2006 16:26:24 +0000

Thank you Nick and Scott,

In fact I had previously used this command but it was not working. I kept getting an error and was wondering if I was doing something wrong. It works now. I just copied Scott's syntax!

Regards,

Gauri


From: "Nick Cox" <[email protected]>
Reply-To: [email protected]
To: <[email protected]>
Subject: RE: st: simple question: generating variables using the if / or command
Date: Thu, 27 Apr 2006 15:18:21 +0100

Typing

help operators

gives all you need to know on this (and you
really need to know all of it, too).

Nick
[email protected]

Scott Cunningham replied to Gauri Khanna [edited]

> > 1) I would like to generate a new variable :
> >
> > generate newvariable=var1+var2+var3 if dum1=1 and or dum2=1 and or
> > dum3=1
>
> gen newvariable=(var1+var2+var3) if dum1==1 | dum2==1 | dum3==1
>
> > 2) If instead I did the following....
> >
> > generate newvariable=var1+var2+var3 if dum1=1 & dum2=1 & dum3=1
> >
> > .... I would only capture values for var1, var2 and var3 if
> ALL the
> > three dummies simultaneously are 1. is this correct? If so I do
> > not want this.

> You want newvariable to equal the sum of three variables if any of
> the dummy variables = 1, but it looks like you are requiring it to
> equal 1 if all of the dummies equal 1. In other words, you
> are using
> the ampersand (&) when you should be using the (|) (see above).

*
* 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/
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index