Announcement

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

  • Converting variables into the values of a new variable?

    Hi all!

    I am quite new in Stata and hoping anyone can help me!

    I am working on a maternity survey and wondering if there is a way to convert 4 variables in my database into the values of a new variable?
    E.g. I have 4 variables (yes/no): 1) midwife 2)physician 3)medical_doctor 4)obstetrician but I want to create a new variable (“Professional responsible for your maternity care” which has 4 different values: midwife, physician, medical doctor, obstetrician

    Is this possible? Do I need to care a local macro? Loop?

    Thank you so much!

    Cristina

  • #2
    Here's a guess

    Code:
    gen wanted = cond(midwife == 1, 1, cond(physician == 1, 2, cond(medical_doctor == 1, 3, cond(obstetrician == 1, 4, .)))) 
    
    label def wanted 1 midwife 2 physician 3 "medical doctor" 4 obstetrician 
    
    label val wanted wanted

    Comment


    • #3
      A short loop will do this:

      Code:
      label define caregiver  1   "midwife"   ///
                              2   "physician" ///
                              3   "medical_doctor"    ///
                              4   "obstetrician"
      gen caregiver:caregiver = .
      local i = 1                    
      foreach v of varlist midwife physician medical doctor obstetrician {
          replace caregiver = `i' if `v' == 1
          local ++i
      }
      Note: Above code assumes that the midwife, physician, medical_doctor, and obstetrician variables are coded 1 = yes and something else = no.

      But there are a couple of issues you need to come to terms with. What do you want to do if the respondent said yes to more than one of these options? The code above will designate the last one among all the yes responses.

      Then there is the ambiguity in the response set offered. The terms physician and medical doctor are more or less synonymous (some might consider osteopaths to be physicians but not medical doctors). So it isn't clear how respondents are expected to choose between these two. On top of that, an obstetrician is definitely both a physician and a medical_doctor. So I suspect that the responses to this question will be a mess and that you would be better off lumping the last three categories together and just contrast those with midwife.

      Added: Crossed with #2.

      Comment

      Working...
      X