【问题标题】:Outputting multiple regressions into a LaTeX document将多个回归输出到 LaTeX 文档中
【发布时间】: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


【解决方案1】:

您只需要使用tex(fragment) 选项:

sysuse auto.dta, clear
generate  wtsq  = weight^2

foreach s in price headroom trunk { 
    regress `s' weight wtsq, vce(robust)
    outreg2 weight wtsq using tab_base_`s'_j.tex, keep(weight wtsq) bdec(3) nocons tex(fragment)
    regress `s' weight wtsq foreign, vce(robust)
    outreg2 weight wtsq foreign using tab_base_`s'_j.tex, keep(weight wtsq foreign) bdec(3) nocons tex(fragment)
    regress `s' weight wtsq foreign length, vce(robust)
    outreg2 weight wtsq foreign length using tab_base_`s'_j.tex, keep(weight wtsq foreign length) bdec(3) nocons tex(fragment)
} 

然后您可以将这些作为较大文档的一部分输入,如下所示:

\documentclass[10pt]{article}
\begin{document}
... text before inclusion of table tab_base_price_j.tex ...
\input{tab_base_price_j.tex}
... text after inclusion of table tab_base_price_j.tex ...
\input{tab_base_headroom_j.tex}
... text after inclusion of table tab_base_headroom_j.tex ...
\input{tab_base_trunk_j.tex}
... text after inclusion of table tab_base_trunk_j.tex ...
\end{document}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    • 2018-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    相关资源
    最近更新 更多