Statalist The Stata Listserver


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

st: Re: dummy variable with overlapping if conditions


From   Kit Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Re: dummy variable with overlapping if conditions
Date   Tue, 26 Sep 2006 08:06:48 -0400

It is useful to note that a binary variable of this sort is the intersection of the sets defined by each dummy. Intersection of sets in binary arithmetic is done by multiplying, or with the AND operator (&). The union of sets -- true if either is true -- is done with the OR operator (|). Stata does not contain an exclusive OR operator (XOR), but one can readily be fashioned by adding the dummies:

gen xor12 = cond(dum1+dum2==1, 1, 0)


Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


On Sep 25, 2006, at 2:33 AM, statalist-digest wrote:



I will just add that Philipp's code generates missing where the condition is not met and these would have to be replaced
with 0 to make it a dummy variable. This two step can be avoided if this code is modified to be

gen cl1 = conlab == 1 & (clmarg>=.95 & clmarg<=1.05)
*
*   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