Announcement

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

  • Format decimal in tabulate

    Hi,
    Could somebody help me with this?
    I want to output my tabulate with only one decimal, for example 65.1. However, the option format(%9.1f) doesn't work after tabulate (i tried tabulate agegroup sex, row nofreq format(%9.1f)).
    Best,
    John
    Stata MP 13 User

  • #2
    The issue is wanting one decimal place not two, and it's awkward that this isn't available.

    You can knit your own with modest effort. An "all" row is possible too.

    Code:
    . sysuse auto, clear 
    (1978 Automobile Data)
    
    . tabulate rep78 foreign, row nofreq 
    
        Repair |
        Record |       Car type
          1978 |  Domestic    Foreign |     Total
    -----------+----------------------+----------
             1 |    100.00       0.00 |    100.00 
             2 |    100.00       0.00 |    100.00 
             3 |     90.00      10.00 |    100.00 
             4 |     50.00      50.00 |    100.00 
             5 |     18.18      81.82 |    100.00 
    -----------+----------------------+----------
         Total |     69.57      30.43 |    100.00 
    
    . egen num = total(1), by(foreign rep78)
    
    . egen den = total(1), by(rep78)
    
    . gen pc = 100 * num/den
    
    . tabdisp rep78 foreign, c(pc) format(%2.1f)
    
    ------------------------------
    Repair    |
    Record    |      Car type     
    1978      | Domestic   Foreign
    ----------+-------------------
            1 |    100.0          
            2 |    100.0          
            3 |     90.0      10.0
            4 |     50.0      50.0
            5 |     18.2      81.8
            . |     80.0      20.0
    ------------------------------
    
    . tabdisp rep78 foreign if rep78 < ., c(pc) format(%2.1f)
    
    ------------------------------
    Repair    |
    Record    |      Car type     
    1978      | Domestic   Foreign
    ----------+-------------------
            1 |    100.0          
            2 |    100.0          
            3 |     90.0      10.0
            4 |     50.0      50.0
            5 |     18.2      81.8
    ------------------------------

    Comment


    • #3
      Thanks Nick!
      I have around 15 tables with 2 rows in each. So I think I it is more efficient for me to just ran the table like usual and then delete the extra number in word rather than write extra code for each of the command line.
      John
      Last edited by John Havens; 04 May 2017, 09:42.
      Stata MP 13 User

      Comment

      Working...
      X