gpt4 book ai didi

latex - 将多个回归输出到LaTeX文档中

转载 作者:行者123 更新时间:2023-12-01 12:06:55 25 4
gpt4 key购买 nike

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
}

我将输出三个名为 .textab_base_price_jtab_base_trunk_j文件,依此类推。当我在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文件之一
LaTeX中的 \input{tab_base_price_j.tex}
我收到此错误: ! 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}

最佳答案

您只需要使用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}

关于latex - 将多个回归输出到LaTeX文档中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55693143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com