Hi All,

I have the following dataset:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(var1 var2 var3)
1 2 0
0 1 0
1 1 1
end
Suppose I wish to create a variable, say x, which takes on a value of 1 if either var1==1 or if var2==1, and if var3==0. The syntax is a bit confusing here:

Code:
g x=1 if var1==1 | var2==2 &var3==0
g xprime=1 (if var1==1 | var2==2) & var3==0
xprime produces what I want, as the and condition is not combined with the second if condition, but is rather an independent condition. Is there any other way one can think of this distinction without using parentheses? In other words, is there a more intuitive way to go about this?


Thanks,
CS