【发布时间】:2019-04-15 16:02:54
【问题描述】:
Outreg2 是一个社区贡献的命令,它可以帮助我们轻松地将在 Stata 上运行的回归结果输出到一个干净的表格中,然后可以在文本、Word 文档或 LaTeX 中查看。
使用auto.dta 数据集,我运行以下回归:
sysuse auto.dta, clear
ssc install outreg2
gen wtsq = weight^2
foreach s in price headroom trunk{
xi: reg `s' weight wtsq, vce(robust)
outreg2 weight wtsq using tab_base_`s'_j, keep(weight wtsq) bdec(3) nocons tex(nopretty) replace
xi: reg `s' weight wtsq foreign, vce(robust)
outreg2 weight wtsq foreign using tab_base_`s'_j, keep(weight wtsq foreign) bdec(3) nocons tex(nopretty) append
xi: reg `s' weight wtsq foreign length, vce(robust)
outreg2 weight wtsq foreign length using tab_base_`s'_j, keep(weight wtsq foreign length) bdec(3) nocons tex(nopretty) append
}
我得到三个名为tab_base_price_j、tab_base_trunk_j 等的.tex 文件的输出。当我在 LaTeX 中打开 .tex 文件并运行它们时,我会以完美的格式获得 PDF 中的回归表,就像我想要的那样。
但是,LaTeX 中的每个文件都具有以下格式:
\documentclass[]{article}
\setlength{\pdfpagewidth}{8.5in} \setlength{\pdfpageheight}{11in}
\begin{document}
\begin{tabular}{lccc} \hline
& (1) & (2) & (3) \\
*** ALL THE TABLE VALUES - DELETED from this illustration ***
\end{tabular}
\end{document}
如果我想创建一个新文档(作为期刊文章或论文格式),并且我想输入这些 .tex 文件之一
\input{tab_base_price_j.tex} 在 LaTeX 中,
我收到此错误:! LaTeX Error: Can be used only in preamble.
如何以输出.tex 文件没有\begin{document} 的方式从Stata 输出回归表,并从以下开始:
\begin{tabular}{lccc} \hline
& (1) & (2) & (3) \\
*** ALL THE TABLE VALUES - DELETED from this illustration ***
\end{tabular}
【问题讨论】:
-
xi:前缀在最新版本的 Stata 中已被弃用,以支持因子变量表示法。在您的示例中,它没有害处,但毫无意义,因为没有变量被标记为分类(在其他术语中是因子变量)。更重要的是,您应该将outreg2解释为来自 SSC 的社区贡献。
标签: latex stata stata-macros