Announcement

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

  • Trailing but not leading zeros in display format

    I would like to display a set of probabilities at two decimal places but with no leading zeros. E.g. I would like .95 to display as .95 and .90 to display as .90. I don't want .90 to display as 0.90 or as .9. Is there a display format that accomplishes this or do I need to resort to string manipulation (which is what I've been doing)?
    Code:
    loc p95=.95
    di %3.2f `p95'
    di %3.2g `p95'
    
    loc p90=.90
    di %3.2f `p90'
    di %3.2g `p90'
    Results:
    Code:
    . loc p95=.95
    
    . di %3.2f `p95'
    0.95
    
    . di %3.2g `p95'
     .95
    
    .
    . loc p90=.90
    
    . di %3.2f `p90'
    0.90
    
    . di %3.2g `p90'
      .9

  • #2
    Good question. Does this help?

    Code:
    .forval j = 0(5)95 {
     di `j'/100    "{col 7}." %02.0f `j'
     }
    
    0     .00
    .05   .05
    .1    .10
    .15   .15
    .2    .20
    .25   .25
    .3    .30
    .35   .35
    .4    .40
    .45   .45
    .5    .50
    .55   .55
    .6    .60
    .65   .65
    .7    .70
    .75   .75
    .8    .80
    .85   .85
    .9    .90
    .95   .95
    .
    In other words:

    1. Display the decimal point.
    2. Display probability x 100 with leading 0.

    mylabels from SSC will do it:

    Code:
    . mylabels 0(5)95, myscale(@/100) prefix(.) format(%02.0f) local(wanted)
    0 ".00" .05 ".05" .1 ".10" .15 ".15" .2 ".20" .25 ".25" .3 ".30" .35 ".35" .4 ".40" .45 ".45" .5 ".50" .55
    ".55" .6 ".60" .65 ".65" .7 ".70" .75 ".75" .8 ".80" .85 ".85" .9 ".90" .95 ".95"
    .


    Comment


    • #3
      Thanks Nick. That'll work quite well for my purposes.

      Comment

      Working...
      X