Announcement

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

  • Modify variable categories' name

    Hello,

    I would like to ask if I could change variable categories' name.

    I have this variable - Marital status with possible responses: 1="married-first and only marriage", 2="remarried-second or later marriage", 3="separated", 4="divorced", 5="widowed" and 6="have never married". I've already regrouped the first two (2=1) and the other ones into one single category. Then, I've created a dummy variable with 1=married and 0=single. But, I couldn't change the category's name. When I write: tab var or tab var, nol I can see that STATA automatically put the first two labels - 1="married-first and only marriage" and 2="remarried-second or later marriage" and it seems that I didn't create the dummy variable.

    So my question is how to rename the first two categories and why I can't see the dummy variable created.

    Please find herewith the code that I used to regroup and create a dummy variable. Also, I have tried to rename the categories, but it didn't work at all.

    *Recode Marital status
    tab e_mar_stat
    tab e_mar_stat, nol
    recode e_mar_stat (2 = 1)
    recode e_mar_stat (6 = 3) (5 = 3) (4 = 3)
    recode e_mar_stat (3 = 2)
    tab e_mar_stat, nol
    *Dummy for marital status
    generate married=.
    replace married=1 if e_mar_stat==1
    generate single=.
    replace single=0 if e_mar_stat==2
    label variable e_mar_stat "Marital status"
    label define mscats 1 "Maried" 2 "Single", modify
    label values e_mar_stat mscats

    Cheers,
    Darina

  • #2
    Hi Darina,
    I can't see why you labeling doesn't work - seeing what error you got from Stata would help.

    Also, you haven't created one dummy variable that assumes value 1 if married and value 0 if single, but two non-dummy variables: the fist equal to 1 if married and missing otherwise; and the second equal to 0 if single and missing otherwise.

    This should work for you.

    Code:
    recode e_mar_stat (1 2 = 1 "Married") (3/6 = 2 "Single"), gen(e_mar_stat_new)
    label variable e_mar_stat_new "Marital status"
    
    gen married = e_mar_stat_new==1

    Raffaele

    Comment


    • #3
      Hi Raffaele,

      Thank you very much for your response. I have no error message, but I know that it is not working because the dummy variable has not been created and STATA automatically put the first labels that are showed in the table. I have tried your code, but now I have this error message :

      recode e_mar_stat (1 2 = 1 "Married")
      Rules defining value labels not allowed when overwriting a variable

      I have no idea why it is not working.

      Cheers,
      Darina

      Comment


      • #4
        Instead of regrouping, say, the levels 2,3,4 of a 4-level variable, you may just - gen mydummy = oldvar > 1.

        That said, since this is just your second post in the forum, I strongly suggest to read the FAQ, particularly the recommendation to share command/output/data by using code delimiters or under - dataex - command (or SSC, for older versions of Stata).
        Best regards,

        Marcos

        Comment


        • #5
          Thank you very much, Marcos, for this information. Consider it done.

          Cheers,
          Darina

          Comment

          Working...
          X