Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: three-way tables, exporting to tex


From   Ben Jann <[email protected]>
To   [email protected]
Subject   Re: st: three-way tables, exporting to tex
Date   Fri, 20 Mar 2009 22:32:53 +0100

A one-step solution could be to use -by- with -eststo- and -estpost
tabstat-. Example:

<--->
clear
webuse union
table year union south, c(freq mean grade)   // the table we want to create

eststo clear
bysort south union: eststo: estpost tabstat grade, by(year) stat(count
mean) nototal
esttab, cells(count mean) gaps noobs
<--->

The table contains the right results but the header is not so
informative. To see the south/union coding you could type:

<--->
esttab, cells(count mean) gaps noobs  ///
    mtitles nonumbers collabels(none)
<--->

But that is still not very nice. Better would be something like:

<--->
esttab, cells(count mean) gaps noobs  ///
    nonumbers collabels(none)  ///
    mlabels("no union" union "no union" union, lhs(year)) ///
    mgroups(north south, pattern(1 0 1 0))
<--->

To get the thing into LaTeX add a "using <name>.tex" and I also
suggest the -booktabs- option (requires you to include
\usepackage{booktabs} in the document preamble). Here's an advanced
example that also prints a nice header:

<--->
esttab using mytable.tex, booktabs align(r) ///
    cells(count mean(fmt(2))) gaps noobs ///
    nonumbers collabels(none) ///
    mlabels("no union" union "no union" union, lhs(year)) ///
    mgroups(north south, pattern(1 0 1 0) span ///
        prefix(\multicolumn{2}{c}{) suffix(})  ///
        erepeat(\cmidrule(lr){@span}))
<--->

ben

On Fri, Mar 20, 2009 at 5:45 PM, Richard Ochmann <[email protected]> wrote:
> Hi,
>
> how would you export a three-way table to a .tex document?
>
> I would like to produce a summary table for a continuous variable over
> three categorical variables. Cells shall contain means as well as
> frequencies.
> I found I can nicely do that with -table- (find my code below). Now I have
> a hard time exporting the resulting table to a .tex document that I can
> further edit in LaTeX.
> I tried with user-written programs like -estout- and -tabout-. While
> -tabout- brings me close, I didnt figure out how to do a three-way table
> there.
> While this problem is certainly easily worked-around producing separate
> two-way tables conditioning on the third variable and somehow combining
> them, I would be happy to have a one-step solution here.
>
> thanks for ideas!
>
> Stata 10, WinXP
>
> best, rich
>
> ***
> clear
> webuse union
> table year union south, c(freq mean grade)
> ***
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index