Announcement

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

  • STATA labelling wrong?

    Hi all,

    I have a ordinal variable with 4 levels, when I upload my data, STATA recognizes it as a string variable so I decided to code it as numeric and then label it properly. The first time I used this code it worked fine, but today for some reason STATA is labelling my variables wrong - and when I mean wrong, the frequency of each level is mixed up. I am not sure what to do!

    This is my code:

    encode category1, generate(ncategory1)
    label define ncategory1 2 "Health maximiser" 1 "Pro-non-cancer" 4 "Strong prioritarian" 3 "Weighted prioritarian", replace

    When I used the tabulate function before I obtained these results (Check image right.jpg)
    Click image for larger version

Name:	right.jpg
Views:	2
Size:	21.9 KB
ID:	1622970



    but now I am obtaining results which are mislabeled and missing (check image wrong.jpg) PLEASE HELP
    Click image for larger version

Name:	wrong.JPG
Views:	1
Size:	39.9 KB
ID:	1622969







    Attached Files

  • #2
    encode will always apply labels in alphabetic order. You must define the label first, then pass it to encode:

    Code:
    label define ncategory1 2 "Health maximiser" 1 "Pro-non-cancer" 4 "Strong prioritarian" 3 "Weighted prioritarian"
    encode category1, generate(ncategory1) label(ncategory1)
    This is documented in the help. Moreover, when you

    Code:
    label define ncategory1 2 "Health maximiser" 1 "Pro-non-cancer" 4 "Strong prioritarian" 3 "Weighted prioritarian", replace
    you are changing the labels, not the underlying values. You never want that!


    As for the different number of observations, you would need to provide a reproducible example. I cannot see how that could really happen given the same dataset.

    Comment


    • #3
      THANK YOU this worked!!!

      Comment

      Working...
      X