Stata 15 新功能:產生Word文件,包含統計結果

Stata recently released a new version of Stata 15. Although I don’t know many new statistical models and functions, what I am most looking forward to is that Stata 15 can directly output Word files in the program, including file content and statistical results.

The following figure is a demonstration of this function on the official Stata website .

You can see that the upper part is the text description, which supports various text formats, and the lower part can directly output pictures and tables. Such a feature will greatly increase the productivity of using Stata.

The syntax for generating this file also maintains Stata’s consistent style of simplicity and is not too complicated.

sysuse auto, replace

putdocx begin

// Create a paragraph
putdocx paragraph
putdocx text ("putdocx "), bold
putdocx text ("can add formatted text to a paragraph. You can ")
putdocx text ("italicize, "), italic
putdocx text ("strikeout, "), strikeout
putdocx text ("underline"), underline
putdocx text (", sub/super script")
putdocx text ("2 "), script(sub)
putdocx text (", and ")
putdocx text("shade"), shading("blue")
qui sum mpg
local sum : display %4.2f `r(sum)'
putdocx text (". Also, you can easily add Stata results to your paragraph (mpg total = `sum')")

// Embed a graph
histogram rep
graph export hist.png, replace
putdocx paragraph, halign(center)
putdocx image hist.png

// Embed Stata output
putdocx paragraph
putdocx text ("Embed the output from a regression command into your docx file.")
regress mpg price
putdocx table mytable = etable

// Embed Stata dataset
putdocx paragraph
putdocx text ("Embed the data in Stata's memory into a table in your docx file.")
statsby Total=r(N) Average=r(mean) Max=r(max) Min=r(min), by(foreign): summarize mpg
rename foreign origin
putdocx table tbl1 = data("Origin Total Average Max Min"), varnames
        border(start, nil) border(insideV, nil) border(end, nil)

putdocx save myreport.docx, replace

When I have the funds to upgrade to Stata 15, I will share the detailed experience with you.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top
Verified by MonsterInsights