Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: tabsum to latex


From   "Carole J. Wilson" <carolejwilson@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: tabsum to latex
Date   Sat, 9 Feb 2008 11:19:35 -0600

Austin,
Thank you.  This approach works nicely.

Cheers,
Carole

On Feb 9, 2008 7:19 AM, Austin Nichols <austinnichols@gmail.com> wrote:
> Carole--
> You might trick -estout- (SSC) into doing this, or -collapse- and use
> -listtex- (SSC) or somesuch, but I would recommend writing a loop
> which calculates the statistics and writes them to a text file with
> -file- as in
> http://www.stata.com/statalist/archive/2006-04/msg01090.html
> http://www.stata.com/statalist/archive/2006-09/msg00837.html
> http://www.stata.com/statalist/archive/2007-10/msg00887.html
> etc.
>
> sysuse auto, clear
> ren rep78 x1
> ren for x2
> ren mpg x3
>
> file open t using /tab.tex, write replace
> levelsof x1, loc(l1)
> levelsof x2, loc(l2)
> file write t  "    & `: var label x2' \\ "
> file write t  _n "`: var label x1' "
> foreach c of loc l2 {
>  file write t  "  & `: label `: val label x2' `c'' "
> }
> file write t " \\" _n
> foreach r of loc l1 {
>  file write t  "`r' &"
>  foreach c of loc l2 {
>  su x3 if x1==`r' & x2==`c', meanonly
>  file write t " `: di %4.3g r(mean)' & "
>  }
>  file write t " \\ " _n "  & "
>  foreach c of loc l2 {
>  su x3 if x1==`r' & x2==`c', meanonly
>  file write t " `: di %4.3g r(N)' & "
>  }
>  file write t " \\ " _n
> }
> file close t
> type /tab.tex
> tab x1 x2, sum(x3) freq mean
>
> The above is just meant to be a quick example of what you can do with
> this approach, which is completely general and can be adapted to any
> need that might arise.  (I have even used it to make graphs in TeX
> files using pstricks, which approach is of course quite obsolete now.)
> Though if you wanted an RTF file or an XML file you would be better
> off using -estout- or the -tabstatmat- plus -xml_tab- approach.
>
>
> On Feb 9, 2008 12:59 AM, Carole J. Wilson <carolejwilson@gmail.com> wrote:
> > I am looking for a stata program to produce LaTeX code for a fairly
> > simple table:
> >
> > .tabulate x1 x2, sum(x3) freq mean
> >
> > Ian Watson's -tabout- can produce either a cross tab with a
> > frequencies or the cross tab with the mean of another variable, but
> > not both (as far as I can tell).  There are other programs with
> > similar limitations (only work with tabulate or tabstat) or they work
> > with estimation results.
> >
> > I can also collapse the data and use tabdisp to produce the same
> > table.  However, I don't see a program that writes to LaTeX the
> > results of either tabsum or tabdisp.
> >
> > Have I missed a user written program that would solve my problem?
> >
> > Thanks,
> > Carole
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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