Announcement

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

  • Change a numerical variable with string input into label value

    Hey there, I have a variable called "ad_tone" that has three values, negative, positive, and attack. When I tab this variable with no label, it shows 1, 2, and 3. However, in my dataset for each observation, the record for this variable is still "negative", "positive" and "attack". My question is how to change the input into the numerical value (to change the "attack" to "3").Thanks very much!
    Click image for larger version

Name:	Screen Shot 2020-10-24 at 17.10.47.png
Views:	1
Size:	4.5 KB
ID:	1578827

  • #2
    As you know from tabbing your variable without labels, ad_tone is a numeric variable with a value label. The value label controls only how it is displayed in output, the numeric values are what are used for all other purposes.

    See
    Code:
    help labels
    and then click through to the full PDF documentation from the top of the help output for a further discussion. Also, section 12.6 of the Stata User's Guide PDF included in your Stata installation and accessible from Stata's Help menu has more to say.

    In short, your variable is as you need it. "attack" is 3, but displayed as "attack" rather than "3" or "3.0" or what its numeric format would have it display as.
    Code:
    count if ad_type==3
    should give the same count as your tab did for "attack".

    Comment


    • #3
      As William explained, what you want to do is already done.

      You might also want to say what you want to do with this variable. The purpose you have in mind for this variable can additionally guide how you can treat this variable best.

      Comment


      • #4
        The browse command has a nolabel option.

        Comment


        • #5
          Thanks everyone!

          Comment

          Working...
          X