Announcement

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

  • Displaying values with one decimal place, including zeros

    Hello! This may seem basic but I have done my best to read all documentation and search the community. I would like to have Stata display output values with one decimal place, even if that would be a zero. For example, if the values are
    4
    5
    0
    1.25
    3.5
    1
    I would want to have it display
    4.0
    5.0
    0.0
    1.3
    3.5
    1.0

    I have used both numeric formats (example: format %9.1g var_name) and the round() function (example: replace var_name = round(var_name, 0.1)) and can get both to work, but neither forces a zero to display after the decimal. Thanks for your consideration.

  • #2
    Hi Kathy

    Try using . format var_name %8.1f

    Comment


    • #3
      You're looking for the fixed-decimal format (%#.#f).

      Code:
      input double x
      4
      5
      0
      1.25
      3.5
      1
      end
      
      format %9.1f x
      list
      Relevant output:

      Code:
           +-----+
           |   x |
           |-----|
        1. | 4.0 |
        2. | 5.0 |
        3. | 0.0 |
        4. | 1.2 |
        5. | 3.5 |
           |-----|
        6. | 1.0 |
           +-----+

      Comment


      • #4
        Amazing! Thank you both. I thought I had tried that already but this time it worked.

        Comment

        Working...
        X