Announcement

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

  • Alternative display formats for same statistics in -dtable-

    I'm trying to create a table of descriptive statistics for a large data set. I have two variables for which I would like to present the 25th, 50th, and 75th percentiles. One of these is a date variable. (I know that it is unusual to present dates with these statistics, but I have my reasons in this case.) The other one is a count variable. So I would like the results for the date variable to be in %tdnn/dd/YY format, but the count variable in %1.0f. I have tried:
    Code:
    dtable, continuous(order_date, statistic(p25 p50 p75)) nformat(%tdnn/dd/YY) continuous(n_orders, statistic(p25 p50 p75)) nformat(%1.0f)
    but that gives me everything as %1.0, so the dates are basically unreadable to humans. I also tried, pretty much knowing it wouldn't work:
    Code:
    dtable, continuous(order_date, statistic(p25 p50 p75) nformat(%tdnn/dd/YY)) continuous(n_orders, statistic(p25 p50 p75) nformat(%1.0f))
    But, as I expected, I got
    Code:
    option nformat() not allowed
    in option continuous()
    r(198)
    How can I do this?

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float record_date int number_of_events
    23100  2
    23310  3
    23140  4
    22779  1
    22741  7
    23014  7
    23198  4
    23103  1
    22882  1
    22685  2
    23267  1
    22680  3
    22987  3
    22973  3
    22707  1
    23323  1
    23124  2
    23120  1
    23071  3
    23274 12
    22718  1
    22729  1
    22660  1
    23119 10
    23022  2
    23135  1
    22683 12
    23308  5
    23219  2
    23062  1
    22942  1
    23314  1
    23035  2
    22965  1
    23125  1
    22746  1
    22986  1
    23228  1
    23251 15
    23199  1
    23099  5
    22747  5
    22629 19
    22642  1
    23187  1
    23288  2
    23168  1
    23019  3
    22647  1
    23015  4
    23114  4
    23015  1
    22673  7
    22851 10
    23287  1
    23154  1
    22715  5
    23316  1
    23316  2
    22607  1
    22690  2
    22826  3
    22767 11
    23040  1
    23126  1
    23327  6
    23323 59
    23155  1
    22612  1
    22896  7
    22698  3
    22641  1
    23115  1
    23068  2
    23215  3
    23070  1
    23224  1
    23201  1
    23285  1
    22927  1
    22984  8
    23044  1
    22951  1
    22708  4
    23091  8
    23126  7
    22939 23
    22936  1
    23070  2
    23317 18
    22783  2
    22796  2
    22847  9
    22732  9
    22752  2
    22931  1
    23178  3
    23316  1
    23236  1
    22833  1
    end
    format %td record_date


  • #2
    The percentiles can also be denoted as q1, q2 and q3 - so you may use these in place of p25, p50 and p75. I am sure it is possible by defining some composite statistics, but my knowledge of dtable is still basic.

    Code:
    dtable, continuous(record_date, statistic(p25 p50 p75)) nformat(%tdnn/dd/YY p25 p50 p75) ///
    continuous(number_of_events, statistic(q1 q2 q3)) nformat(%1.0f q1 q2 q3)
    Res.:

    Code:
    . dtable, continuous(record_date, statistic(p25 p50 p75)) nformat(%tdnn/dd/YY p25
    >  p50 p75) ///
    > continuous(number_of_events, statistic(q1 q2 q3)) nformat(%1.0f q1 q2 q3)
    
    ----------------------------------------
                             Summary        
    ----------------------------------------
    N                                    100
    record_date      5/16/22 1/27/23 6/21/23
    number_of_events                   1 2 4
    ----------------------------------------

    Comment


    • #3
      Thank you so much!!!

      Comment

      Working...
      X