# Re: st: Adjusting -tabout- to include top.tex and bot.tex lines automatically?

 From Roy Wada To statalist@hsphsun2.harvard.edu Subject Re: st: Adjusting -tabout- to include top.tex and bot.tex lines automatically? Date Tue, 17 Nov 2009 15:33:19 -0800

> I would also very much appreciate any advice on how to modify top.tex
> and bot.tex to include \begin{table}, \caption, \label and \end{table}
> so that tabout could automatically generate a table float.

You already know about the stuff that goes to the top and the bottom?
You just want to write it automatically? I can't really recommend that
you go into the ado file unless you really want to.

However, you can directly add the stuff you want to the file produced
by -tabout-. Just put it on the top and the bottom. The following is a
fast and easy method of doing this. You have a tex fragment hanging
around? No problem. Just run the code and it will be fixed.

In fact, this is perhaps the easiest method available in Stata for
reading and writing to a text file. No need to go through the
technical foo foo on the way there.

sysuse auto, clear
replace style(tex)

logout, use(table1.tex) clear raw

gen temp=1
set obs =_N+5'
replace temp=0 if temp==.
sort temp

replace raw="\begin{center}" in 1
replace raw="\footnotesize" in 2
replace raw="\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}" in 3
replace raw="\begin{tabularx} {#} {@{} l Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y
Y@{}} \\" in 4
replace raw="\toprule" in 5

set obs =_N+5'
replace raw="\bottomrule" in  =_N-5'
replace raw="\addlinespace[.75ex]" in =_N-4'
replace raw="\scriptsize{\emph{Source: }#}" in =_N-3'
replace raw="\end{tabularx}" in =_N-2'
replace raw="\normalsize" in =_N-1'
replace raw="\end{center}" in =_N-0'

outsheet raw using raw.tex, noquote noname replace

The stuff about \begin{table}, \caption, \label and \end{table} can be
inserted as well. Just add a few more lines and you are good to go.

Roy
*
*   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/