Announcement

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

  • #16
    You are the best. Between this version and the one you did for Matthew Wallace in the related post, I think I might have my perfect version of Table 1 demographics.

    Comment


    • #17
      Hi Jeff -- reviving this thread. I've been working to essentially create the same template I created for dtable, but for table. Since table doesn't have inherent testing as part of the command (unlike dtable), I've tried to recreate that within the do-file creating the style. Here's my style creation code for context:

      Code:
      clear all
      sysuse auto
      drop if rep78==1 | rep78==2
      set table_style table
      
      table (rep78) (foreign), statistic(p50 mpg) statistic(p25 mpg) statistic(p75 mpg)
      
      levelsof rep78, local(levels)
      
      foreach l of local levels {
          quietly: collect r(p), tag(rep78[`l']): ranksum mpg if rep78==`l', by(foreign)
      }
      quietly: collect r(p), tag(rep78[.m]): ranksum mpg, by(foreign)
      
      collect style cell result[p25 p50 p75], nformat("%4.1f")
      
      collect composite define iqr = p25 p75 , delimiter("-") trim
      
      collect style cell result[iqr], sformat("[%s]")
      
      collect composite define median_iqr = p50 iqr , delimiter(" ") trim
      
      collect stars p .1 "*" .01 "**" .001 "***"
      
      collect style header result[stars], level(hide)
      
      collect composite define p_stars = p stars    
      
      collect layout (rep78) (foreign[.m 0 1]#result[median_iqr] result[p_stars])
      
      collect style header foreign, title(hide)
      
      collect style header result[median_iqr], level(hide)
      
      collect label levels result p "PValue", modify
      
      collect style row stack, nobinder spacer
      
      collect style cell border_block, border(right, pattern(nil))
      
      collect label levels result median_iqr "Median [IQR]", modify
      
      collect notes "Median [IQR]"
      
      collect notes "* p<0.05 ** p<0.01 *** p<0.001"
      collect style notes, font(Garamond, size(7) italic)
      collect style cell result[p], nformat(%5.3f)
      collect style cell result[p_stars], halign(left)
      collect style cell, font(Garamond)
      
      collect preview
      
      collect style save style-multimedian, replace
      
      set table_style style-multimedian
      
      table (rep78) (foreign), statistic(p50 mpg) statistic(p25 mpg) statistic(p75 mpg) // style(style-multimedian, override)
      
      //set table_style style-multimedian
      
      collect preview
      I've tried various combinations on those last few lines of code (indicated by the commenting out), but I can't get it working. Below is what it SHOULD look like:


      Code:
      -------------------------------------------------------------------------------------
                                     Total           Domestic            Foreign   PValue  
      -------------------------------------------------------------------------------------
      Repair record 1978                                                                  
        3                 19.0 [17.0-21.0]   19.0 [16.0-21.0]   23.0 [21.0-26.0]   0.040 *
        4                 22.5 [18.0-25.0]   18.0 [15.0-21.0]   25.0 [23.0-25.0]   0.005 **
        5                 30.0 [18.0-35.0]   32.0 [30.0-34.0]   25.0 [18.0-35.0]   0.635  
        Total             20.0 [18.0-25.0]   19.0 [16.0-21.0]   25.0 [21.0-28.0]   0.004 **
      -------------------------------------------------------------------------------------
      Median [IQR]
      * p<0.05 ** p<0.01 *** p<0.001





      But when I apply it as a saved style, I get this:

      Code:
      -----------------------------------------------
                           Domestic   Foreign   Total
      -----------------------------------------------
      Repair record 1978                            
        3                                            
          50th percentile      19.0      23.0    19.0
          25th percentile      16.0      21.0    17.0
          75th percentile      21.0      26.0    21.0
                                                    
        4                                            
          50th percentile      18.0      25.0    22.5
          25th percentile      15.0      23.0    18.0
          75th percentile      21.0      25.0    25.0
                                                    
        5                                            
          50th percentile      32.0      25.0    30.0
          25th percentile      30.0      18.0    18.0
          75th percentile      34.0      35.0    35.0
                                                    
        Total                                        
          50th percentile      19.0      25.0    20.0
          25th percentile      16.0      21.0    18.0
          75th percentile      21.0      28.0    25.0
      -----------------------------------------------
      Median [IQR]
      * p<0.05 ** p<0.01 *** p<0.001


      It occurs to me only now that style's in and of themselves (probably) can't run tests, so I get why there wouldn't be any column for testing. But none of the other formatting re: hiding/combining rows, etc seems to work either. Any ideas?

      I'd also love to solve the testing issue too, if you've got any thoughts on that. Hoping I don't have to create my own program to do that, but I'm thinking that is probably what will be needed.

      Thanks,
      Kevin
      Last edited by Kevin Blaine; 12 Dec 2023, 14:45.

      Comment


      • #18
        HI Jeff -- any chance you can provide any clarification?

        Thanks!

        Comment


        • #19

          table constructs its own layout, a style specified with a call
          set table_style before calling table or with option
          style() in the call to table will not override this
          behavior.

          The p-values from ranksum are not part of the style, they must be
          collected by you or some code separately from table.

          You can force your style and layout on a collection by calling
          Code:
          collect style use style-multimedian, override layout
          after the call to table. This will produce the table you want,
          minus the column "PValue".

          Comment


          • #20
            Thank you, Jeff -- this is so helpful!

            Comment

            Working...
            X