在Stata中创建简单表,然后将它们导出到LaTeX

时间:2016-04-19 15:39:09

标签: export latex stata

table fecha, contents(mean var_men_ipc mean var_men)

所以这是我用来在Stata中创建简单表格的代码。我想将这些表包含在我正在创建的LaTeX文件中,其中还包含一堆图形。我知道有很多用户创建的命令对于从Stata导出表是半无用的。尽管如此,这些主要仅适用于回归或统计输出,而不适用于我所拥有的简单表格。

2 个答案:

答案 0 :(得分:1)

社区贡献命令tabout提供了一种即用型解决方案:

. tabout rep78 using table.tex, style(tex) content(mean mpg mean weight) sum replace

Table output written to: table.tex

\begin{center}
\footnotesize
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\begin{tabularx} {14} {@{} l Y Y @{}}
\toprule
 & mpg & weight \\
\midrule 
Repair Record 1978 \\
1 & 21.0 & 3,100.0 \\
2 & 19.1 & 3,353.8 \\
3 & 19.4 & 3,299.0 \\
4 & 21.7 & 2,870.0 \\
5 & 27.4 & 2,322.7 \\
Total & 21.3 & 3,032.0 \\
\bottomrule
\end{tabularx}
\normalsize
\end{center}

答案 1 :(得分:0)

以下是使用texdoc的一个非常简单的工作示例。这将创建一个.tex文件,然后您可以根据需要进行编译。

/* Create sample data */
clear *
set obs 10
gen date = _n
expand 10
set seed 123
gen i = runiform()
cd "/path/to/my/output"

/* Initialize and create LaTeX document */
texdoc init TexTest, replace

tex \documentclass{article}
tex \usepackage{stata}
tex \begin{document}

tex \section{Table 1}

texdoc stlog TexLog
table date, contents(mean i)

texdoc stlog close

tex \end{document}

以上代码在" / path / to / my / output /"创建TexTest.tex。我在提交texdoc stlog命令之前使用table来捕获日志文件中table的输出。如果打开生成的.tex文件,您会注意到有一行\input{TexLog.log.tex} - 编译器将在LaTeX文档中的该位置插入日志文件的内容。

您可以使用首选方法编译.tex文件。我在Linux环境中使用pdflatex。在最初安装pdflatex之后我还遇到了一些问题,并且必须解决stata.sty的一些依赖关系。

编译后,生成的PDF文件将包含此表:

Resulting PDF output