Announcement

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

  • label define but it's not 1-to-1

    I don't think I make a clear question, so let me show my data.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str31 q14_marriage
    "Single; never married"          
    "Single; never married"          
    "Single; never married"          
    "Married or domestic partnership"
    "Married or domestic partnership"
    "Divorced"                       
    "Married or domestic partnership"
    "Married or domestic partnership"
    "Married or domestic partnership"
    "Married or domestic partnership"
    end
    For this string variable, it has multiple choices and I want them to be 0,1,1,0,0: (my reasoning here is whether people are in a relationship or not. I'm open if you have different opinions.)

    Divorced
    Engaged; to be married
    Married or domestic partnership
    Separated
    Single; never married

    In my case, three string values are 0 and two string values should be 1. How to do it?

  • #2
    there are lots of ways to do this (but note that your example does not include "Engaged; to be married"); here is one:
    Code:
    gen byte partner=substr(q14,1,3)=="Mar" | substr(q14,1,3)=="Eng"
    at this point you can add labels to the new variable; see
    Code:
    help label

    Comment


    • #3
      Code:
      gen wanted = strpos(Q14, "Single") | strpos(Q14, "Separated")  | strpos(Q14, "Divorced")
      will assign Single and Separated and Divorced to 1 and the others to 0. Or use negation to flip it round.

      That may not be your distinction but it may help with technique. I don't follow your 0 1 1 0 0 or your ordering as being anything but alphabetical.

      Comment

      Working...
      X