Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • "or" operator

    Hi Statalist,

    I would like to generate a group which includes female-asian students and female-european students.

    a=1 for female
    a=0 for male
    b=1 for asian
    b=2 for european
    b=3 for african
    b=4 for x
    b=5 for y.......
    b=6.....

    gen G=1 if a==1 & b==1 | b==2

    This command gives female students and all asian and all european students.
    How should I correct my mistake?

    Thank you
    Beyza


  • #2
    The order of Boolean operations in Stata, as in most programming languages, is that & takes precedence over |. So what you want is

    Code:
    gen G = 1 if a == 1 & (b == 1 | b == 2)
    Comments: This generates a 1/. variable rather than a 1/0 variable. 1/0 variables are generally more useful. Also, while there is little difference when only two values of b are under consideration, with longer lists of alternatives, using the inlist() function is easier than enumerating a list of disjoined equalities. So, if I were doing this, it would be:

    Code:
    gen G = (a== 1 & inlist(b, 1, 2))

    Comment


    • #3
      Great! Thanks a lot!

      Comment

      Working...
      X