我正在使用 Benn Jan 的 Stata esttab 命令,并将结果与我的 LaTeX 文档草稿相结合,使用 Jörg Weber 提供的有用提示。我想在回归表中包含一些非标准结果,但用一条线将它们分开,并可能将它们与副标题关联起来。Stata 中的 do 文件将是这样的:
sysuse auto, clear
reg mpg weight length i.foreign, robust
test weight+length=0
estadd scalar f_test=r(F)
estadd scalar ppdiff=r(p)
lincom weight+length
estadd scalar marginal=r(estimate)
est store A
esttab A using auto.tex, replace nonotes nomtitles f ///
label booktabs b(3) alignment(S) eqlabels(none) ///
drop(0.foreign) star(* 0.10 ** 0.05 *** 0.01) stats(marginal f_test ppdiff N r2, ///
fmt(3 3 3 %9.0gc 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}") ///
labels(`"Hypothesis test"' `"F-test"' `"p-value"' `"Observations"' `"\(R^{2}\)"'))
以及相关的 LaTeX 代码:
\documentclass[12pt,A4,fleqn]{article} % fleqn: align equations left
% Document:
\usepackage{geometry} % Custom margins for single page, etc.
\usepackage{fullpage} % Use the full page
\usepackage{setspace} % Enables custom margins, doublespacing, etc.
\usepackage{pdflscape} % Use: \begin{landscape} ... \end{landscape}
\usepackage{bm}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{lscape}
\usepackage{datetime}
\usepackage{longtable}
\usepackage{lscape} % To create a table in a landscape environment
\usepackage{rotating} % To use sideways table
\usepackage{rotfloat} % Use H with a sideways table
\usepackage{mathtools}
\usepackage{bibentry}
\usepackage{graphics}
\usepackage{threeparttable}
\usepackage{siunitx}
\usepackage{booktabs,dcolumn}
\usepackage{array}
\usepackage{hyperref}
% Font/text:
\usepackage[latin9]{inputenc} % Font definition and input type
\usepackage[T1]{fontenc} % Font output type
\usepackage{lmodern} % Latin Modern fonts
\usepackage{textcomp} % Supports many additional symbols
\usepackage{amsmath} % Math equations, etc.
\usepackage{amsthm} % Math theorems, etc.
\usepackage{amsfonts} % Math fonts (e.g. script fonts)
\usepackage{amssymb} % Math symbols such as infinity
\DeclareMathOperator*{\Max}{Max} % Better looking max function
\DeclareMathOperator*{\Min}{Min} % Better looking min function
\usepackage{color} % Enables colored text
\definecolor{darkblue}{rgb}{0.0,0.0,0.66} % Custom color: dark blue
\usepackage[hyperfootnotes=false,bookmarksopen]{hyperref} % Enable hyperlinks, expand menu subtree
\hypersetup{ % Custom hyperlink settings
pdffitwindow=false, % true: window fit to page when opened
pdfstartview={XYZ null null 1.00}, % Fits the default zoom of the page to 100%
pdfnewwindow=true, % Links in new window
colorlinks=true, % false: boxed links; true: colored links
linkcolor=darkblue, % Color of internal links
citecolor=darkblue, % Color of links to bibliography
urlcolor=darkblue } % Color of external links
%\usepackage{kpfonts} % for nice fonts
% Images:
\usepackage{graphicx} % Allows more types of images to be included
\usepackage[position=bottom]{subfig} % Enables arrayed images
\usepackage[section]{placeins} % Forces floats to stay in section
\usepackage{float} % Used with restylefloat
\restylefloat{figure} % "H" forces a figure to be "exactly here"
\usepackage[justification=centering]{caption} % Center captions
% Tables/arrays:
\usepackage{booktabs} % Table format - increases table spacing
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}} % Spacing for tables increased
\renewcommand{\arraystretch}{1} % Spaces arrays at 1x
\usepackage{dcolumn} % Align decimals in tables (as option)
%\newcolumntype{.}{D{.}{.}{-1}} % Align decimals e.g. \begin{tabular}{c...}
% Miscellaneous:
\interfootnotelinepenalty=10000 % Footnotes won't break across pages
\usepackage[semicolon]{natbib} % Bibliography and citation formating
\usepackage{datetime} % Custom date format for date field
\newdateformat{mydate}{\monthname[\THEMONTH] \THEYEAR} % Defining month year date format
%\usepackage{tikz} % Timelines and other drawings
%\usetikzlibrary{decorations} % Formating for Tikz
% *****************************************************************
% Estout related things
% *****************************************************************
\newcommand{\sym}[1]{\rlap{#1}}% Thanks to David Carlisle
\let\estinput=\input% define a new input command so that we can still flatten the document
\newcommand{\estwide}[3]{
\vspace{.75ex}{
\begin{tabular*}
{\textwidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{#2}{#3}}
\toprule
\estinput{#1}
\bottomrule
\addlinespace[.75ex]
\end{tabular*}
}
}
\newcommand{\estauto}[3]{
\centering{
\vspace{.75ex}{
\begin{tabular}{l*{#2}{#3}}
\toprule
\estinput{#1}
\bottomrule
\addlinespace[.75ex]
\end{tabular}
}
}
}
% Allow line breaks with \\ in specialcells
\newcommand{\specialcell}[2][c]{%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
% *****************************************************************
% Custom subcaptions
% *****************************************************************
% Note/Source/Text after Tables
\newcommand{\figtext}[1]{
\vspace{-0.4ex}
\captionsetup{justification=justified,font=footnotesize}
\caption*{\hspace{6pt}\hangindent=1.5em #1}
}
\newcommand{\fignote}[1]{\figtext{\emph{Note:~}~#1}}
\newcommand{\figsource}[1]{\figtext{\emph{Source:~}~#1}}
% Add significance note with \starnote
\newcommand{\starnote}{\figtext{* p<0.1, ** p<0.05, *** p<0.01. Clustered standard errors in parentheses.}}
% *****************************************************************
% siunitx
% *****************************************************************
\usepackage{siunitx} % centering in tables
\sisetup{
detect-mode,
tight-spacing = true,
group-digits = false ,
input-signs = ,
input-symbols = ( ) [ ] - + *,
input-open-uncertainty = ,
input-close-uncertainty = ,
table-align-text-post = false
}
% *****************************************************************
% *****************************************************************
% *****************************************************************
% DOCUMENT BEGINS HERE
% *****************************************************************
% *****************************************************************
% *****************************************************************
\begin{document}
\begin{table}[h]
\caption{Auto example}
\estauto{auto}{3}{S[table-format=3.4]}
\starnote
\label{tab2}
\end{table}
\end{document}
在此示例中,我如何在“p 值”和“观测值”之间插入一行(仅通过修改 do 文件)?如果我想为表格的这一部分插入某种标识符,我该怎么做?任何建议都非常感谢。