Announcement

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

  • Announcing improved table1_mc: Stata module to create "Table 1.docx" of baseline characteristics for a manuscript

    Dear Statalisters,

    I have just posted an updated version of my program table1_mc on SSC. To make use of the ability to put the output into a docx file, version 15.1 is required, otherwise version 14.2.

    . sysuse auto, clear
    . generate much_headroom = (headroom>3)
    . table1_mc, by(foreign) vars(price conts \ weight contn %5.0f \ rep78 cate \ much_headroom bin) nospace clear
    . table1_mc_dta2docx using "C:\example Table 1.docx", replace tablenumber("Table 1.") tabletitle("Car characteristics by car type.") footnote("Foreign cars included Audi, Datsun, Toyota and VW cars.")
    Click image for larger version

Name:	output for Statalist Dec 2017.png
Views:	1
Size:	33.7 KB
ID:	1420931



    PS. First announcement was in May 2017 https://www.statalist.org/forums/for...r-a-manuscript

  • #2
    Congratulations, really awesome!

    I have just two questions:

    First, I wonder whether it is possible to add a * sign to p-values, crossed with, say, the information about the respective test on the footnote, such as p = 0.07* and in the foootnote: * = Pearson chi-square; ** Mann-Whitney, etc.

    Second, I know we may add the total and get, say, the mean value for the total sample, but I wonder whether we could get a column with the "available" cases according to each variable.

    Thank you for this program.
    Best regards,

    Marcos

    Comment


    • #3
      Hi Marcos

      I'm glad you like the program!

      The following option is probably best to use to say what test was used.
      test include column describing the significance test used

      As for adding available cases, here's the beginnings of how you could do that:
      sysuse auto, clear
      table1_mc, by(foreign) vars(price conts \ weight contn %5.0f \ rep78 cate) extraspace clear total(before)
      browse
      rename N_T AvailableCases
      drop *T
      table1_mc_dta2docx using "C:\example Table 1.docx", replace

      Cheers,
      Mark

      Comment


      • #4
        Thank you for the tips, Mark. I’m on a trip and, as soon as I come back to ‘my Stata’, I’ll add the options you suggested.

        Again, congratulations for such a helpful program.
        Best regards,

        Marcos

        Comment


        • #5
          Mark Chatfield : I wonder whether it is possible to abridge a specific command.

          For example: instead of typing each variable name, then selecting for each one whether it is, say, "countn", than formating for each one the decimals, is there some way we could select a given specification for a row of variables, as we do when using, say, var1-var50 in "regular" Stata.

          I tried with - vars(var1-var100 countn %5.1f), to no avail.

          Considering I'd have to type 50 variables plus the selected test plust the format for decimals, it would give quite a big line for the command.

          Thanks in advance.
          Best regards,

          Marcos

          Comment


          • #6
            Hi Marcos

            Not easy for me to do that, but easy for you to do that:

            . foreach v of var var1-var100 {
            . local vlist "`vlist' `v' contn %5.1f "
            . }
            . table1_mc, vars(`vlist')

            ps There is the format option to set the default for formatting continuous variables which you might like to use.

            Cheers,
            Mark

            Comment


            • #7
              Hi Mark Chatfield , thank you for the reply and the command. Perhaps there is something missing. I tried it with the example below, and I still keep getting just the first variable:

              Code:
              . sysuse auto
              (1978 Automobile Data)
              
              . foreach v of var price-displacement {
                2. local vlist "`vlist' `v' contn %5.1f "
                3. }
              
              . table1_mc, by(foreign) vars(`vlist')
              
                +--------------------------------+
                | factor   N_0   N_1   m_0   m_1 |
                |--------------------------------|
                | Price     52    22     0     0 |
                +--------------------------------+
                 N_ ... #records used below,   m_ ... #records not used
               
                +------------------------------------------+
                |          Domestic    Foreign     p-value |
                |------------------------------------------|
                |          N=52        N=22                |
                |------------------------------------------|
                | Price    6072.4 ()   6384.7 ()    0.68   |
                +------------------------------------------+
              Data are presented as mean (SD).
              I wonder whether some extra fiddling with the code could solve the problem.

              Thanks in advance.
              Best regards,

              Marcos

              Comment


              • #8
                Hi Marcos

                It just needs the backslash (\) added

                . local vlist "`vlist' `v' contn %5.1f "

                . display "`vlist'"
                would have revealed this.

                Cheers,
                Mark

                Comment


                • #9
                  Sorry, the backslash after %5.1f and before " gets deleted whenever I save

                  Comment


                  • #10
                    Mark Chatfield: Thank you for the helpful command. The added backlash provided the desired output:

                    Code:
                    . sysuse auto
                    . foreach v of var price-displacement {
                      2. local vlist "`vlist' `v' contn %5.1f \"
                      3. }
                    
                    . table1_mc, by(foreign) vars(`vlist')
                    
                      +------------------------------------------------+
                      | factor                   N_0   N_1   m_0   m_1 |
                      |------------------------------------------------|
                      | Price                     52    22     0     0 |
                      |------------------------------------------------|
                      | Mileage (mpg)             52    22     0     0 |
                      |------------------------------------------------|
                      | Repair Record 1978        48    21     4     1 |
                      |------------------------------------------------|
                      | Headroom (in.)            52    22     0     0 |
                      |------------------------------------------------|
                      | Trunk space (cu. ft.)     52    22     0     0 |
                      |------------------------------------------------|
                      | Weight (lbs.)             52    22     0     0 |
                      |------------------------------------------------|
                      | Length (in.)              52    22     0     0 |
                      |------------------------------------------------|
                      | Turn Circle (ft.)         52    22     0     0 |
                      |------------------------------------------------|
                      | Displacement (cu. in.)    52    22     0     0 |
                      +------------------------------------------------+
                       N_ ... #records used below,   m_ ... #records not used
                     
                      +----------------------------------------------------------------------+
                      |                          Domestic          Foreign           p-value |
                      |----------------------------------------------------------------------|
                      |                          N=52              N=22                      |
                      |----------------------------------------------------------------------|
                      | Price                    6072.4 (3097.1)   6384.7 (2621.9)    0.68   |
                      |----------------------------------------------------------------------|
                      | Mileage (mpg)            19.8 (4.7)        24.8 (6.6)        <0.001  |
                      |----------------------------------------------------------------------|
                      | Repair Record 1978       3.0 (0.8)         4.3 (0.7)         <0.001  |
                      |----------------------------------------------------------------------|
                      | Headroom (in.)           3.2 (0.9)         2.6 (0.5)          0.011  |
                      |----------------------------------------------------------------------|
                      | Trunk space (cu. ft.)    14.8 (4.3)        11.4 (3.2)         0.002  |
                      |----------------------------------------------------------------------|
                      | Weight (lbs.)            3317.1 (695.4)    2315.9 (433.0)    <0.001  |
                      |----------------------------------------------------------------------|
                      | Length (in.)             196.1 (20.0)      168.5 (13.7)      <0.001  |
                      |----------------------------------------------------------------------|
                      | Turn Circle (ft.)        41.4 (4.0)        35.4 (1.5)        <0.001  |
                      |----------------------------------------------------------------------|
                      | Displacement (cu. in.)   233.7 (85.3)      111.2 (24.9)      <0.001  |
                      +----------------------------------------------------------------------+
                    Data are presented as mean (SD).
                    However, for a reason I cannot envisage, the .docx file gets an error.

                    We get the results of "make" variable" (and I didn't ask for that in the command), the firts two lines are in bold, and we don't get the results by "foreign", according to the command I typed.

                    Please see below.

                    The output in Word is like this:

                    Table 6. Car characteristics by car type.
                    AMC Concord 4,099 22 3 2.5 11 2,930 186 40 121 3.58 Domestic
                    AMC Pacer 4,749 17 3 3.0 11 3,350 173 40 258 2.53 Domestic
                    AMC Spirit 3,799 22 . 3.0 12 2,640 168 35 121 3.08 Domestic
                    Buick Century 4,816 20 3 4.5 16 3,250 196 40 196 2.93 Domestic
                    Buick Electra 7,827 15 4 4.0 20 4,080 222 43 350 2.41 Domestic
                    Buick LeSabre 5,788 18 3 4.0 21 3,670 218 43 231 2.73 Domestic
                    Buick Opel 4,453 26 . 3.0 10 2,230 170 34 304 2.87 Domestic
                    Buick Regal 5,189 20 3 2.0 16 3,280 200 42 196 2.93 Domestic
                    Buick Riviera 10,372 16 3 3.5 17 3,880 207 43 231 2.93 Domestic
                    Buick Skylark 4,082 19 3 3.5 13 3,400 200 42 231 3.08 Domestic
                    Cad. Deville 11,385 14 3 4.0 20 4,330 221 44 425 2.28 Domestic
                    Cad. Eldorado 14,500 14 2 3.5 16 3,900 204 43 350 2.19 Domestic
                    Cad. Seville 15,906 21 3 3.0 13 4,290 204 45 350 2.24 Domestic
                    Chev. Chevette 3,299 29 3 2.5 9 2,110 163 34 231 2.93 Domestic
                    Chev. Impala 5,705 16 4 4.0 20 3,690 212 43 250 2.56 Domestic
                    Chev. Malibu 4,504 22 3 3.5 17 3,180 193 31 200 2.73 Domestic
                    I wonder whether you know what is happening and would kindly provide a solution for this.

                    Thank you in advance.
                    Best regards,

                    Marcos

                    Comment


                    • #11
                      Mark Chatfield : I tried to use table1_mc_dta2docx in another computer (also Windows 10), and I got the same odd display. I wonder whether this is a bug or I’m missing something.

                      Thanks in advance.
                      Last edited by Marcos Almeida; 17 Jan 2018, 14:52.
                      Best regards,

                      Marcos

                      Comment


                      • #12
                        Hi Marcos, if you would like to email me directly (my email address can be found on http://researchers.uq.edu.au/researcher/20374), I can look into this if you haven't solved it yet. Please provide me with all the Stata syntax you used.

                        Comment


                        • #13
                          Hi all
                          I've uploaded a newer version of table1_mc. Along with one bug fix (N and m now reported correctly when row -rather than the default column- percentages), I've expanded the Remarks section to mention Susan Donath's new -baselinetable- command (Stata Journal 18-2), and a command -tabxml- for use in surveys:

                          Remarks

                          table1_mc is an extension and modification of Phil Clayton's table1 command.

                          Other user written commands that do similar things include:
                          baselinetable ... very nice, but no p-values. Can use any statistics from summarise, can't report geometric
                          mean and geometric SD.
                          tabout ... http://tabout.net.au/docs/home.php
                          sumtable ... two stats in two (not one) columns, generally not as flexible, no p-values
                          partchart ... quite similar but strangely doesn't seem to express IQR as (Q1-Q3), reporting instead the
                          difference between the two quartiles
                          tabxml ... survey data frequencies and/or % for categorical variables, means and SE / CI for continuous
                          variables. To avoid matsum error message: . net install sg100, from(http://www.stata.com/stb/stb47)

                          See also
                          http://blog.stata.com/2017/04/06/cre...ts-for-arbitrary-variables/

                          While table1_mc does not report an effect size (e.g. differences in means, medians or proportions) &
                          associated 95% CI for a variable when there are 2 or more groups, readers might consider calculating and
                          reporting these also.

                          Comment


                          • #14
                            Dear Mark,

                            Could you please illustrate how to get the row percentages (rather than the default column percentage) for categorical variables? From the example above :
                            table1_mc, by(foreign) vars(price conts \ weight contn %5.0f \ rep78 cate \ much_headroom bin) ?

                            Thank you!
                            Saranya

                            Comment


                            • #15
                              Hi Saranya
                              The answer is clearly documented in the help file.
                              . table1_mc, by(foreign) vars(price conts \ weight contn %5.0f \ rep78 cate \ much_headroom bin) catrowperc
                              BW,
                              Mark

                              Comment

                              Working...
                              X