Announcement

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

  • Exporting Tabstat to MS Word

    Hello!

    I've been trying to export my table in stata to a word document but it does not work. The table I want to save is :

    tabstat sales logsales agefirm sizeoflocality k30 j30a, statistics( mean sd min max sum ) by(femfirm) varwidth(10) columns(statistics)



  • #2
    Here is a way using estout from SSC. Remove the asterisk in the first line to install.

    Code:
    *ssc install estout, replace
    sysuse auto, clear
    estpost tabstat mpg weight turn, statistics( mean sd min max sum) by(foreign) columns(statistics)
    esttab using myfile.rtf, replace cells("mean(fmt(a2)) sd(fmt(a2)) min(fmt(a2)) max(fmt(a2)) sum(fmt(a2))") nonum mlab(none)
    Res.:

    Code:
    . esttab, replace cells("mean(fmt(a2)) sd(fmt(a2)) min(fmt(a2)) max(fmt(a2)) sum(fmt(a2))") nonum mlab(none)
    
    -----------------------------------------------------------------------------
                         mean           sd          min          max          sum
    -----------------------------------------------------------------------------
    Domestic                                                                     
    mpg                  19.8         4.74           12           34         1031
    weight             3317.1        695.4         1800         4840       172490
    turn                 41.4         3.97           31           51         2155
    -----------------------------------------------------------------------------
    Foreign                                                                      
    mpg                  24.8         6.61           14           41          545
    weight             2315.9        433.0         1760         3420        50950
    turn                 35.4         1.50           32           38          779
    -----------------------------------------------------------------------------
    Total                                                                        
    mpg                  21.3         5.79           12           41         1576
    weight             3019.5        777.2         1760         4840       223440
    turn                 39.6         4.40           31           51         2934
    -----------------------------------------------------------------------------
    N                      74                                                    
    -----------------------------------------------------------------------------

    Comment


    • #3
      You can use asdoc to export result from any Stata command

      Code:
      ssc install asdoc
      sysuse auto, clear
      asdoc tabstat mpg weight turn, statistics( mean sd min max sum) by(foreign) columns(statistics)
      Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	31.9 KB
ID:	1638137


      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


      • #4
        Thank you! I'll try them and see if they work.

        Comment


        • #5
          Hello!

          I've got the same problem as Klaudia, however the proposed solution does not work for me. I might be doing something wrong, though...
          I'm trying to output this command to word:

          tabstat Headcountindex Povertygapratio PovertySeverity WattsIndex MC SelfEmploymentrate Unemployment CPI GDPPC LiteracyRate GiniIndex, by(Country) format(%9.3fc)

          Thanks for your help!

          Comment


          • #6
            Show us the exact commands that you ran and the resulting output. Post these within CODE delimiters:

            ([Click Toggle Advanced Editor -> #] and post the output between \([\)\(\text{CODE}\)\(]\) and \([\)\(\text{/CODE}\)\(]\)).
            Last edited by Andrew Musau; 04 Jan 2023, 07:33.

            Comment


            • #7
              Attaullah Shah Thanks for the asdoc to export word. In the example that you have provided, how do you format the mean to zero dec or 1 dec place. I use the code you have provided and get the table as given. I then format the mean and min(as there are 3 zeros and want to get rid of them).Please help with how you format the decimals as i get error message "error in the stat (mean(fmt(a2) option". Here is my code
              Code:
               ssc install asdoc sysuse auto, clear asdoc tabstat mpg weight turn, statistics( mean sd min max sum) by(foreign) columns(statistics) asdoc tabstat mpg weight turn, statistics( mean(fmt(a2)) sd min(fmt(a2)) max sum) by(foreign) columns(statistics)
              Last edited by Duncan Mphande; 24 May 2023, 09:14.

              Comment


              • #8
                Hello Duncan
                You can format each column separately in asdocx, see details here https://fintechprofessor.com/asdocx/decimal-points/, sub-topic 4, (Different decimal points for specific columns)
                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


                • #9
                  Hello! I have been trying to output to word using asdoc and I get a certain error of mismatch please help. The error: . * Create a summary table using tabstat
                  . tabstat income_source_pct_1 income_source_pct_2 income_source_pct_3 income_source_pct_4
                  > income_source_pct_5, ///
                  > statistics(N obs mean sd min max) nototal
                  nothing to display

                  .
                  . * Export table to Word document using asdoc
                  . asdoc, replace title("Summary of Income Source pct_1 to 5") label
                  type mismatch
                  r(109);
                  The syntax:
                  * Rename variables for export
                  rename income_source_pct_1 income_source_pct_1
                  rename income_source_pct_2 income_source_pct_2
                  rename income_source_pct_3 income_source_pct_3
                  rename income_source_pct_4 income_source_pct_4
                  rename income_source_pct_5 income_source_pct_5

                  * Set custom variable labels
                  lab var income_source_pct_1 "Income Source pct_1"
                  lab var income_source_pct_2 "Income Source pct_2"
                  lab var income_source_pct_3 "Income Source pct_3"
                  lab var income_source_pct_4 "Income Source pct_4"
                  lab var income_source_pct_5 "Income Source pct_5"

                  * Create a summary table using tabstat
                  tabstat income_source_pct_1 income_source_pct_2 income_source_pct_3 income_source_pct_4 income_source_pct_5, ///
                  statistics(N obs mean sd min max) nototal

                  * Export table to Word document using asdoc
                  asdoc, replace title("Summary of Income Source pct_1 to 5") label

                  Comment

                  Working...
                  X