Announcement

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

  • Generating new variables from 2 string values

    Hi everyone, I would like to create new dummy variables (LOCAL & INTL) from 2 string values taken from variables ORIGIN and TARGET.
    Below is an example:
    ORIGIN TARGET LOCAL INTL
    US US 1 0
    NL CH 0 1
    GB TH 0 1
    CH CH 1 0
    IN BR 0 1
    So, what line of code should I use to create something like:

    Local = 1 if ORIGIN = TARGET (INTL = 0)
    INTL = 1 if ORGIN =/= TARGET (LOCAL = 0)

    (the contry codes listed are only an example)

    I hope that makes sense. Thank you!

    -KH

  • #2
    Code:
    g local = ORIGIN == TARGET
    g intl = ORIGIN != TARGET
    tab2 local intl

    Comment


    • #3
      George Ford is bang on but I want to add that these indicator (you say "dummy") variables are complements, so there is little point in having both.

      Comment


      • #4
        Brilliant! Thank you George

        Comment


        • #5
          As Nick says,
          Code:
           
           g local = ORIGIN == TARGET g intl = 1-local
          or just use ~local for intl. It is sometimes easier to have both variable defined.

          Comment

          Working...
          X