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   Scott Cunningham <scunning@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: simple question: generating variables using the if / or command
Date   Thu, 27 Apr 2006 10:06:44 -0400

On Apr 27, 2006, at 10:02 AM, Gauri Khanna wrote:

Dear Stata list,

I have a seemingly simple problem that I can't seem to figure out.

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+vhttp:// by112fd.bay112.hotmail.msn.com/cgi-bin/compose?&curmbox=00000000% 2d0000%2d0000%2d0000% 2d000000000001&a=8e97f2d6d33d18578baf68a0a3ed45387544cbaa5b179c9e4483d 1f9e6d16955#
Sendar3 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.
This was garbled for some reason. Not sure what happened, but a URL was posted in the middle. I think I can see one problem, though. 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).

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