Announcement

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

  • Changing value labels (dropping a part of value labels)

    Hi everyone,

    I am working on a dataset which has coded variables whose labels are for example, like, "1. Yes; 0. No" or "10. Raj; 11. UP; 12. HP" etc. Basically all label values contain digits in the beginning of the label but the number of digits could differ depending on the variable.

    I want to change the value labels such that the digits are dropped and I only retain the string value in all such variables, that is, "Yes; No" etc.

    It would be great if someone can let me how I can do the above in an efficient manner than having to redefine the label values for each.

    Thank you
    Last edited by rachita vig; 26 Jul 2021, 04:42.

  • #2
    Depending on the details,

    Code:
    numlabel , remove
    will do the trick.

    This will work only if the numbers that are part of the text in value labels are the same as the integer values they are mapped to. For example, if the label, say yesno, were defined as

    Code:
    . label list yesno
    yesno:
               0 0. No
               1 1. Yes
    the code above will remove 0. and 1. However, in

    Code:
    . label list yesno
    yesno:
               0 73. No
               1 42. Yes
    numlabel will not work.

    Get back if you need a more flexible approach.



    Comment


    • #3
      Looks like the result of using numlabel . That is nice when preparing the data, but for presenting the final analysis you typically want to remove that again, like in your question. Fortunately, the numlabel command has the remove option. Just typing numlabel, remove should do the trick.
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Thanks a lot Daniel and Maarten!

        Daniel, while my dataset pertains to case #1 as you described - it would be great to also know what to do under case #2.

        Best,
        Rachita

        Comment


        • #5
          Originally posted by rachita vig View Post
          - it would be great to also know what to do under case #2.
          The second example in #2 is just that: an example. Thus, the details will be important. That aside, the text in value labels are strings. Strings can be manipulated by string functions (and extended macro functions, but let's stick with string functions for now). elabel (SSC) applies string functions to value labels. If all value labels follow the pattern

          #. text

          then

          Code:
          elabel define * (= #) (= substr(@, strpos(@, ".")+2, .)) , modify


          That code will, however, mess up value labels that do not follow the specific pattern.

          Comment

          Working...
          X