Announcement

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

  • Displaying '%' to the right of 'frequency' instead 'below' it in a Stata output table

    Hello Everone,


    I hope everyone is doing well.

    I have an unusual problem and request. In a typical Stata output of 'tabulate' command, the Stata first displays the 'frequency' and just below it the corresponding %. My Boss wants % to be displayed to the just right of the frequency instead.

    Is there a way of doing that?


    Thank you

    PS: You will save me countless hours of copy and pasting.

  • #2
    That is wired into tabulate and not an optional choice.

    Better news:

    You shouldn't need hours of copying and pasting. This should be perhaps two "find and replace" jobs in any good text editor, word processor or scripting language.

    You should be able to get equivalent output in other commands. I guess that the new table is more flexible.

    Comment


    • #3
      You can save the time of Statalist members who want to help you by following the guidance of the Statalist FAQ which provides advice on effectively posing your questions, posting data, and sharing Stata output.

      I have invented a tabulate example which I am guessing demonstrates the problem you want to solve, then show how to reproduce it with the percentages to the right using the enhanced version of the table command introduced in Stata 17. If you are using an older version of Stata, tell your boss that they need to invest in an upgrade.
      Code:
      sysuse auto
      tabulate rep78 foreign, column
      table (rep78) (foreign result), statistic(frequency) statistic(percent, across(rep78))
      Code:
      . tabulate rep78 foreign, column
      
      +-------------------+
      | Key               |
      |-------------------|
      |     frequency     |
      | column percentage |
      +-------------------+
      
          Repair |
          record |      Car origin
            1978 |  Domestic    Foreign |     Total
      -----------+----------------------+----------
               1 |         2          0 |         2 
                 |      4.17       0.00 |      2.90 
      -----------+----------------------+----------
               2 |         8          0 |         8 
                 |     16.67       0.00 |     11.59 
      -----------+----------------------+----------
               3 |        27          3 |        30 
                 |     56.25      14.29 |     43.48 
      -----------+----------------------+----------
               4 |         9          9 |        18 
                 |     18.75      42.86 |     26.09 
      -----------+----------------------+----------
               5 |         2          9 |        11 
                 |      4.17      42.86 |     15.94 
      -----------+----------------------+----------
           Total |        48         21 |        69 
                 |    100.00     100.00 |    100.00 
      
      . table (rep78) (foreign result), statistic(frequency) statistic(percent, across(rep78))
      
      -------------------------------------------------------------------------------------
                         |                             Car origin                          
                         |        Domestic              Foreign                Total       
                         |  Frequency   Percent   Frequency   Percent   Frequency   Percent
      -------------------+-----------------------------------------------------------------
      Repair record 1978 |                                                                 
        1                |          2      4.17                                 2      2.90
        2                |          8     16.67                                 8     11.59
        3                |         27     56.25           3     14.29          30     43.48
        4                |          9     18.75           9     42.86          18     26.09
        5                |          2      4.17           9     42.86          11     15.94
        Total            |         48    100.00          21    100.00          69    100.00
      -------------------------------------------------------------------------------------
      
      .

      Comment


      • #4
        Originally posted by Nick Cox View Post
        That is wired into tabulate and not an optional choice.

        Better news:

        You shouldn't need hours of copying and pasting. This should be perhaps two "find and replace" jobs in any good text editor, word processor or scripting language.

        You should be able to get equivalent output in other commands. I guess that the new table is more flexible.

        Good Evening Dr Nick,


        Thank you very much for your reply.

        I generally use asdoc command to get outputs in MS Word.

        Could you please elaborate, how can I find and replace in MS word. I want to replace all the % from below the frequency to the right of it in a table.


        Comment


        • #5
          Originally posted by William Lisowski View Post
          You can save the time of Statalist members who want to help you by following the guidance of the Statalist FAQ which provides advice on effectively posing your questions, posting data, and sharing Stata output.

          I have invented a tabulate example which I am guessing demonstrates the problem you want to solve, then show how to reproduce it with the percentages to the right using the enhanced version of the table command introduced in Stata 17. If you are using an older version of Stata, tell your boss that they need to invest in an upgrade.
          Code:
          sysuse auto
          tabulate rep78 foreign, column
          table (rep78) (foreign result), statistic(frequency) statistic(percent, across(rep78))
          Code:
          . tabulate rep78 foreign, column
          
          +-------------------+
          | Key |
          |-------------------|
          | frequency |
          | column percentage |
          +-------------------+
          
          Repair |
          record | Car origin
          1978 | Domestic Foreign | Total
          -----------+----------------------+----------
          1 | 2 0 | 2
          | 4.17 0.00 | 2.90
          -----------+----------------------+----------
          2 | 8 0 | 8
          | 16.67 0.00 | 11.59
          -----------+----------------------+----------
          3 | 27 3 | 30
          | 56.25 14.29 | 43.48
          -----------+----------------------+----------
          4 | 9 9 | 18
          | 18.75 42.86 | 26.09
          -----------+----------------------+----------
          5 | 2 9 | 11
          | 4.17 42.86 | 15.94
          -----------+----------------------+----------
          Total | 48 21 | 69
          | 100.00 100.00 | 100.00
          
          . table (rep78) (foreign result), statistic(frequency) statistic(percent, across(rep78))
          
          -------------------------------------------------------------------------------------
          | Car origin
          | Domestic Foreign Total
          | Frequency Percent Frequency Percent Frequency Percent
          -------------------+-----------------------------------------------------------------
          Repair record 1978 |
          1 | 2 4.17 2 2.90
          2 | 8 16.67 8 11.59
          3 | 27 56.25 3 14.29 30 43.48
          4 | 9 18.75 9 42.86 18 26.09
          5 | 2 4.17 9 42.86 11 15.94
          Total | 48 100.00 21 100.00 69 100.00
          -------------------------------------------------------------------------------------
          
          .


          Thank you very much Willian.

          The command worked as I wanted.

          However, it does not work with the 'asdoc' command.

          Do you know a better and easy way of exporting tables to MS word using the 'table' command?

          Comment


          • #6
            #4 Sorry, but although I said that this should be easy I didn't volunteer how to do it in any particular application! I don't offer advice on MS Word and I don't use asdoc (from SSC).

            Comment


            • #7
              Do you know a better and easy way of exporting tables to MS word using the 'table' command?
              after the table command, you can use collect export. See
              Code:
              help collect export

              Comment


              • #8
                Originally posted by Hemanshu Kumar View Post

                after the table command, you can use collect export. See
                Code:
                help collect export



                Hi Himanshu,


                I want to collect the results of all the tables into a single word file, and I am running the following commands.

                Right now I am using "collect export "results2", as(docx) replace " command but it collects the results of only the last command and not from all the commands.


                I want to collect the output/ results/tables of all the following commands into a single MS word file.


                table () ( response2 ) (), statistic(min age) statistic(mean age) statistic(median age) statistic(max age)
                table () ( response2 ) (), statistic(min tlc) statistic(mean tlc) statistic(median tlc) statistic(max tlc)
                table () ( response2 ) (), statistic(min plt) statistic(mean plt) statistic(median plt) statistic(max plt)
                table () ( response2 ) (), statistic(min bilirubin) statistic(mean bilirubin) statistic(median bilirubin) statistic(max bilirubin)
                table () ( response2 ) (), statistic(min inr) statistic(mean inr) statistic(median inr) statistic(max inr)
                table () ( response2 ) (), statistic(min hb) statistic(mean hb) statistic(median hb) statistic(max hb)

                table () ( response2 ) (), statistic(min albumin) statistic(mean albumin) statistic(median albumin) statistic(max albumin)
                table () ( response2 ) (), statistic(min ast) statistic(mean ast) statistic(median ast) statistic(max ast)
                table () ( response2 ) (), statistic(min alt) statistic(mean alt) statistic(median alt) statistic(max alt)
                table () ( response2 ) (), statistic(min urea) statistic(mean urea) statistic(median urea) statistic(max urea)
                table () ( response2 ) (), statistic(min creatitine) statistic(mean creatitine) statistic(median creatitine) statistic(max creatitine)

                table () ( response2 ) (), statistic(min sodium) statistic(mean sodium) statistic(median sodium) statistic(max sodium)
                table () ( response2 ) (), statistic(min potas) statistic(mean potas) statistic(median potas) statistic(max potas)
                table () ( response2 ) (), statistic(min meldna) statistic(mean meldna) statistic(median meldna) statistic(max meldna)
                table () ( response2 ) (), statistic(min meldcyst) statistic(mean meldcyst) statistic(median meldcyst) statistic(max meldcyst)
                table () ( response2 ) (), statistic(min cystatin) statistic(mean cystatin) statistic(median cystatin) statistic(max cystatin)


                table () ( response2 ) (), statistic(min mapd1) statistic(mean mapd1) statistic(median mapd1) statistic(max mapd1)
                table () ( response2 ) (), statistic(min mapd3) statistic(mean mapd3) statistic(median mapd3) statistic(max mapd3)
                table () ( response2 ) (), statistic(min map) statistic(mean map) statistic(median map) statistic(max map)

                Comment


                • #9
                  Exporting to a MS Word document does not support appending, but you could export each table to the same markdown file (using the append option), and then convert the markdown document to MS Word?

                  Comment

                  Working...
                  X