Announcement

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

  • Adding characters to dtable output

    Hi All,

    I'm looking to generate a "Table 1", and having recently upgraded to Stata 18, am attempting to use dtable. Generally speaking it's great, however because my continuous variables are skewed I need to report median and interquartile range rather than mean and standard deviation. This is the code I've used at the base level:


    Code:
    dtable client_days_at_risk client_age i.gender_collapse if episode_counter==1, by(overall_service) continuous(client_days_at_risk client_age, statistics(med p25 p75))
    
    
    -------------------------------------------------------------------------------------------
                                           Service Type for Episode (Health vs ACC)            
                                     Health                  ACC                  Total        
    -------------------------------------------------------------------------------------------
    N                               69,757 (64.1%)         39,064 (35.9%)      108,821 (100.0%)
    Total Client Days at Risk 33.000 7.000 164.000 282.000 96.000 427.000 83.000 15.000 334.000
    Client Age                67.000 51.000 80.000   82.000 76.000 88.000  75.000 61.000 84.000
    Gender                                                                                     
      Male                          32,128 (46.1%)         13,627 (34.9%)        45,755 (42.0%)
      Female                        36,769 (52.7%)         25,178 (64.5%)        61,947 (56.9%)
      Other                             469 (0.7%)             151 (0.4%)            620 (0.6%)
      Missing                           391 (0.6%)             108 (0.3%)            499 (0.5%)
    -------------------------------------------------------------------------------------------
    However, you can see that the median and IQR are just one after the other, and I'd like to add some characters to aid interpretability. Ideally, something like:


    Code:
    -------------------------------------------------------------------------------------------
                                           Service Type for Episode (Health vs ACC)            
                                     Health                  ACC                  Total        
    -------------------------------------------------------------------------------------------
    N                               69,757 (64.1%)         39,064 (35.9%)      108,821 (100.0%)
    Total Client Days at Risk        33 (7 -  164)        282 (96 -  427)        83 (15 -  334)
    Client Age                        67 (51 - 80)          82 (76 -  88)          75 (61 - 84)
    Gender                                                                                     
      Male                          32,128 (46.1%)         13,627 (34.9%)        45,755 (42.0%)
      Female                        36,769 (52.7%)         25,178 (64.5%)        61,947 (56.9%)
      Other                             469 (0.7%)             151 (0.4%)            620 (0.6%)
      Missing                           391 (0.6%)             108 (0.3%)            499 (0.5%)
    -------------------------------------------------------------------------------------------

    I've attempted to achieve this by using both the sformat command within dtable, and even combining dtable with the collect commands, but have not yet had any luck. Can anyone assist me to achieve a more interpretable outcome?

    Thanks in advance,

    Marissa

  • #2
    Here is an example of how to do this, using the auto data.
    Code:
    . sysuse auto
    (1978 automobile data)
    
    . 
    . dtable mpg price i.rep78, ///
    >         define(iqi = p25 p75, delimiter(" - ")) ///
    >         sformat("(%s)" iqi) ///
    >         nformat(%12.0g p25 median p75) ///
    >         continuous(price, statistics(median iqi)) ///
    >         by(foreign)
    
    -------------------------------------------------------------------------------
                                                Car origin                         
                             Domestic             Foreign              Total       
    -------------------------------------------------------------------------------
    N                            52 (70.3%)         22 (29.7%)          74 (100.0%)
    Mileage (mpg)            19.827 (4.743)     24.773 (6.611)       21.297 (5.786)
    Price              4782.5 (4184 - 6234) 5759 (4499 - 7140) 5006.5 (4195 - 6342)
    Repair record 1978                                                             
      1                            2 (4.2%)           0 (0.0%)             2 (2.9%)
      2                           8 (16.7%)           0 (0.0%)            8 (11.6%)
      3                          27 (56.2%)          3 (14.3%)           30 (43.5%)
      4                           9 (18.8%)          9 (42.9%)           18 (26.1%)
      5                            2 (4.2%)          9 (42.9%)           11 (15.9%)
    -------------------------------------------------------------------------------

    Comment


    • #3
      Hi Jeff,

      Thank you so much for your reply! This worked perfectly. Apologies for the lateness in responding - I saw your reply and immediately went to applying it to my data, rather than responding, which is rather rude of me.

      Thank you again, and sorry for my delayed reply!

      Marissa

      Comment

      Working...
      X