Announcement

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

  • Returning variable value from lables

    I am dealing with county-level data and each county is assigned a unique number. I can see the county name (which is defined as label for each unique number). How do I see the unique number for a given county name (label)?

    My data looks like:

    County employment
    1101.Utica 23%
    1102.Riverside 45%


    where county is a numeric variable.

  • #2
    When you list or tabulate or browse the data, you can add a -nolabel- option to the command and what you see will be the numbers rather than the labels.

    If you need to use the actual numeric value in some expression, you can get it as -`=Utica:name_of_the_value_label'- (If you don't know the name of the value label you can see it by running -des County-.)

    Comment


    • #3
      Thank you for your response. I would like to make my question clearer. I have added a snapshot of the data. There are around 2500 unique counties. Now, I would like to see the "code" which is assigned to a particular county. For example what is the code for the county Riverside? How should I find that?
      Attached Files

      Comment


      • #4
        To list the value label, which will show you each county and the associated numeric value:
        Code:
        label list `:value label county'
        I also notice two things in your screenshot. The first is that you have selected the county cell in the second observation, which is Autauga. If you look just under here it says Stata 16.0 SE - Fracking.dta, you will notice the number 1001. That is the numeric code underlying Autuga. I also note that the way the labels were constructed, they actually contain the number in them right at the beginning.

        Added: That said, it is going to be difficult to extract the code for Riverside. (If you just want to see it, scroll down in the browser to an observation that has Riverside county.) If the label for that county were just "Riverside", it would be easy to extract: -display `"`="Riverside":`:value label county'"'-. But the label, if it looks like the ones you show, will not be "Riverside." It will be some number, followed by a period followed by Riverside. But that number is precisely what you are hoping to find. So you would have to do something rather roundabout, like this:

        Code:
        summ county, meanonly
        local low `r(min)'
        local high `r(max)'
        forvalues i = `low'/`high' {
            local lbl: label (county) `i'
            if strmatch(`"`lbl'"', "Riverside") {
                display "Code for Riverside may be `i'"
            }
        }
        I put "may be" in there because I don't know your data set, but there are in the United States several counties named Orange, for example. (CA, TX, and NY each have one, and there are probably others.) Riverside sounds like another name that might be found in multiple places.
        Last edited by Clyde Schechter; 12 Dec 2023, 14:41.

        Comment


        • #5
          Thank you very much.

          Comment

          Working...
          X