Announcement

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

  • How to merge three variables from one data set

    Hi, I am a Stata newbie. I collected data using the online platform survey monkey. Unfortunately, the answers for some questions were transformed by Survey monkey into several different variables. For instance, in the question what is your civil status, answers were separated into four different variables (i.e. v19 single, v20 married, v21 divorced/separated, etc). I need to consolidate the different variables under one overarching variable, but I want to avoid manually doing this through my Excel file. What command/s should I use to generate a new variable under which I can consolidate the different variables? I tried searching for similar problems here, but did not find any. Since divorced/separated are also very low numbers, how do I consolidate the figures here under one category? Thank you for your help.

    What is |
    your civil |
    status? | Freq. Percent Cum.
    ------------+-----------------------------------
    Single | 156 100.00 100.00
    ------------+-----------------------------------
    Total | 156 100.00

    v20 | Freq. Percent Cum.
    ------------+-----------------------------------
    Married | 217 100.00 100.00
    ------------+-----------------------------------
    Total | 217 100.00

    v22 | Freq. Percent Cum.
    ------------+-----------------------------------
    Separated | 4 100.00 100.00
    ------------+-----------------------------------
    Total | 4 100.00

    . tab v23

    v23 | Freq. Percent Cum.
    ------------+-----------------------------------
    Divorced | 3 100.00 100.00
    ------------+-----------------------------------
    Total | 3 100.00




  • #2
    I'm assuming the variables are coded as strings? My first idea is to first rename the variables so they're grouped together as a single variable name and the coded value:
    v19 = marital1
    v20 = marital2
    v21 = marital3
    etc.
    then
    Code:
    foreach var of varlist marital* {
    local value=subinstr("`var'","marital","",.)
    replace `var'="`value'"
    destring `var', replace
    }
    egen marital=rowmax(marital*)
    If you have all your variables coded as above, you could use loops to substitute variable names and make your life easier.

    Comment

    Working...
    X