Announcement

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

  • Copying labels of encoded variables

    Dear all,

    I was wondering whether it is possible to copy labels of encoded variables. Suppose I have the following code:

    // Notice: A was a string categorical variable and now it is encoded into a numeric one.
    enocode A, gen(enc_A)

    // Notice: B was a string categorical variable, with the same categories as A, but now encoded into a numeric one.
    encode B, gen(enc_B)

    For the sake of example, let's assume they have 3 categories, High, Mid and Low, I would like to have the same numbers assigned to A as to B (i.e. if in A the label is: 1 - High, 2 - Mid, 3 - Low; I would like to have B encoded as 1 - High, 2 - Mid, 3 - Low). Note: I know I can do this by hand, however the problem is that there are about 50+ categories, so I prefer a different approach.

    Thanks for your response!

  • #2
    I think all you need is:

    Code:
    encode A, gen(enc_A)
    encode B, gen(enc_B) label(enc_A)

    Comment


    • #3
      Oh, I did not knew that! I probably have overlooked this function. Thank you! (PS: how do you do the code section, it looks really pretty!)

      Comment


      • #4
        How to set up code (and our preference for using full real names) are among the details (now) covered in http://www.statalist.org/forums/help

        As the home page itself advised.

        Read the Statalist FAQ, especially if you wish to post a message to Statalist.

        Comment

        Working...
        X