Вывод нескольких регрессий в документ LaTeX - PullRequest
2 голосов
/ 15 апреля 2019

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
} 

Я получаю три .tex файла с именами tab_base_price_j, tab_base_trunk_j и так далее. Когда я открываю файлы .tex в LaTeX и запускаю их, я получаю таблицы регрессии в 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 Error: Can be used only in preamble.

Как вывести таблицы регрессии из Stata таким образом, чтобы выходные файлы .tex не имели \begin{document}, а просто начинались с:

\begin{tabular}{lccc} \hline
 & (1) & (2) & (3) \\
*** ALL THE TABLE VALUES - DELETED from this illustration ***
\end{tabular}

1 Ответ

4 голосов
/ 15 апреля 2019

Вам просто нужно использовать опцию 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}
...