Announcement

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

  • Simple question - how to extract the value label for a given variable value?

    Hi,

    I have a variable Gender. The actual values are 0 or 1. I then gave it the value label genderlab2. You can see 0=Female and 1=Male:
    Code:
    . label list
    
    genderlab2:
               0 Female
               1 Male


    As part of a much longer code, I would like to display just "Male" or just "Female". Tried something like this, but clearly it is not right:

    Code:
    . di  "`: value label Gender'==1"
    genderlab2==1
    Code:
    
    


    Appreciate any guidance! Thanks!

  • #2
    Originally posted by Jay Gold View Post
    . . . I would like to display just "Male" or just "Female".
    Do you mean like this?

    . quietly sysuse auto

    . display in smcl as result "`: label (foreign) 1'"
    Foreign

    . display in smcl as result "`: label (foreign) 0'"
    Domestic

    .


    Code:
    help macro
    and scroll down to the Macro functions for extracting data attributes section.

    Comment


    • #3
      Cross-posted at https://www.reddit.com/r/stata/comme...e_value_label/

      It is a request here -- see https://www.statalist.org/forums/help#crossposting -- and a rule there on r/stata that you tell people about cross-posting in other places.

      Comment


      • #4
        My mistake Nick! Thank you for the heads up. I will remove from the other site.

        Comment


        • #5
          Originally posted by Jay Gold View Post
          My mistake Nick! Thank you for the heads up. I will remove from the other site.
          Just want to make sure you understand that this is not about copyright issues like who gets to host the question. It's about not wasting people's time. If the version on site A has been solved then the site B users will know of that and move on to help the next one.

          Deleting the one on Reddit was the next worst thing to do. Now that the thread was gone, not only it's unfair to the users who helped you with the answer over there, but also to other Reddit users who might benefit from reading the Q&A exchange.

          Comment


          • #6
            Well, now I feel doubly worse... I suppose a Google search will direct other users here...

            Comment


            • #7
              Originally posted by Jay Gold View Post
              Well, now I feel doubly worse... I suppose a Google search will direct other users here...
              Please don't worry. There is always next time.

              Comment

              Working...
              X