Announcement

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

  • Ordering the results of a tabulation of a string variable

    I am trying to change the order of the tabulation for household income, the order comes up as shown below:


    . tabulate hincome

    Household income |
    (annual) | Freq. Percent Cum.
    ------------------+-----------------------------------
    0 - £19,999 | 12 12.00 12.00
    £100,000 and over | 14 14.00 26.00
    £20,000 - £39,999 | 16 16.00 42.00
    £40,000 - £59,999 | 20 20.00 62.00
    £60,000 - £79,999 | 24 24.00 86.00
    £80,000 - £99,999 | 14 14.00 100.00
    ------------------+-----------------------------------
    Total | 100 100.00


    I have tried using the command:

    . label define order 1 "0-£19999" 2 "£20000-£39999" 3 "£40000-£59999" 4 "£60000-£79999" 5 "£80000-£99999" 6 "£100000 and over"

    but it hasn't moved "£100,000 and over" to the bottom.

    Any suggestions how I can move it? Thank you


  • #2
    is hincome really a string variable? if yes, -label- won't help as you can't -label- strings (further, you need to assign the labels after defining them anyway; see - h label-); you could -encode- this and then label (or just use the label option to the -encode- command to then force the order)

    Comment


    • #3
      I have used encode to convert hincome from a string variable to a numeric one and then used label define but it hasn't changed the order?

      Comment


      • #4

        . describe hincome

        storage display value
        variable name type format label variable label
        --------------------------------------------------------------------------------------------------
        hincome long %17.0g hincome Household income (annual)

        Comment


        • #5
          nevermind, i've figured it out!!

          Comment


          • #6
            This does not solve your problem but you say

            I have used encode to convert hincome from a string variable to a numeric one
            and help encode states:

            Do not use encode if varname contains numbers that merely happen to be stored as strings; instead, use generate newvar = real(varname) or destring; see real() or [D] destring.
            You should:

            1. Read the FAQ carefully.

            2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

            3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

            4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

            Comment

            Working...
            X