Announcement

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

  • f format uses an inconsistent number of character positions

    If I set a format "%04.2f" I get the requested 2 decimal places for non-integer values, but integer values are displayed with no decimal point or decimal part - taking 1 character space instead of 4. (All the values are <10). This interferes with vertical alignment, so I would like to display zero as "0.00" rather than just "0". I thought of replacing zero with .00001 thinking it would round on output to "0.00", but that just causes Stata to switch to scientific format which uses even more character positions. Do I need to use -tostring- and -replace- the "0"'s with "0.00" or is there an easier way?

    Code:
    .
    . set obs 1
    . gen x=0
    . format x %04.2f
    . di x
    0 the string 
    . replace x=1.22
    . di x
    1.22

  • #2
    I don't think that display respects a variable's display format. Try

    Code:
    . display %04.2f x
    0.00
    or

    Code:
    . list x
    
         +------+
         |    x |
         |------|
      1. | 0.00 |
         +------+


    Comment

    Working...
    X