Announcement

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

  • How do I incorporate 'or' in to a stata command for generating a new variable

    Hi Statalist,

    I am trying to create a new variable (choice) which notes whether a graduate attended (collatt) one of their first or second choice universities (dummies of which being collprf1 and collprf2).
    I have generated a new variable: gen 'choice'=0
    following this I need to use: replace choice =1 if collatt==collprf1 OR collatt==collprf2
    however I am unsure how to incorporate this either/or dimension in to the command.
    any help would be greatly appreciated.

    Oliver

  • #2
    replace choice = 1 if collatt==collprf1 | collatt==collprf2

    See the output of -help operator- for the list of arithmetic, logical and relational operators.

    Comment


    • #3
      instead of what you have, substitute the "pipe" character (vertical bar) for your "OR"; e.g.,
      Code:
      replace choice =1 if collatt==collprf1 | collatt==collprf2

      Comment


      • #4
        thanks a lot, great help!

        Comment


        • #5
          Better still, there is no reason to use a -gen choice = 0- command followed by a -replace-. It can all be done in one line, and can be done with less typing:

          Code:
          gen choice = inlist(collatt, collprf1, collprf2)

          Comment

          Working...
          X