Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Centering column headers using estpost tabulate (twoway) in LaTeX table
From
Bert Lloyd <[email protected]>
To
[email protected]
Subject
Re: st: Centering column headers using estpost tabulate (twoway) in LaTeX table
Date
Sat, 19 Jan 2013 17:03:35 -0500
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}\\
& 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}
}
As PDF:
https://dl.dropbox.com/u/2937392/esttab-twoway-tabulate-example-corrected.pdf
On Sat, Jan 19, 2013 at 3:53 PM, annoporci <[email protected]> wrote:
> I think you want to override the automatic alignment. I think you may be
> able to achieve that by adding: layout("\multicolumn{1{c}{@}")
>
> That and much more is discussed here:
>
> http://tex.stackexchange.com/questions/48966/esttab-overriding-decimal-alignment
>
> See also this:
>
> http://www.jwe.cc/2012/03/stata-latex-tables-estout/
>
>
> ---
> Patrick Toche.
>
>
> On Sun, 20 Jan 2013 01:11:28 +0800, Bert Lloyd <[email protected]>
> wrote:
>
>> 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/
>
>
>
> --
> Patrick Toche.
>
> *
> * 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/
*
* 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/