Announcement

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

  • -table- results to rtf or excel?

    Dear all, I'm wondering if there is an easy way to generate a .rtf or .xlsx file that include results of -table-.

    Code:
    sysuse auto.dta
                table foreign rep78

  • #2
    Code:
    ssc install estout, replace
    Code:
    sysuse auto.dta
    table foreign rep78
    
    *USING ESTPOST +TAB + ESTTAB
    estpost tab foreign rep78
    esttab using myfile.rtf, replace cells(b) unstack compress ///
    nonumbers collab(none) eqlabel(, lhs(`:var lab foreign')) noabbrev ///
    drop(Total) title("                                    `:var lab rep78'")
    Res.:

    Code:
    . table foreign rep78
    
    ----------------------------------------
              |      Repair Record 1978    
     Car type |    1     2     3     4     5
    ----------+-----------------------------
     Domestic |    2     8    27     9     2
      Foreign |                3     9     9
    ----------------------------------------
    
    
    . esttab,  cells(b) unstack compress nonumbers drop(Total) ///
    > collab(none) eqlabel(, lhs(`:var lab foreign')) noabbrev ///
    > title("                                    `:var lab rep78'")
    
                                        Repair Record 1978
    ----------------------------------------------------------------------
                                                                          
    Car type           1         2         3         4         5     Total
    ----------------------------------------------------------------------
    Domestic           2         8        27         9         2        48
    Foreign            0         0         3         9         9        21
    ----------------------------------------------------------------------
    N                 69                                                  
    ----------------------------------------------------------------------

    Comment


    • #3
      Both -putdocx- and -putexcel- support collections if using Stata 17's new -table-. You could give -help table- and -help collect- a read to get started.

      Comment


      • #4
        Another way, which generalises, and cannot be done with Stata 17's new table command, is:
        Code:
        ssc install table1_mc, replace
        
        sysuse auto, clear
        
        *create an indicator variable to show how a binary variable can be summarised in a moment
        generate much_headroom = (headroom>3)
        
        table1_mc, by(foreign) ///
          vars(price conts \ displacement contln %5.0f %4.2f \ weight contn %5.0f \ rep78 cate \ much_headroom bine) ///
          onecol gsdleft(" ×/ ") gsdright(" ") sdleft(" ± ") sdright(" ") nospacelowpercent clear ///
          saving("example Table 1.xlsx", replace)
        
        
        
          +--------------------------------------------------------------------------------+
          |                          Domestic                Foreign               p-value |
          |--------------------------------------------------------------------------------|
          |                          N=52                    N=22                          |
          |--------------------------------------------------------------------------------|
          | Price                    4,782.5 (4,184-6,234)   5,759 (4,499-7,140)    0.30   |
          |--------------------------------------------------------------------------------|
          | Displacement (cu. in.)   217 ×/ 1.49             109 ×/ 1.24           <0.001  |
          |--------------------------------------------------------------------------------|
          | Weight (lbs.)            3317 ± 695              2316 ± 433            <0.001  |
          |--------------------------------------------------------------------------------|
          | Repair Record 1978                                                     <0.001  |
          |    1                     2 (4%)                  0 (0%)                        |
          |    2                     8 (17%)                 0 (0%)                        |
          |    3                     27 (56%)                3 (14%)                       |
          |    4                     9 (19%)                 9 (43%)                       |
          |    5                     2 (4%)                  9 (43%)                       |
          |--------------------------------------------------------------------------------|
          | much_headroom            28 (54%)                2 (9%)                <0.001  |
          +--------------------------------------------------------------------------------+
        Data are presented as mean ± SD  or geometric mean ×/ geometric SD  or median (IQR) for continuous measures, and n (%) for categorical measures.

        Comment


        • #5
          You can also try asdoc. asdoc creates neat table with a much simple syntax, that is to add the word asdoc before any Stata command. See the following example:

          Code:
          ssc install asdoc 
          sysuse auto.dta
          
          asdoc table foreign rep78
          Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	9.0 KB
ID:	1613667


          asdocx is now available
          A more powerful and flexible version of asdoc is now available. I call it asdocx. You may like to check the details here

          https://fintechprofessor.com/asdocx


          Please do remember to cite asdoc. To cite:

          In-text citation
          Tables were created using asdoc, a Stata program written by Shah (2018).

          Bibliography
          Shah, A. (2018). ASDOC: Stata module to create high-quality tables in MS Word from Stata output. Statistical Software Components S458466, Boston College Department of Economics.



          Regards
          --------------------------------------------------
          Attaullah Shah, PhD.
          Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
          FinTechProfessor.com
          https://asdocx.com
          Check out my asdoc program, which sends outputs to MS Word.
          For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

          Comment

          Working...
          X