Announcement

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

  • Renaming New Variables' values

    I am conducting a cross-sectional study of UK firms. I have created a variable (ind1) that groups the firms into 11 industry categories numbered 1 to 11. I want to replace these values with industry names i.e. 1 = Natural Resources, 2 = Manufacturing etc. How do I go about this considering the variable ind1 is numeric? Do I first convert that to a string variable and literally type out a replace command for each category?

  • #2
    See

    Code:
    help encode
    Best
    Daniel

    Comment


    • #3
      -encode- could help you here, but I think you might not understand the role of value labels in Stata. See -help label- and follow your way into the PDF documentation. The approach in Stata, and in similar programs since about 1975, is to store variables as numeric (almost always), but to associate string labels with the numeric values if the numeric values are codes with no inherent meaning. On this basis, I think you don't really want string variables, but rather a means to see what 1, 2, 3, ... actually mean for this variable. A standard way to do this is as follows:

      1) Define a value label that can be used to label the values of this variable:
      Code:
      label define Industrylbl 1 "Natural Resources" 2 "Manufacturing" .....
      2) Associate this label with your variable:
      Code:
      label values ind1 Industrylbl
      This will associate those string labels with the numeric values, and will display labels in various results and in your data editor by default.

      In general, you don't want to store anything in Stata or similar programs as a string except names, addresses, and (usually) identification codes.

      Comment

      Working...
      X