打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Stata:毕业论文大礼包 B——神速实证结果输出之搜狗短语

作者:王美庭 (中南民族大学经济学院)

Stata连享会 计量专题  || 公众号合集

连享会-内生性专题现场班-2019.11.14-17

特别说明

文中包含的链接在微信中无法生效。请点击本文底部左下角的【阅读原文】,请点击【原文链接】

Stata 结果输出系列推文:

1. 本文目的

几天前,连享会发布了大福利推文 —— 「Stata:毕业论文大礼包 A——实证结果输出命令大比拼」,系统梳理了 Stata 各种常用的实证结果输出命令(含 Word 表格输出和 LaTeX 代码输出),并对它们的优劣进行了评价。这篇推文被转发了 800 多次,浏览量超过 5000 次,受欢迎程度可见一斑。

然而,人的需求总是在不断提升。大家发来信息问我们,能否敲几个字母就能实现实证结果的快速输出?我们捉摸了一下,还真完美解决了这个有点看似有点过分的需求。

解决方法出奇地简单 —— 使用 「搜狗短语」!

这在此前的推文「Stata+搜狗=?=效率!(搜狗自定义短语)」 已经进行了详细的说明。

比如,我们只需用 搜狗输入法 在中文模式下输入 sysuse,按下空格键,就可以输入 sysuse auto.dta, clear 这条对于 Stata 用户而言记为熟悉的语句。如果输入 sysuse 后,再按下数字键 2,就可以自动输入 sysuse 'nlsw88.dta', clear 这条命令。

本文将继续扩展搜狗短语的功能范围,目的在于:把文章「Stata:毕业论文大礼包 A——实证结果输出命令大比拼」 中所涉及的所有命令变成搜狗自定义短语,供大家进行套用,以提高大家的工作效率。

另外,大家使用该方法在快速的键出 Stata 各种实证结果输出命令的同时,还能根据命令主体后面的注释,知道该命令的特点和存在的问题,从而能帮大家更快的选择合适自己的命令。

2. 实际效果演示

在正式介绍之前,我们先看看使用 搜狗短语 快速输入 Stata 大块命令的效果:

  • 用 asdoc 输出描述性统计 Word 表格

    关键字:asdocsum
  • 用 esttab 输出分组 T 均值检验 Word 表格

    关键字:esttabttest
  • 用 corr2docx 输出相关系数矩阵 Word 表格

    关键字:corrdocx

    用 outreg2 输出回归结果 Word 表格

    关键字:outregreg

    用 esttab 输出所有以上表格至一个 Word 文件里


    用 esttab 输出所有以上表格至一个 .tex 文件里


3. 各种自定义短语关键字及其含义

最后一节的附件中,包含了所有搜狗自定义短语。为了让大家能快速的使用,下面用表格的形式列出其中所有的自定义短语关键字及其含义。

关键字所用命令输出表格类型
asdocsumasdoc sum ...描述性统计 Word 输出
sumdocxsum2docx ...描述性统计 Word 输出
outregsumoutreg2 using Myfile, sum(detail)...描述性统计 Word 输出
esttabsum(estpost summarize ...)(esttab ...)描述性统计 Word 输出
outregsumloutreg2 using Myfile, sum(detail)...描述性统计 LaTeX 输出
esttabsuml(estpost summarize ...)(esttab ...)描述性统计 LaTeX 输出
asdocttestasdoc ttest ...分组 T 均值检验 Word 输出
tdocxt2docx ...分组 T 均值检验 Word 输出
logoutttestlogout, save(Myfile) word replace: ttable2 ...分组 T 均值检验 Word 输出
esttabttest(estpost ttest ...)(esttab ...)分组 T 均值检验 Word 输出
logoutttestllogout, save(Myfile) tex replace: ttable2 ...分组 T 均值检验 LaTeX 输出
esttabttestl(estpost ttest ...)(esttab ...)分组 T 均值检验 LaTeX 输出
asdoccorrasdoc cor ...相关系数矩阵 Word 输出
corrdocxcorr2docx ...相关系数矩阵 Word 输出
logoutcorrlogout, save(Myfile) word replace : pwcorr ...相关系数矩阵 Word 输出
esttabcorr(estpost correlate ...)(esttab ...)相关系数矩阵 Word 输出
logoutcorrllogout, save(Myfile) tex replace : pwcorr ...相关系数矩阵 LaTeX 输出
esttabcorrl(estpost correlate ...)(esttab ...)相关系数矩阵 LaTeX 输出
asdocregasdoc reg ...回归结果 Word 输出
regdocxreg2docx ...回归结果 Word 输出
outregreg(reg ...)(outreg2 using Myfile ...)回归结果 Word 输出
esttabreg(reg ...)(esttab ...)回归结果 Word 输出
outregregl(reg ...)(outreg2 using Myfile ...)回归结果 LaTeX 输出
esttabregl(reg ...)(esttab ...)回归结果 LaTeX 输出
esttab-导出所有表格至一个 Word 文件
esttabl-导出所有表格至一个 .tex 文件

注意:搜狗的快捷短语的关键字只能是大小写英文字母,不能有空格、数字、下划线等其他字符。

4. 下载定义好的短语

特别说明: 文中包含的链接在微信中无法生效。请点击本文底部左下角的【阅读原文】。

所有搜狗自定义短语.do

使用方法

参照 「Stata+搜狗=?=效率!(搜狗自定义短语)」 设定搜狗短语,将如下代码贴入搜狗短语设定文件中即可。

  1. asdocsum,1=

  2. *-----------------描述性统计 Word 输出(by asdoc)-------------------------------

  3. local varlist 'wage age race married grade collgrad south union occupation'

  4. asdoc sum `varlist', save(Myfile.doc) replace ///

  5. stat(N mean sd min p50 max) dec(3) ///

  6. title(asdoc_Table: Descriptive statistics)

  7. /*

  8. 1. 在将结果导入到 word 的途中,Stata 界面也能看到相应的结果。

  9. 2. 该命令不支持中文。

  10. 3. 若有字符串变量,命令会报错。

  11. */

  12. sumdocx,1=

  13. *-----------------描述性统计 Word 输出(by sum2docx)-------------------------------

  14. local varlist 'wage age race married grade collgrad south union occupation'

  15. sum2docx `varlist' using Myfile.docx,replace ///

  16. stats(N mean(%9.2f) sd(%9.3f) min(%9.2f) median(%9.2f) max(%9.2f)) ///

  17. title(sum2docx_Table: Descriptive statistics)

  18. /*

  19. 1. 在将结果导入到 word 的途中,Stata 界面不能看到相应的结果。

  20. 2. 该命令支持中文。

  21. 3. 若有字符串变量,命令会报错。

  22. 4. 能分别设置每个统计量的小数点位数。

  23. */

  24. outregsum,1=

  25. *-----------------描述性统计 Word 输出(by outreg2)-------------------------------

  26. local varlist 'wage age race married grade collgrad south union occupation'

  27. outreg2 using Myfile, sum(detail) replace word eqkeep(N mean sd min p50 max) ///

  28. fmt(f) keep(`varlist') sortvar(wage age grade) ///

  29. title(outreg2_Table: Descriptive statistics)

  30. /*

  31. 1. 在将结果导入到 word 的途中,Stata 界面能看到相应的结果。

  32. 2. 该命令不支持中文。

  33. 3. 若有字符串变量,命令会在窗口说明什么变量是字符型,并在报告列表中自动剔除该变量。

  34. 4. 支持变量排序。

  35. */

  36. esttabsum,1=

  37. *-----------------描述性统计 Word 输出(by esttab)-------------------------------

  38. local varlist 'wage age race married grade collgrad south union occupation'

  39. estpost summarize `varlist', detail

  40. esttab using Myfile.rtf, ///

  41. cells('count mean(fmt(2)) sd(fmt(2)) min(fmt(2)) p50(fmt(2)) max(fmt(2))') ///

  42. noobs compress replace title(esttab_Table: Descriptive statistics)

  43. /*

  44. 1. 在将结果导入到 word 的途中,Stata 界面能看到相应的结果。

  45. 2. 该命令不支持中文(有些教程说可以对中文进行 gb18030 转码后导入,但本文试验不成功)。

  46. 3. 若有字符串变量,命令仍会直接运行,在输出列表中字符型变量名会写上去,但后面的统计量为空白。

  47. 4. 能分别设置每个统计量的小数点位数。

  48. */

  49. asdocttest,1=

  50. *-----------------分组 T 均值检验 Word 输出(by asdoc)---------------------------

  51. local common_exp 'save(Myfile.doc) by(south) stat(obs mean p)'

  52. asdoc ttest wage, `common_exp' replace title(asdoc_Table: T_test by group)

  53. asdoc ttest age, `common_exp' rowappend

  54. asdoc ttest race, `common_exp' rowappend

  55. asdoc ttest married, `common_exp' rowappend

  56. asdoc ttest grade, `common_exp' rowappend

  57. asdoc ttest collgrad, `common_exp' rowappend

  58. asdoc ttest union, `common_exp' rowappend

  59. /*

  60. 1. 每次只能检验一个变量, 当然它可以通过 rowappend 进行叠加,但这样麻烦不少。

  61. 2. 内容不完整,本身没有也无法添加 MeanDiff 一列。

  62. */

  63. tdocx,1=

  64. *-----------------分组 T 均值检验 Word 输出(by t2docx)--------------------------

  65. local varlist 'wage age race married grade collgrad union'

  66. t2docx `varlist' using Myfile.docx,replace ///

  67. not by(south) title(t2docx_Table: T_test by group)

  68. /*

  69. 1. 表格报告的内容剔除了所输入变量中包含缺漏值的观测值,且该操作无法被禁止。

  70. 2. 支持中文。

  71. 3. 有 MeanDiff 一列,并默认以'* p < 0.1 ** p < 0.05 *** p < 0.01'的方式标注星号。

  72. */

  73. logoutttest,1=

  74. *-----------------分组 T 均值检验 Word 输出(by logout)--------------------------

  75. ! taskkill /F /IM WINWORD.EXE /T

  76. local varlist 'wage age race married grade collgrad union'

  77. logout, save(Myfile) word replace: ttable2 `varlist', by(south)

  78. /*

  79. 1. 能一次性分组 T 均值检验所有变量

  80. 2. 有 MeanDiff 一列,并默认以'* p < 0.1 ** p < 0.05 *** p < 0.01'的方式标注星号

  81. 3. 该命令不能书写表格标题。

  82. */

  83. esttabttest,1=

  84. *-----------------分组 T 均值检验 Word 输出(by esttab)--------------------------

  85. local varlist 'wage age race married grade collgrad union'

  86. estpost ttest `varlist', by(south)

  87. esttab using Myfile.rtf, ///

  88. cells('N_1 mu_1(fmt(3)) N_2 mu_2(fmt(3)) b(star fmt(3))') starlevels(* 0.10 ** 0.05 *** 0.01) ///

  89. noobs compress replace title(esttab_Table: T_test by group)

  90. /*

  91. 1. 能一次性分组 T 均值检验所有变量。

  92. 2. 有 MeanDiff 一列,可设置以'* p < 0.1 ** p < 0.05 *** p < 0.01'的方式标注星号

  93. 3. 能分别设置每一列的小数点位数。

  94. */

  95. asdoccorr,1=

  96. *-----------------相关系数矩阵 Word 输出(by asdoc)------------------------------

  97. local varlist 'wage age race married grade collgrad'

  98. asdoc cor `varlist', save(Myfile.doc) replace nonum dec(3) ///

  99. title(asdoc_Table: correlation coefficient matrix)

  100. /*

  101. 1. 无法使用 asdoc pwcorr 命令,而简易的 asdoc cor 命令不能报告 p 值(显著性),不能标星号。

  102. */

  103. corrdocx,1=

  104. *-----------------相关系数矩阵 Word 输出(by corr2docx)--------------------------

  105. local varlist 'wage age race married grade collgrad'

  106. corr2docx `varlist' using Myfile.docx, replace spearman(ignore) ///

  107. star title(corr2docx_Table: correlation coefficient matrix)

  108. /*

  109. 1. 支持中文

  110. 2. 不能报告 p 值,但能以'* p < 0.1 ** p < 0.05 *** p < 0.01'的方式标注星号

  111. */

  112. logoutcorr,1=

  113. *-----------------相关系数矩阵 Word 输出(by logout)------------------------------

  114. ! taskkill /F /IM WINWORD.EXE /T

  115. local varlist 'wage age race married grade collgrad'

  116. logout, save(Myfile) word replace : pwcorr `varlist', ///

  117. star(0.05) listwise

  118. /*

  119. 1. 能报告 p 值,能标注星号(只能设置一个显著性水平)。

  120. 2. 表格会有串行的问题,需要后期自己手动调整。

  121. 3. 不能设置表格标题。

  122. */

  123. esttabcorr,1=

  124. *-----------------相关系数矩阵 Word 输出(by esttab)------------------------------

  125. local varlist 'wage age race married grade collgrad'

  126. estpost correlate `varlist', matrix listwise

  127. esttab using Myfile.rtf, ///

  128. unstack not noobs compress nogaps replace star(* 0.1 ** 0.05 *** 0.01) ///

  129. b(%8.3f) p(%8.3f) title(esttab_Table: correlation coefficient matrix)

  130. /*

  131. 1. 能报告 p 值,可设置以'* p < 0.1 ** p < 0.05 *** p < 0.01'的方式标注星号。

  132. */

  133. asdocreg,1=

  134. *-----------------回归结果 Word 输出(by asdoc)------------------------------

  135. asdoc reg wage age married occupation, save(Myfile.doc) nest replace ///

  136. cnames(OLS-1) rep(se) add(race, no)

  137. asdoc reg wage age married collgrad occupation, save(Myfile.doc) nest append ///

  138. cnames(OLS-2) add(race, no)

  139. asdoc reg wage age married collgrad occupation race_num*, save(Myfile.doc) nest append ///

  140. add(race, yes) cnames(OLS-3) dec(3) drop(occupation race_num*) ///

  141. stat(r2_a, F, rmse, rss) title(asdoc_Table: regression result)

  142. /*

  143. 1. 可添加不同列的列名。

  144. 2. 没有诸如 indicate('race=race_num*') 的选项,需用 add(race, yes) 代替。

  145. 3. 不能对变量进行排序。

  146. 4. 表格布局与一般的文献不同,且不能用命令调整。

  147. */

  148. regdocx,1=

  149. *-----------------回归结果 Word 输出(by reg2docx)------------------------------

  150. reg wage age married occupation

  151. est store m1

  152. reg wage age married collgrad occupation

  153. est store m2

  154. reg wage age married collgrad occupation race_num*

  155. est store m3

  156. reg2docx m1 m2 m3 using Myfile.docx, replace indicate('race=race_num*') ///

  157. b(%9.2f) se(%7.2f) scalars(r2(%9.3f) r2_a(%9.2f) N) ///

  158. drop(occupation) order(married) ///

  159. title(reg2docx_Table: regression result) ///

  160. mtitles('OLS-1' 'OLS-2' 'OLS-3')

  161. /*

  162. 1. 可添加不同列的列名

  163. 2. 有诸如 indicate('race=race_num*') 的选项。

  164. 3. 命令运行之后会将所有已经储存的回归结果清除,导致后面无法再继续使用前面的回归结果。

  165. 4. 支持中文。

  166. */

  167. outregreg,1=

  168. *-----------------回归结果 Word 输出(by outreg2)------------------------------

  169. local subexp 'nor2 noobs e(r2 r2_a F N) fmt(f) bdec(2) sdec(2) drop(occupation race_num*) sortvar(married)'

  170. reg wage age married occupation

  171. outreg2 using Myfile, word replace title(outreg2_Table: regression result) ///

  172. ctitle(OLS-1) `subexp' addtext(race, no)

  173. reg wage age married collgrad occupation

  174. outreg2 using Myfile, word append ctitle(OLS-2) `subexp' addtext(race, no)

  175. reg wage age married collgrad occupation race_num*

  176. outreg2 using Myfile, word append ctitle(OLS-3) `subexp' addtext(race, yes)

  177. /*

  178. 1. 可添加不同列的列名。

  179. 2. 没有诸如 indicate('race=race_num*') 的选项,需用 addtext(race, yes) 代替。

  180. */

  181. esttabreg,1=

  182. *-----------------回归结果 Word 输出(by esttab)------------------------------

  183. reg wage age married occupation

  184. est store m1

  185. reg wage age married collgrad occupation

  186. est store m2

  187. reg wage age married collgrad occupation race_num*

  188. est store m3

  189. esttab m1 m2 m3 using Myfile.rtf, ///

  190. replace star( * 0.10 ** 0.05 *** 0.01 ) nogaps compress ///

  191. order(married) drop(occupation) b(%20.3f) se(%7.2f) ///

  192. r2(%9.3f) ar2 aic bic obslast scalars(F) ///

  193. indicate('race=race_num*') mtitles('OLS-1' 'OLS-2' 'OLS-3') ///

  194. title(esttab_Table: regression result)

  195. /*

  196. 1. 可添加不同列的列名。

  197. 2. 有诸如 indicate('race=race_num*') 的选项。

  198. 3. 表格形式最符合一般文献报告表格的格式。

  199. */

  200. outregsuml,1=

  201. *------------------描述性统计 LaTeX 输出(by outreg2)---------------------------

  202. local varlist 'wage age race married grade collgrad south union occupation'

  203. outreg2 using Myfile, sum(detail) replace tex eqkeep(N mean sd min p50 max) ///

  204. fmt(f) keep(`varlist') sortvar(wage age grade) ///

  205. title(outreg2_Table: Descriptive statistics)

  206. /*

  207. 默认:输出一个完整的可以编译的但格式较为简易 .tex 文件,表格默认居左对齐。

  208. outreg2 的 tex() 的专有选项:

  209. 1. fragment:只输出表格本身。

  210. 2. pretty:在默认的基础上增加了更为丰富的格式,并将表格居中对齐。

  211. 3. landscape:横置页面。

  212. */

  213. logoutttestl,1=

  214. *-----------------分组 T 均值检验 LaTeX 输出(by logout)-------------------------

  215. local varlist 'wage age race married grade collgrad union'

  216. logout, save(Myfile) tex replace: ttable2 `varlist', by(south)

  217. /*

  218. 1. LaTeX 输出不能增加表格标题。

  219. 2. logout 的 tex 没有选项,只有默认形式。

  220. */

  221. logoutcorrl,1=

  222. *-----------------相关系数矩阵 LaTeX 输出(by logout)-------------------------

  223. local varlist 'wage age race married grade collgrad'

  224. logout, save(Myfile) tex replace : pwcorr `varlist', ///

  225. star(0.05) listwise

  226. /*

  227. 1. 表格会有串行的问题,需要后期自己手动调整。

  228. 2. LaTeX 输出不能增加表格标题。

  229. 3. logout 的 tex 没有选项,只有默认形式。

  230. */

  231. outregregl,1=

  232. *-----------------回归结果 LaTeX 输出(by outreg2)-------------------------

  233. local subexp 'tex nor2 noobs e(r2 r2_a F N) fmt(f) bdec(2) sdec(2) drop(occupation race_num*) sortvar(married)'

  234. reg wage age married occupation

  235. outreg2 using Myfile, replace title(outreg2_Table: regression result) ///

  236. ctitle(OLS-1) `subexp' addtext(race, no)

  237. reg wage age married collgrad occupation

  238. outreg2 using Myfile, append ctitle(OLS-2) `subexp' addtext(race, no)

  239. reg wage age married collgrad occupation race_num*

  240. outreg2 using Myfile, append ctitle(OLS-3) `subexp' addtext(race, yes)

  241. /*

  242. 默认:输出一个完整的可以编译的但格式较为简易 .tex 文件,表格默认居左对齐。

  243. outreg2 的 tex() 的专有选项:

  244. 1. fragment:只输出表格本身。

  245. 2. pretty:在默认的基础上增加了更为丰富的格式,并将表格居中对齐。

  246. 3. landscape:横置页面。

  247. */

  248. esttabsuml,1=

  249. *------------------描述性统计 LaTeX 输出(by esttab)---------------------------

  250. local varlist 'wage age race married grade collgrad south union occupation'

  251. estpost summarize `varlist', detail

  252. esttab using Myfile.tex, ///

  253. cells('count mean(fmt(2)) sd(fmt(2)) min(fmt(2)) p50(fmt(2)) max(fmt(2))') ///

  254. noobs compress replace title(esttab_Table: Descriptive statistics) ///

  255. booktabs page(array, makecell) alignment(cccccc) width(\hsize)

  256. /*

  257. esttab 的 LaTeX 输出的专有选项:

  258. 1. booktabs: 用 booktabs 宏包输出表格(三线表格)。

  259. 2. page[(packages)]: 创建完成的 LaTeX 文档以及添加括号里的宏包

  260. 3. 如果写了 booktabs 选项,则 page[(packages)] 将自动添加\usepackage{booktabs}。

  261. 4. alignment(cccccc):定义从第二列开始的列对齐方式(默认居中)。

  262. 5. width(\hsize):可以使得表格宽度为延伸至页面宽度

  263. 6. fragment:不输出表头表尾,只输出表格本身内容,其不能与 page[(packages)] 选项共存。

  264. */

  265. esttabttestl,1=

  266. *-----------------分组 T 均值检验 LaTeX 输出(by esttab)-------------------------

  267. local varlist 'wage age race married grade collgrad union'

  268. estpost ttest `varlist', by(south)

  269. esttab using Myfile.tex, ///

  270. cells('N_1 mu_1(fmt(3)) N_2 mu_2(fmt(3)) b(star fmt(3))') starlevels(* 0.10 ** 0.05 *** 0.01) ///

  271. noobs compress replace title(esttab_Table: T_test by group) ///

  272. booktabs page width(\hsize)

  273. /*

  274. esttab 的 LaTeX 输出的专有选项:

  275. 1. booktabs: 用 booktabs 宏包输出表格(三线表格)。

  276. 2. page[(packages)]: 创建完成的 LaTeX 文档以及添加括号里的宏包

  277. 3. 如果写了 booktabs 选项,则 page[(packages)] 将自动添加\usepackage{booktabs}。

  278. 4. alignment(cccccc):定义从第二列开始的列对齐方式(默认居中)。

  279. 5. width(\hsize):可以使得表格宽度为延伸至页面宽度

  280. 6. fragment:不输出表头表尾,只输出表格本身内容,其不能与 page[(packages)] 选项共存。

  281. */

  282. esttabcorrl,1=

  283. *-----------------相关系数矩阵 LaTeX 输出(by esttab)-------------------------

  284. local varlist 'wage age race married grade collgrad'

  285. estpost correlate `varlist', matrix listwise

  286. esttab using Myfile.tex, ///

  287. unstack not noobs compress nogaps append star(* 0.1 ** 0.05 *** 0.01) ///

  288. b(%8.3f) p(%8.3f) title(esttab_Table: correlation coefficient matrix) ///

  289. booktabs page width(\hsize)

  290. /*

  291. esttab 的 LaTeX 输出的专有选项:

  292. 1. booktabs: 用 booktabs 宏包输出表格(三线表格)。

  293. 2. page[(packages)]: 创建完成的 LaTeX 文档以及添加括号里的宏包

  294. 3. 如果写了 booktabs 选项,则 page[(packages)] 将自动添加\usepackage{booktabs}。

  295. 4. alignment(cccccc):定义从第二列开始的列对齐方式(默认居中)。

  296. 5. width(\hsize):可以使得表格宽度为延伸至页面宽度

  297. 6. fragment:不输出表头表尾,只输出表格本身内容,其不能与 page[(packages)] 选项共存。

  298. */

  299. esttabregl,1=

  300. *-----------------回归结果 LaTeX 输出(by esttab)-------------------------

  301. reg wage age married occupation

  302. est store m1

  303. reg wage age married collgrad occupation

  304. est store m2

  305. reg wage age married collgrad occupation race_num*

  306. est store m3

  307. esttab m1 m2 m3 using Myfile.tex, ///

  308. append star( * 0.10 ** 0.05 *** 0.01 ) nogaps compress ///

  309. order(married) drop(occupation) b(%20.3f) se(%7.2f) ///

  310. r2(%9.3f) ar2 aic bic obslast scalars(F) ///

  311. indicate('race=race_num*') mtitles('OLS-1' 'OLS-2' 'OLS-3') ///

  312. title(esttab_Table: regression result) booktabs page width(\hsize)

  313. /*

  314. esttab 的 LaTeX 输出的专有选项:

  315. 1. booktabs: 用 booktabs 宏包输出表格(三线表格)。

  316. 2. page[(packages)]: 创建完成的 LaTeX 文档以及添加括号里的宏包

  317. 3. 如果写了 booktabs 选项,则 page[(packages)] 将自动添加\usepackage{booktabs}。

  318. 4. alignment(cccccc):定义从第二列开始的列对齐方式(默认居中)。

  319. 5. width(\hsize):可以使得表格宽度为延伸至页面宽度

  320. 6. fragment:不输出表头表尾,只输出表格本身内容,其不能与 page[(packages)] 选项共存。

  321. */

  322. esttab,1=

  323. *--------------------四张表输出至一个 Word 文件里(by esttab)------------------

  324. ! taskkill /F /IM WINWORD.EXE /T

  325. *描述性统计输出

  326. local varlist 'wage age race married grade collgrad south union occupation'

  327. estpost summarize `varlist', detail

  328. esttab using Myfile.rtf, ///

  329. cells('count mean(fmt(2)) sd(fmt(2)) min(fmt(2)) p50(fmt(2)) max(fmt(2))') ///

  330. noobs compress replace title(esttab_Table: Descriptive statistics)

  331. /*

  332. 1. 在将结果导入到 word 的途中,Stata 界面能看到相应的结果(下同)。

  333. 2. 该命令不支持中文(有些教程说可以对中文进行 gb18030 转码后导入,但本文试验不成功)。

  334. 3. 若有字符串变量,命令仍会直接运行,在输出列表中字符型变量名会写上去,但后面的统计量为空白。

  335. 4. 能分别设置每个统计量的小数点位数。

  336. */

  337. *分组 T 均值检验输出

  338. local varlist 'wage age race married grade collgrad union'

  339. estpost ttest `varlist', by(south)

  340. esttab using Myfile.rtf, ///

  341. cells('N_1 mu_1(fmt(3)) N_2 mu_2(fmt(3)) b(star fmt(3))') starlevels(* 0.10 ** 0.05 *** 0.01) ///

  342. noobs compress append title(esttab_Table: T_test by group)

  343. /*

  344. 1. 能一次性分组 T 均值检验所有变量。

  345. 2. 有 MeanDiff 一列,可设置以'* p < 0.1 ** p < 0.05 *** p < 0.01'的方式标注星号

  346. 3. 能分别设置每一列的小数点位数。

  347. */

  348. *相关系数矩阵输出

  349. local varlist 'wage age race married grade collgrad'

  350. estpost correlate `varlist', matrix listwise

  351. esttab using Myfile.rtf, ///

  352. unstack not noobs compress append nogaps star(* 0.1 ** 0.05 *** 0.01) ///

  353. b(%8.3f) p(%8.3f) title(esttab_Table: correlation coefficient matrix)

  354. /*

  355. 1. 能报告 p 值,可设置以'* p < 0.1 ** p < 0.05 *** p < 0.01'的方式标注星号。

  356. */

  357. *回归结果输出

  358. reg wage age married occupation

  359. est store m1

  360. reg wage age married collgrad occupation

  361. est store m2

  362. reg wage age married collgrad occupation race_num*

  363. est store m3

  364. esttab m1 m2 m3 using Myfile.rtf, ///

  365. compress append star( * 0.10 ** 0.05 *** 0.01 ) nogaps ///

  366. order(married) drop(occupation) b(%20.3f) se(%7.2f) ///

  367. r2(%9.3f) ar2 aic bic obslast scalars(F) ///

  368. indicate('race=race_num*') mtitles('OLS-1' 'OLS-2' 'OLS-3') ///

  369. title(esttab_Table: regression result)

  370. /*

  371. 1. 可添加不同列的列名。

  372. 2. 有诸如 indicate('race=race_num*') 的选项。

  373. 3. 表格形式最符合一般文献报告表格的格式。

  374. */

  375. esttabl,1=

  376. *----------------------四张表输出至一个 tex 文件中(by esttab)------------------

  377. *描述性统计输出

  378. local varlist 'wage age race married grade collgrad south union occupation'

  379. estpost summarize `varlist', detail

  380. esttab using Myfile.tex, ///

  381. cells('count mean(fmt(2)) sd(fmt(2)) min(fmt(2)) p50(fmt(2)) max(fmt(2))') ///

  382. noobs compress replace title(esttab_Table: Descriptive statistics) ///

  383. booktabs page(array, makecell) alignment(cccccc) width(\hsize)

  384. /*

  385. esttab 的 LaTeX 输出的专有选项:

  386. 1. booktabs: 用 booktabs 宏包输出表格(三线表格)。

  387. 2. page[(packages)]: 创建完成的 LaTeX 文档以及添加括号里的宏包

  388. 3. 如果写了 booktabs 选项,则 page[(packages)] 将自动添加\usepackage{booktabs}。

  389. 4. alignment(cccccc):定义从第二列开始的列对齐方式(默认居中)。

  390. 5. width(\hsize):可以使得表格宽度为延伸至页面宽度

  391. 6. fragment:不输出表头表尾,只输出表格本身内容,其不能与 page[(packages)] 选项共存。

  392. */

  393. *分组 T 均值检验输出

  394. local varlist 'wage age race married grade collgrad union'

  395. estpost ttest `varlist', by(south)

  396. esttab using Myfile.tex, ///

  397. cells('N_1 mu_1(fmt(3)) N_2 mu_2(fmt(3)) b(star fmt(3))') starlevels(* 0.10 ** 0.05 *** 0.01) ///

  398. noobs compress append title(esttab_Table: T_test by group) ///

  399. booktabs page width(\hsize)

  400. /*

  401. 1. 这里的 page 选项可以将本部分附着在先前的 document 环境中,从而形成一个整体。

  402. */

  403. *相关系数矩阵输出

  404. local varlist 'wage age race married grade collgrad'

  405. estpost correlate `varlist', matrix listwise

  406. esttab using Myfile.tex, ///

  407. unstack not noobs compress append nogaps star(* 0.1 ** 0.05 *** 0.01) ///

  408. b(%8.3f) p(%8.3f) title(esttab_Table: correlation coefficient matrix) ///

  409. booktabs page width(\hsize)

  410. *回归结果输出

  411. reg wage age married occupation

  412. est store m1

  413. reg wage age married collgrad occupation

  414. est store m2

  415. reg wage age married collgrad occupation race_num*

  416. est store m3

  417. esttab m1 m2 m3 using Myfile.tex, ///

  418. append star( * 0.10 ** 0.05 *** 0.01 ) nogaps compress ///

  419. order(married) drop(occupation) b(%20.3f) se(%7.2f) ///

  420. r2(%9.3f) ar2 aic bic obslast scalars(F) ///

  421. indicate('race=race_num*') mtitles('OLS-1' 'OLS-2' 'OLS-3') ///

  422. title(esttab_Table: regression result) booktabs page width(\hsize)

  423. *小结

  424. /*

  425. 1. 这里所有的表格都可以生成标题,也没有串行的问题。

  426. 2. 与 out_log 不一样,esttab 能形成一个整体,所有的表格都能完美的 append 在一起,

  427. 并且可以设置生成导言区和正文区的 document 环境。所以以上命令生成的 .tex 文件可以

  428. 直接拿去编译,并生成所有表格,一步到位。之后我们再统一做一些微调就可以放在 LaTeX

  429. 正文中了。

  430. */

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Stata结果输出系列A:esttab, xxx2docx, outreg2, asdoc 对比
Selection Ratio:帮你解决头疼的遗漏变量偏误
Stata:毕业论文大礼包 C——新版 esttab
STATA結果以Excel、WORD 以及LaTex編譯格式輸出
互助问答第342期:关于动态面板分位数回归的问题
[转]qtp小结
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服