【问题标题】:How to include "&" in variable label for LaTeX output using esttab?如何使用 esttab 在 LaTeX 输出的变量标签中包含“&”?
【发布时间】:2019-07-19 19:23:41
【问题描述】:

我正在尝试将一些回归表从 Stata 导出到 LaTeX

问题是我想在表格中显示变量标签,但我的一些标签包含& 字符。因此,当我使用 community-contributed 命令esttab 导出到LaTeX 然后尝试编译时,我收到一个错误,因为Texmaker 认为& 应该指示额外柱子。

下面是我的Stata代码:

esttab results1 results2 using "$repodir/output/tables/tract_xregs.tex", ///
       se noconstant label star(* 0.10 ** 0.05 *** 0.01) replace  ///
       nonotes compress nomtitles booktabs ///
       s(modelsample modelobs, label("Sample" "N")) 

esttab sumstats1 using "$repodir/output/tables/tract_sumstats.tex", booktabs label ///
       nonumbers cells("mean p50 min max sd") replace 

如何在变量标签中包含& 字符而不在编译时出错?

【问题讨论】:

  • 欢迎来到 Stack Overflow。重要的是,您始终提供一个包含重现问题的数据和代码的示例。请阅读Stata tag wiki,了解如何在此处提出 Stata 相关问题的建议。

标签: latex stata


【解决方案1】:

考虑以下使用 Stata' toy auto 数据集的示例,它重现了您的问题:

sysuse auto, clear
estimates clear

label variable weight "One & Two"

regress price weight
estimates store ols

esttab ols, label tex

{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{1}{c}}
\hline\hline
                    &\multicolumn{1}{c}{(1)}\\
                    &\multicolumn{1}{c}{Price}\\
\hline
One & Two           &       2.044\sym{***}\\
                    &      (5.42)         \\
[1em]
Constant            &      -6.707         \\
                    &     (-0.01)         \\
\hline
Observations        &          74         \\
\hline\hline
\multicolumn{2}{l}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{2}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
}

您需要在变量标签中的&amp; 之前包含\,如下所示:

label variable weight "One \& Two"

esttab ols, label tex

{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{1}{c}}
\hline\hline
                    &\multicolumn{1}{c}{(1)}\\
                    &\multicolumn{1}{c}{Price}\\
\hline
One \& Two          &       2.044\sym{***}\\
                    &      (5.42)         \\
[1em]
Constant            &      -6.707         \\
                    &     (-0.01)         \\
\hline
Observations        &          74         \\
\hline\hline
\multicolumn{2}{l}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{2}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
}

前者产生错误,而后者编译正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2013-12-22
    • 2018-06-14
    • 2023-03-21
    相关资源
    最近更新 更多