【问题标题】:Stata esttab output to Latex : changing font sizeStata esttab 输出到 Latex :更改字体大小
【发布时间】:2021-12-05 18:11:51
【问题描述】:

有时您必须使用从 Stata 到 Latex 的非常长或非常大的回归表导出,以使其不适合单个页面。这通常发生在初步分析中,即您保留最多的控制变量并并排测试各种模型。一种解决方案是在 Latex 输出 ResultsTable.tex 文件中手动修改字体,方法是在 \caption 之后添加 \footnotesize\tiny

\begin{table}[htbp]\centering
\caption{Main Results} \footnotesize
\begin{tabular}{l*{3}{c}}

但是每次对表格进行修改时都必须重复此操作。

使用 esttab 包将 Latex 的字体大小直接修改为 STATA 的方法是什么?

esttab m1 m2 m3 m4 m5 m6 m7 m8 using "ResultsTable.tex", replace booktabs compress 

感谢您对此的任何建议!

【问题讨论】:

  • esttab 的选项记录在help esttab 中。如果这不允许足够的灵活性,您可以使用 import delimited 读取生成的 tex 文件并使用 replace if 添加您的更改
  • 我认为@Wouter 的链接解决方案是编辑表格主体(即不受preheadpostfoot 控制的部分)的绝佳解决方案,但适用于编辑“头部”下面的答案也很好,就足够了。

标签: stata


【解决方案1】:

虽然help esttab 总是有用的,但大多数解决棘手的esttab-to-Latex 问题的方法都依赖于esttabestout 的包装器这一事实,并且可以通过estout 的@ 轻松解决987654327@ 选项...esttab 下未记录。

这里是一个简短的MWE,它与您问题中的信息近似:

sysuse auto

reg price mpg 
estimates store m1
reg price mpg rep78
estimates store m2 
reg price mpg rep78 headroom
estimates store m3

esttab m1 m2 m3 ///
    using "out1.tex", ///
    replace booktabs compress ///
    title("Main Results")

这会生成一个.tex 文件,其中包含一个带有以下标题的表:

\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Main Results}
\begin{tabular}{l*{3}{c}}
\toprule

要添加\footnotesize,您需要将完整的标头从\begin{table} 传递到\toprule(因为您使用的是booktabs)到prehead() 选项,如下所示:

esttab m1 m2 m3 ///
    using "out2.tex", ///
    replace booktabs compress ///
    prehead(`"\begin{table}[htbp]\centering"' `"\footnotesize"' ///
            `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' ///
            `"\caption{Main Results}"' ///
            `"\begin{tabular}{l*{@M}{c}}"' ///
            `"\toprule"' ) //

请注意,.tex 输出中的每一行都包含一个反引号和撇号,并且\begin{tabular}{l*{@M}{c}} 语句引用@M 而不是明确说明列数。 这会生成一个.tex 文件,其中包含一个具有以下标题的表:

\begin{table}[htbp]\centering
\footnotesize
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Main Results}
\begin{tabular}{l*{3}{c}}
\toprule

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    相关资源
    最近更新 更多