Or, allowing for missing values:
gen and = d1&d2 if !mi(d1, d2)
gen or = d1|d2 if !mi(d1, d2)
gen xor = cond(d1+d2==1, 1, 0) if !mi(d1, d2)
It's always a good idea to add the "if not missing" clause.
On 9/26/06, Kit Baum <[email protected]> wrote:
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:
*
* 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/