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 <>
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
An Introduction to Modern Econometrics Using Stata:

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:

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