Announcement

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

  • Export two-way table to excel

    I'm trying to export a table like this into excel. I want the table in excel to show up exactly like how it is in the picture below. Any help/suggestions appreciated.

    Example code:

    Code:
     clear
    input int growth str6 meds
    0 regular
    0 exp
    0 exp
    0 regular
    1 regular
    1 regular
    1 exp
    1 exp
    1 exp
    end  
    
    tab growth meds, col
    Attached Files
    Last edited by Amber Pong; 12 Jan 2023, 14:08.

  • #2
    What version of Stata are you using?

    With Stata 17 this is a start; much more customization is available using the collect suite of commands described in the Stata Customizable Tables And Collected Results Reference Manual PDF included in your Stata 17 installation and accessible from Stata's Help menu.
    Code:
    table (growth) (meds), statistic(frequency) statistic(percent, across(growth))
    collect export "~/Downloads/example.xlsx"
    Click image for larger version

Name:	example.png
Views:	1
Size:	55.8 KB
ID:	1697045
    Last edited by William Lisowski; 12 Jan 2023, 15:06.

    Comment


    • #3
      William Lisowski Stata 15

      Comment


      • #4
        Sorry, can't help you there. In the future, do be sure to follow the guidance in the Statalist FAQ linked to from the top of the page, which notes that the assumption here is that the current version of Stata is suitable, and the poster should specify when that is not the case.

        Comment


        • #5
          ok did not know that

          Comment


          • #6
            There are many user-written commands for exporting tables to Excel or Word, for example, asdoc, outtable, tabout, estout, logout, outreg, outreg2, partchart, publish. You can try to search, install and apply it/them to your data management.

            Comment


            • #7
              I'm not sure to what extent these commands support Excel, I find that many of them do not allow you to save results in Excel file. Fortunately, an alternative is -tab2xl-, see here: https://blog.stata.com/2018/06/07/ex...-excel-update/, and you can try
              Code:
              net install http://www.stata.com/users/kcrow/tab2xl, replace
              tab2xl growth meds using t2.xls, row(1) col(1) percentage

              Comment


              • #8
                you can use user written package table1_mc then edit the table as appropriate
                ssc install table1_mc
                table1_mc, by (meds) vars(growth cate %3.1f\) nospace onecol total(before) saving ("example.xlsx", replace)

                Comment

                Working...
                X