I quickly adapted and simplified some of his code to get an example to
work with the auto dataset. It has the sort of alignment you were looking
for, albeit for a different type of Stata commands, and may prove useful
at some future time, for you or for me!
I include it below for the record.
Patrick.
Stata Code Below
------------------------------
clear all
set more off
sysuse auto
qui probit foreign weight mpg headroom trunk
predict pr1, pr
quietly su pr1
estadd scalar pr = r(mean)
estadd margins, dydx(*) atmeans
est store A
qui probit foreign weight mpg headroom length
predict pr2, pr
quietly su pr2
estadd scalar pr = r(mean)
estadd margins, dydx(*) atmeans
est store B
qui probit foreign weight mpg headroom weight
predict pr2_disp, pr
quietly su pr2_disp
estadd scalar pr = r(mean)
estadd margins, dydx(*) atmeans
est store C
esttab A B C using table4.tex, replace f ///
% \caption*, use a star to omit automatic numbering
% use caption package to control alignments
\end{table}
\end{document}
------------------------------------------------------------
On Sun, 20 Jan 2013 06:03:35 +0800, Bert Lloyd <bert.lloyd.89@gmail.com>
wrote:
Patrick,
Thank you for your suggestion. I couldn't use it directly, since
layout() appears to be a suboption only for stats(), but it led me to
something that worked (see below).
I am posting the code for others' benefit but should emphasize that I
am in well over my head with LaTeX here, so this may be "working" only
by fluke (e.g. is it correct to use @span twice to refer to different
sets of columns?).
Stata code:
set more off
sysuse auto
local rowvar_label : variable label rep78
local colvar_label : variable label foreign
estpost tabulate rep78 foreign
esttab using esttab-example-corrected.tex, booktabs replace ///
cell("b rowpct(fmt(2))") collabels("N" "Row Pct") ///
unstack nonote noobs nonumber ///
eqlabels(, ///
lhs("`rowvar_label'") ///
span prefix(\multicolumn{@span}{c}{) suffix(}) ///
) ///
nomtitles ///
mgroups("`colvar_label'", pattern(1 0 0) ///
prefix(\multicolumn{@span}{c}{) suffix(}) ///
span erepeat(\cmidrule(lr){@span}))
Yields tex code:
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{3}{cc}}
\toprule
&\multicolumn{6}{c}{Car type}
\\\cmidrule(lr){2-7}
Repair Record
1978&\multicolumn{2}{c}{Domestic}&\multicolumn{2}{c}{Foreign}&\multicolumn{2}{c}{Total}\\
Dear Statalist,
I am trying to create a simple twoway tabulation table in LaTeX using
the excellent user-written esttab command (version 2.0.5, part of the
estout package).
I am reporting both observation counts and row percentages, with the
value labels as column headers. Everything looks great using the code
below, but I would like to make one minor modification: center the
column headers between the observation count and row percent columns.
That is, currently the column header ("Domestic", "Foreign", "Total")
appears directly above the observation count column, I would like to
shift these slightly to the right so that the span both the
observation count and row percent columns. An example of what I would
like to do is found in Table 1 of the tabout tutorial, page 13 of
http://www.ianwatson.com.au/stata/tabout_tutorial.pdf.
Any advice?
Best,
BL
Stata code:
set more off
estimates clear
sysuse auto
local rowvar_label : variable label rep78
local colvar_label : variable label foreign
estpost tabulate rep78 foreign
esttab using esttab-example.tex, booktabs replace ///
cell("b rowpct(fmt(2))") collabels("N" "Row Pct") ///
unstack nonote noobs nonumber ///
eqlabels(, lhs("`rowvar_label'")) ///
nomtitles ///
mgroups("`colvar_label'", pattern(1 0 0) ///
prefix(\multicolumn{@span}{c}{) suffix(}) ///
span erepeat(\cmidrule(lr){@span}))
Generated TeX code:
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{3}{cc}}
\toprule
&\multicolumn{6}{c}{Car type}
\\\cmidrule(lr){2-7}
Repair Record 1978& Domestic& & Foreign&
& Total& \\
& N& Row Pct& N& Row Pct&
N& Row Pct\\
\midrule
1 & 2& 100.00& 0& 0.00&
2& 100.00\\
2 & 8& 100.00& 0& 0.00&
8& 100.00\\
3 & 27& 90.00& 3& 10.00&
30& 100.00\\
4 & 9& 50.00& 9& 50.00&
18& 100.00\\
5 & 2& 18.18& 9& 81.82&
11& 100.00\\
Total & 48& 69.57& 21& 30.43&
69& 100.00\\
\bottomrule
\end{tabular}
}
pdf table:
https://dl.dropbox.com/u/2937392/esttab-twoway-tabulate-example.pdf
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/