'If and Or syntax wrong

What do I need to change so that the binaryeducation variable always==0 for this regression? The "or" should only be for the scenarios

svy: reg binaryanswer1 i.scenario if scenario==5 | scenario==9 | scenario==12 | scenario==14 | scenario==15 & binaryeducation==0


Solution 1:[1]

See

help operator

for the precedence of operators. I have never memorised this either on purpose or by accident. If the order of operators is not what you want, use parentheses to enforce a different order. I think what you want is

if (scenario==5 | scenario==9 | scenario==12 | scenario==14 | scenario==15) & binaryeducation==0

and indeed another device would solve the problem more neatly:

if inlist(scenario, 5, 9, 12, 14, 15) & binaryeducation == 0 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nick Cox