Announcement

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

  • Annoying leading space with %3.0f

    Hello all,

    I am noticing an annoying leading space before the numbers after I run the code with a di %3.0f and an endash. Which I end up correcting in Word after the putdocx statement I typically have. I don't think it is an MS Word issue. Would love pointers to see if it is a code issue. If I change it to di %3.1f, the spacing issue disappears. There are some variables like number of co-mutations (in my study) for which I cannot have decimals in the reporting.

    My code illustration below with the auto dataset.

    Code:
    sysuse auto, clear
    local x gear_ratio
    local unit "cm"
    
    local endash = ustrunescape("\u2013")
    
    
    // Code to just do stats around median for one whole group not stratified
    *---------------------------------------------------------------------------------------------
    foreach v of local x{
    qui tabstat `v', statistic(p25 p50 p75 min max) save
    return list
    local `v'lqr  : di %3.0f `=r(StatTotal)[1,1]'    
    local `v'med  : di %3.0f `=r(StatTotal)[2,1]'
    local `v'uqr  : di %3.0f `=r(StatTotal)[3,1]'
    local `v'min  : di %3.0f `=r(StatTotal)[4,1]'
    local `v'max  : di %3.0f `=r(StatTotal)[5,1]'
    local `v'_miqr `"``v'med' `unit' (IQR: ``v'lqr'`endash'``v'uqr' `unit')"'
    local `v'_mr `"``v'med' `unit' (range: ``v'min'`endash'``v'max' `unit')"'
    }
    
    di "`gear_ratio_miqr'"
    What it prints:
    Code:
    3 cm (IQR:   3–  3 cm)
    There is an extra space before both the 3's in the IQR.

  • #2
    Use a shorter format, that is, change %3.0f to %1.0f.

    Compare what you get with
    Code:
    local three : display %3.0f 3
    display in smcl as text "IQR: `three'–`three' cm"
    to that with
    Code:
    local three : display %1.0f 3
    display in smcl as text "IQR: `three'–`three' cm"

    Comment


    • #3
      Thanks much, Joseph Coveney That did it.
      I get the logic of display a little better now, thanks to your solution.

      Comment

      Working...
      X