Announcement

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

  • Help with merging variables

    Hi, i have 3 variables concerning migrationsbackground: born in country (yes or no), mother born in country (yes or no) and father born in country (yes or no). What i want is to create a new variable called migrationbackground where its yes if mother and father is no or if born in country is no.
    Hopefulle somebody can help me to do this. Thanks

  • #2
    you don't give us the names of the variables nor whether the variables are string or numeric (please read the FAQ); my suggestion below assumes that each of the 3 variables is a string variable and I give fake names; the new variable, however, is numeric and 1 is for yes:
    Code:
    gen byte migback=(mother=="yes" & father=="yes") | born=="no"
    since you did not supply a data example (use -dataex- and CODE blocks as per the FAQ), this code is not tested and there may well be typo's or other errors

    Comment


    • #3
      You provided no example of your data, so I get to invent variable names and coding assumptions, and you can translate my answer to match the specifics of your data.

      I am going to assume that your existing variable names are bic (born in country), mbic (mother born in country), and fbic (father born in country), and that each variable, including migrationbackground, is coded to take a value of 1 for yes or 0 for no.
      Code:
      generate migrationbackground = 0
      replace migrationbackground = 1 if (mbic==0 & fbic==0) | bic==0

      Comment

      Working...
      X