Announcement

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

  • How do I sort values of string variable based on the order of frequencies

    I mean, in my dataset, I have a string variable X, which has 10 values such as a, b, c, etc.
    When I use tab command, it gives the result
    X freq.
    a 10
    b 5
    c 20
    And I want to sort values of X, from highest to lowest, in order to have the following result
    X freq.
    c 20
    a 10
    b 5


    Can I do that in stata? Thank you all in advance

  • #2
    The results are equivalent. Do you want a different output or a different sort order of the dataset?

    Best
    Daniel

    Comment


    • #3
      Let me make my problem clearer for you! When using the sort command. It will sort the variable based on the alphabetical order of values of variable, not on order of frequency of values. In fact, I have a list of diseases, which is coded before and entried in excell. And I want to obtain the top ten diseases that occur most frequently in the dataset. Thanks for your help!

      Comment


      • #4
        List of diseases is so long and if I create a new variable and then replace, label, it will take a lot of time!

        Comment


        • #5
          -tabulate, sort-

          -ssc desc groups-
          -ssc inst groups-

          Comment


          • #6
            Nick answered the question (I think). If you want the frequencies in a dataset

            Code:
            contract X
            sort _freq
            Best
            Daniel

            Comment


            • #7
              Thanks for your help but I don't know how to make it right.
              I have a string variable X
              X has 4 groups, such as a b c d
              and I have different number of observations with each groups.
              How do I list groups orderly based on the count of observations in the study (from highest to lowes).

              Comment


              • #8
                Finally, I get it. Thank you all!

                Comment

                Working...
                X