Announcement

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

  • Relabeling Values

    This is my first time using Stata without help from a professor, and I am struggling to relabel my values in one of my tables. I need to label my female and male values as '0' and my trans-female and trans-male values as '1'. I have included screenshots of my do-file and the outcome that I get. I have tried multiple ways of relabeling and consistently get an invalid syntax error. Any help would be greatly appreciated.



    Click image for larger version

Name:	Screen Shot 2020-03-15 at 4.17.49 PM.png
Views:	3
Size:	70.1 KB
ID:	1541433

    Click image for larger version

Name:	Screen Shot 2020-03-15 at 4.18.17 PM.png
Views:	1
Size:	115.5 KB
ID:	1541431
    Attached Files

  • #2
    The command - encode - has the option - label() - for that matter. You shall - label define - beforehand.
    Best regards,

    Marcos

    Comment


    • #3
      Hi Cassidy, try this:
      Code:
      label define gender  0   "female" ///
                          0   "male"    ///
                          1   "trans-female"    ///
                          1   "trans-male"
      Does this work?

      Comment


      • #4
        Welcome to Statalist.

        The syntax error on your label define command is because value labels assign text to numeric values, not the other way around.

        I think you will have better luck by replacing your label define and encode commands with these commands.
        Code:
        label define gender_all 1 "female" 2 "male" 3 "trans-female" 4 "trans-male"
        encode candidategender, generate(candidategender_all) label(gender_all)
        recode candidategender_all (1 3 = 0 "female") (2 4 = 1 "male"), generate(candidategender_new)
        The result will be two new variables: candidategender_all with numeric values for each of the four categories in candidategender, and then candidategender_new which recodes the four values to two values.

        Comment


        • #5
          Yao Zhao - apparently not.
          Code:
          . label define gender  0   "female" ///
          >                     0   "male"    ///
          >                     1   "trans-female"    ///
          >                     1   "trans-male"
          
          . label list gender
          gender:
                     0 male
                     1 trans-male

          Comment


          • #6
            Aha, you're right. Thanks.

            Comment


            • #7
              William Lisowski That worked! Thank you for the help

              Comment

              Working...
              X