Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Eric Booth <eric.a.booth@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: latex output for "table" |

Date |
Thu, 8 Mar 2012 22:27:12 -0600 |

<> Hi Abhishek: -tabout- (from SSC by the way) outputs statistics (like mean and SD) that are placed in cells that are side-by-side in the exported table. There is no way (that I've ever encountered) to instruct -tabout- to stack your stats in the same way they are in the -table- output(without manipulating your row variable in some way). Be sure to consult this document from Ian Watson for more help on this package: http://www.ianwatson.com.au/stata/tabout_tutorial.pdf Here are 3 ways I'd might use to approach this issue: 1. If you are not concerned about the stacking and just want a standard -tabout- LaTeX table with the mean and SD, then Example 1 below will create a table with mean and sd placed side-by-side. This is the standard layout for this information using -tabout-. 2. If you do desire the stacking, then you can reshape a collapsed version of your data to produce some data that can be used by -tabout- to produce your LaTeX code. Examples 2 does exactly this (though there may be more straightforward ways to get there). 3. Finally, if you go through the trouble of collapsing and reshaping your data to produce a dataset that just needs the LaTeX code wrapped around it (via -tabout-), you could instead use the user-written command -texsave- (from SSC) to output your table with LaTeX code. Example 3 below does this. The example code below produces these 3 tables in LaTeX (click for pdf version): http://goo.gl/vPu5I *********************!Begin Example *-----watch for wrapping issues below *-----fake data sysuse auto, clear replace rep78 = cond(rep78>3, 0, 1) //create binary var for table table for rep78, c(mean price sd price) *-----EXAMPLE 1: standard tabout example (sd next to mean) for A in num 0/1: g priceA = price if rep78 ==A //old school loop tabout for `x' using `"table1.tex"', replace sum /// c(mean price0 sd price0 mean price1 sd price1) /// f(1cm) clab(Mean-Not SD-Not Mean-Repair SD-Repair) /// npos(lab) ptotal(both) /// style(tex) bt font(bold) /// topf(top.tex) botf(bot.tex) botstr(7cm) /// topstr( \caption{ Stats for \textbf{`:var lab price' `x'}}) drop price? *-----alternatives with mean stacked above sd //EXAMPLE2: using collapse and tabout// *reshape data* collapse (mean) rep2 = price (sd) rep3 = price, by(for rep78) reshape wide rep2 rep3, i(for) j(rep78) reshape long rep@0 rep@1, i(foreign) j(stat) list //this looks like the -table- command *labels* lab var rep0 "No Repairs" lab var rep1 "Repairs" replace stat = 4 if for ==1 & stat ==2 replace stat = 5 if for ==1 & stat ==3 lab def s 2 "Domestic-Mean" 3 "Domestic-SD" /// 4 "Foreign-Mean" 5 "Foreign-SD" , modify lab val stat s *tabout* tabout stat using `"table1.tex"', append sum /// c(mean rep0 mean rep1) h2(nil) /// f(1cm) clab(No_Repairs Repairs) /// ptotal(none) style(tex) bt font(bold) /// topf(top.tex) botf(bot.tex) botstr(7cm) /// topstr( \caption{ Second Example: Stats for Price } ) //EXAMPLE 3: using collapse and texsave// *install texsave* cap which texsave if _rc ssc install texsave *export file* decode stat, g(stat2) drop stat foreign order stat2 lab var stat2 "Foreign Status" texsave * using "table2.tex" , size(2) /// width(0.6\textwidth) title("Third example") /// hlines(2) replace varlabels frag location(ht) *********************!End Example HTH, Eric __ Eric A. Booth Public Policy Research Institute Texas A&M University ebooth@tamu.edu +979.845.6754 On Mar 8, 2012, at 4:47 PM, Abhishek wrote: > Hi, > > I have a simple query that I've been having trouble with. How do I get > the following into a table? I've tried tabout, but it doesnt seem to > work, but perhaps I dont understand it well. > > table var1 var2, c(mean statistic sd statistic) > > I want output that looks something like this: > > ------------------------------ > | var2 > var1 | 0 1 > -----------+------------------- > 0 | .157895 .182796 > | .5234516 .6133507 > | > 1 | .666667 1.15054 > | 1.309673 1.693152 > ------------------------------ > > > Thanks, > ~A > * > * 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/

**References**:**st: latex output for "table"***From:*Abhishek <cheerfulguy@gmail.com>

- Prev by Date:
**Re: st: can I use binary_mediation on imputed data?** - Next by Date:
**Re: st: -SML- estimator of Klein and Spady (1993)** - Previous by thread:
**st: latex output for "table"** - Next by thread:
**st: Interpretation of gllamm** - Index(es):