Announcement

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

  • Format the number of decimals in Table command in Stata-17

    Hello everyone.
    I use the command below to determine the number of decimals in my table in Stata-17. However, I get different numbers of decimals in the last column (mean).
    table (Q)(), statistic(frequency) statistic (sum income) statistic (percent income) statistic (mean income) nformat(%9.1f percent ) sformat("%s%%" percent )
    I want all figures in the last column to be displayed with one decimal place. How should I modify my command?
    I appreciate your time.

  • #2
    Your command didn't specify any format for means or sums, so Stata used some default for that. Change -nformat(%9.1f percent)- to -nformat(%9.1f percent mean sum)-. (You can add frequency to that as well if you want, but since that's always an integer, I assume the default display of no decimal places makes more sense than one decimal place for that one.)

    Comment


    • #3
      Dear Clyde,
      Thank you. That was a great help.
      I changed the command to this and it works well.
      table (Q)(), statistic(frequency) statistic (sum income) statistic (percent income) statistic (mean income) nformat(%9.1f percent mean sum) sformat("%s%%" percent )

      This command gives the figures in the ‘frequency’ and ‘Total’ (sum income) columns in comma style (format with a thousands separator). How can I apply the same style to the last column (Mean)? I want to get the figures in the last column with both comma and 1 decimal places.
      Thank you.

      Comment


      • #4
        It surprises me that you are getting these results. Stata does not normally insert commas unless you request it, which your code does not do. I don't grasp why the formatting isn't the same for percent, mean, and sum. If you had requested commas by using the %9.1fc format, it would be possible that the numbers for mean might be too large to include commas and still fit into 9 characters, so the commas might be omitted. But I would expect, in that case, that the values for sum would be even larger and would also lack commas, so I'm not sure what to tell you. I suppose if I were in your shoes I would replace -nformat (%9.1f percent mean sum)- with -nformat(%12.1fc percent mean sum)- to see if that accomplishes what you want. If that doesn't work, try increasing even beyond 12 to see if that does it. Otherwise, I don't know what to suggest.

        Comment


        • #5
          Thanks a lot. That was really helpful.

          Comment

          Working...
          X