Announcement

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

  • How to combine two variables which are categorical, not numerical?

    Hi,

    I am facing problem in combining two variables in the same dataset as those are categorical, answered in yes(code-1), no(code-0) and missing(code-99). Please help me with the command. i am writing an example here.

    1. variable A1 (went to the doctor or not)
    yes - 100
    No- 50
    missing- 5

    2. Variable A2 (went to the Nurse or not)
    yes- 200
    No- 75
    missing- 4

    Now i want to add these two variables into one variable A (went to professionals), want to add all the yes, no and missing together. egen command doesn't work as this is not numerical data. if i stack, them, then i get the expected result but all other data gets deleted after stacking them. so, i cannot use the stacking command for my analysis. and if stacking is the only option please give me solution how can keep my all other data and use for my analysis. For the example i provided here, the expected result is-

    variable A
    yes- 300
    No- 125
    Missing- 9

    I hope i could describe my problem clearly. Please help me with the stata command that i can use for my analysis.

    -Sharmeen

  • #2
    gen varA = 1 if var1 == 1 | var2 ==1 (if you use numerical values)

    gen varA = "1" if var1 == 1 | var2 =="1" (if you use string values)

    Comment


    • #3
      No, it's not giving me what i want. for Numerical we can use Egen command for rowtotal. What do we use for adding categorical variables into one?

      Comment


      • #4
        neither your question nor your data are clear; please read the FAQ which has advice about giving data examples (via -dataex-) and advice on asking clear(er) questions; for example, I read your question in #1 as saying you want to add the values even if the value is for missing and thus adding A1=yes and A2=missing would give a total of 100 - but this makes no sense to me; please clarify

        Comment

        Working...
        X