查看原文
其他

一文读懂stata表格数据导入word与Excel新命令:tab2xl and tab2docx

导读
 

It’s summer time, which means we have interns working at StataCorp again. Our newest intern, Chris Hassell, was tasked with updating my community-contributed command tab2xl with most of the suggestions that blog readers left in the comments. Chris updated tab2xl and wrote tab2docx, which writes a tabulation table to a Word file using the putdocx command.


外部命令下载安装


To install or update your tab2xl command, type

. net install http://www.stata.com/users/kcrow/tab2xl, replace


To install the new tab2docx command, type

. net install http://www.stata.com/users/kcrow/tab2docx


备注:这是一个Stata15.1版本命令,您可能无法在Stata15.0及以下版本运行!


tab2xl



tab2xl will perform both one-way and two-way tabulation replicas with default formatting and labeling based on the data given. This command does not support string variables in two-way form. 

tab2xl was written for the Stata blog.  You can view the blog at     http://blog.stata.com


tab2xl now allows weights, ifin, formatting of the cells, and two-way tabulations. Once installed, you can type

. sysuse auto, clear
(1978 Automobile Data).
. tab2xl rep78 foreign in 1/50 [fweight=mpg] using testfile, col(1) row(1)
file testfile.xlsx saved


结果为:


tab2docx


To write the table to a Word document, you must first open a .docx file using the command putdocx begin, type your tab2docx command to append the table to your file, and then save the document using putdocx save filename


For example, typing

. sysuse auto, clear(1978 Automobile Data). putdocx begin . tab2docx rep78 in 1/50 [fweight=mpg] . putdocx save testfile.docx


结果为:


来源:Stata Blog,原文链接:https://blog.stata.com/2018/06/07/export-tabulation-results-to-excel-update/


您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存