{smcl}
{* 13mar05}{...}
{hline}
help for {hi:tabout8}
{hline}

{title:Command to export publication quality cross-tabulations to a text file}

{p 5 5}Basic syntax:

{p 8 14 2}
{cmdab:tabout8}
{it:varlist} 
[{cmd:if} {it:exp}] 
[{cmd:in} {it:range}] 
[{it:weight}{cmd: = }{it:exp}] 
{cmd:using} {it:output filename}
{break} 
{cmd:,} {cmdab:rep:lace} {cmdab:app:end}
  {cmdab:c:ells(}{it:cell}{cmd:)}
  {cmd: oneway}

{p 14 14 2}  
  {cmdab:f:ormat(}{it:%fmt ...}{cmd:)} 
  {cmd:stats(}{it:chi2}{cmd:)} 
  {cmd:n(}{it:pos | label | weight}{cmd:)} 


{p 14 14 2}  
  {cmd:style(}{it:outstyle}{cmd:)} {cmd:lines(}{it:lstyle}{cmd:)}
  {cmd:font(}{it:fstyle}{cmd:)} {cmd:bt} {cmdab:nobord:er}

{p 14 14 2}  
  {cmd:total(}{it:totalname | totalname}{cmd:)} 
  {cmd:header1(}{it:namelist}{cmd:)}
  {cmd:header2(}{it:namelist}{cmd:)} 
  {cmd:header3(}{it:namelist}{cmd:)} 
  {cmdab:nohead:er} {cmdab:lefth:ead}
  {cmdab:notot:als(}{it:varname}{cmd:)}
  
{p 14 14 2}  
  {cmd:body} {cmd:topf(}{it:input filename}{cmd:)}
  {cmd:botf(}{it:input filename}{cmd:)} 
  {cmd:topstr(}{it:namelist}{cmd:)} 
  {cmd:botstr(}{it:namelist}{cmd:)} 
  {cmdab:psymb:ol(}{it:string}{cmd:)}
  {cmdab:delim:it(}{it:string}{cmd:)}
  
{p 14 14 2}  
  {cmd:show(}{it:display}{cmd:)} {cmdab:labw:idth(}{it:#}{cmd:)} 
  {cmdab:colw:idth(}{it:#}{cmd:)} {cmdab:tabw:idth(}{it:#}{cmd:)}]

{p 8 14 2}
{cmd:where:}

{p 14 14 2}
{it:varlist} is [list] of vertical (row) variables, followed by
the horizontal (column) variable last. if the {cmd:oneway} option is
specified, then all the variables are regarded as vertical.

{p 14 14 2}
{it:cells} is {cmd:fcount} {cmd:fper} {cmd:fcum} for frequency tables 
(default is fcount). All three may be specified.

{p 14 14 2}
{it:cells} is {cmd:row} | {cmd:col} | {cmd:count} | {cmd:double}  for 
two-way tables (default is count). Only one may be specified, but note
that {cmd:double} produces two side-by-side columns of counts and column
percentages.

{p 14 14 2}
{it:cells} is {cmd:summary statistic {it:variable name}}. You may have
multiple cells for oneway tables, but only a single cell for two-way tables. 
The summary statistics permitted are any of the following:

{p 16 16 10}
{it}
      N count mean median var sd skewness kurtosis sum min max 
      p1 p5 p10 p25 p50 p75 p90 p95 p99 iqr r9010 r9050 r7525 r1050
      
{sf}
{p 14 14 2} 
Note that you may enter the median as either {it:p50} or {it:median} and you
may enter N as either {it:N} or {it:count}.

{p 14 14 2}
{cmd:oneway} is very important. Unless you specify {cmd:oneway}, {cmd:tabout8} 
will always treat the last variable in your varlist as the horizontal variable.
{cmd:oneway} signals to {cmd:tabout8} that all variables in the varlist are to
be regarded as vertical variables.

{p 14 14 2}
{it:outstyle} is {cmd:tab} | {cmd:tex} | {cmd:html} (default is tab)

{p 14 14 2}
{it:lstyle} is {cmd:single} | {cmd:double} | {cmd:blank} | 
{cmd:none} (default is single) These only apply to Tex or LaTeX output,
except that {cmd:blank} will enter a blank line in tab delimited output.

{p 14 14 2}
{it:fstyle} is {cmd:plain} | {cmd:bold} | {cmd:italic} (default is plain)

{p 14 14 2}
{it:totalname} is {it:anything}. Two terms are required, one for
the vertical variable and one for the horizontal. They must be separated by
the pipe delimiter (or a user-provided delimiter, see later). If omitted, 
reverts to {it:Total|Total}.

{p 14 14 2}
{it:namelist} is {it:anything} (list of names separated by pipe delimiters).
These apply to the headers ({cmd:header1}, {cmd:header2} and {cmd:header3}) and to the strings ({cmd:topstr} and {cmd:botstr}) passed as arguments to the files
 ({cmd:topf()} and {cmd:botf()}) which can be inserted above and below the table.

{p 14 14 2}
{cmdab:nohead:er} switches off all headers, whether these are the automatically
generated headers produced by {cmd:tabout8} or user defined headers.
  
{p 14 14 2}
{cmdab:lefth:ead} can be either 1, 2 or 3. This determines on which line in the
header the variable label should appear when using simple frequency or two-way 
tables (that is, tables which are not stacked). The default position is usually
the best, so this option is rarely needed.

{p 14 14 2}
{cmd:body} is used to insert some basic HTML or LaTeX code above and
below the table. This allows you to view the table without further
coding.
 
{p 14 14 2}  
{cmd:topf()} {cmd:botf()} allow you to insert code stored in files which
{cmd:tabout8} can insert above and below the tables. These are mainly intended
for HTML and LaTeX (or TeX) users, and allow you to control the layout of
the tables more precisely.

{p 14 14 2}
{cmdab:psymb:ol(}{it:string}{cmd:)} can be any symbol the user chooses. The 
default is # and it provides a "placemarker" in the stored files which
{cmd:tabout8} places above and below the tables.

{p 14 14 2}
{cmdab:delim:it(}{it:string}{cmd:)} can be any symbol the user chooses. The
default is the pipe delimiter |. It is used to separate strings within various
namelists, such as headers, arguments passed to stored files, and total names.

{p 14 14 2}
{it:display} is {cmd:all} | {cmd:table} | {cmd:code} | {cmd:none}
(default is table, but note that the file message is always displayed).


{p 5 5 2}
{cmd:fweight}s, {cmd:aweight}s, and {cmd:iweight}s are allowed by
{cmd:tabout8} and can be used for frequency tables and two-way tables of
counts and percentages. For tables of summary statistics, {cmd:iweight}s are
not allowed, because {cmd:tabout8} uses the {cmd:detail} option in {it:Stata}'s 
{help summarize} command (which does not allow {cmd:iweight}s).


{title:Description}

{p 5 5}{cmd:tabout8} produces publication quality cross-tabulations of variables 
and exports the output to a text file. These tables can be in tab-delimited output 
(the default), LaTeX / TeX formatted output, or HTML formatted output.

{p 5 5}The output in {cmd:tabout8} can be frequency tables and simple two-way 
cross tabulations. In this regard {cmd:tabout8} resembles {help tabulate}. The only
statistics allowed, however, are chi2. 

{p 5 5}
{cmd:tabout8} also produces tables of
summary statistics (mean, median, etc) in either cross-tabulated form, or in
oneway tables. In this regard, {cmd:tabout8} resembles {help table}.

{p 5 5}
{cmd:tabout8} also allows multiple columns of different summary
statistics when producing oneway tables. 

{p 5 5}
In addition to the summary statistics, {cmd:tabout8} also 
produces a number of percentile ratios (eg. 90th to the 10th,
90th to the median etc).


{p 5 5}
Unlike the standard {it:Stata} tables, {cmd:tabout8} also provides for the stacking of
tables into multiple panels, so that a number of vertical variables may be
cross-tabulated against a horizontal variable.

{p 5 5}
{cmd:tabout8} provides control over number formatting and does not
abbreviate variable or value labels (except on the screen, for display purposes).

{p 5 5}
When the output is sent to TeX or HTML, {cmd:tabout8} also provides 
formatting of fonts for variable labels.

{p 5 5}
Finally, {cmd:tabout8} allows the user to insert their own code (stored in files)
above and below the tables they produce. In addition, arguments can be passed to 
these stored files, so that individual tables can be customised with their own
titles and captions etc.

{p 5 5}
See {browse "http://www.ianwatson.com/stata/tabout8examples"} for a tutorial file. 

{p 5 5}
{cmd:tabout8} supersedes {net "describe http://fmwww.bc.edu/RePEc/bocode/l/latab":latab}.
{cmd:tabout8} has been replaced by {net "describe http://fmwww.bc.edu/RePEc/bocode/t/tabout":tabout}.


{title:The output}

{p 5 5}The table displayed on the screen is just to give you an idea of what
the table will look like. It may not always display perfectly. However, you 
can be confident that the table sent to the text file will be correct.

{p 5 5}While the results from {cmd:tabout8} will look best using TeX or
LaTeX, the most common use of {cmd:tabout8} is likely to be sending tables 
to word processors like MS Word. While a number of approaches are possible, 
two simple approaches are:

{p 10 10 5}
1. open your text editor with the output file displayed; copy and paste in into
a document in Word. Then use Table / Convert / Text to Table.

{p 10 10 5}
2. output the table as HTML, open the file in your browser and copy it. 
Inside Word, use Paste Special and paste the table as Formatted Text (rtf).

{p 5 5}
There is a more extensive discussion of these issues in the internet file found
at {browse "http://www.acirrt.com/watson/tabout8":examples}.

{p 5 5}
For users of TeX or LaTeX, the {it:booktabs} package is supported by
the {cmd:bt} option. This allows the use of \midrule rather than \line.
As with HTML, TeX output can be sent to a text file with or
without headers; and with or without surrounding code. If the user wants
to quickly preview the table in a browser (or compile under TeX / LaTeX),
the {cmd:body} option surrounds the table code with some basic code to make the
table "stand-alone". Note that the {cmd:bt} option will not work if
you have also selected {cmd:body}. 

{p 5 5}
For more  customised control over the final results,
users can merge the table code with code stored in "style" files. The
{cmd:topf()} option designates the text file where the code to be
inserted above the table resides, while the {cmd:botf()} option designates the
code to come after the table. You can also pass arguments to these files
by including strings in the {cmd:topstr} and {cmd:botstr} options. These strings
will be inserted into the {cmd:topf()} and {cmd:botf()} files where ever the
placemarker (default #) has been placed. Note that each placemarker must be on
a separate line in these files. The strings designated in the {cmd:topstr} 
and {cmd:botstr} must be separated with the pipe delimiter (or other user-chosen
delimiter) if there is more than one argument being passed.

{title:Headers}

{p 5 5}
Headers are the most complicated part of {cmd:tabout8} 
(and the most complex part of the programming). 
The default headers work reasonably well and should suffice for 
most occasions. The principles are as follows:

{p 10 10 5}
1. there are at most three headers, though only two are used in the 
default settings (except for the {cmd:double} type of table, which 
makes use of all three).

{p 10 10 5}
2. the first line of the headers begins above the numerical cells of the table. 
This is usually the horizontal variables label. It is usually fonted 
(bold or italic) in LaTeX or HTML.

{p 10 10 5}
3. the second line of the headers usually contains the values of the horizontal
variable. These also begin above the numerical cells.

{p 10 10 5}
4. the variable labels for the vertical variables are usually below the headers.
An exception to this is simple tables (that is, those that not stacked), 
which place the single vertical variable's label in the first column of the 
bottom row of the headers (similar to what {cmd:tabulate} does). 
These types of tables also place a rule above the Total line in the table, 
also in the style of the {cmd:tabulate} commmand. 
In LaTeX and HTML these labels are also usually fonted.

{p 5 5}
When it comes time to add your own headers, you can simply overwrite 
the line you wish to change, and the other lines will remain unaffected. 
If you wish your header to start in the second column 
(that is, above the numerical cells), 
enter an underscore, followed by the pipe (or other) delimiter into your string, 
for example: 

{p 10 10 2}
{cmd}
header1(_|This is my main heading)
{text}

{p 5 5}
If you want to skip any other columns, also use underscores in this way, 
for example:

{p 10 10 2}
{cmd}
header3(_|First numerical column|_|Now third one|_|Now fifth one)
{text}

{p 5 5}
The user headers work well using the {cmd:tex} option, though you need to 
enter your own code for spans, and for fonts. The user headers do not work as 
well with HTML because you often need to control the following line, that is, 
header1 content can be easily changed, but header2 may also have to be changed.
Possibly the easiest option here is to specify the {cmd:noheader} option,
which suppresses all automatic header output, and then create your own custom 
commands in the {cmd:topf()} file for the table.

{p 5 5}
Sometimes, the only change needed to the automatic headers is a change to
the location of the vertical variable's label (which appears in the 
first column, usually on the bottom row of the headers). Rather than having to 
create a user header (which has implications for the whole line, not just 
the first column), you have another strategy: the {cmd:lefthead} option takes 
the values 1, 2 or 3, and these determine on which of the three header lines 
this label appears. Re-positioning the label in this way has no effect on the 
rest of the header, that is, the labels which are above the numerical cells.


{title:Options (not already discussed)}

{p 5 5}{cmd:using(}{it:filename}{cmd:)} is {it:not} an option, because
{cmd:tabout8} relies on sending its output to a text file. You must provide
the full path name, enclosed in double quotes if there are any blanks, and
with the filename extension included. If the output is going to the
working directory, then the full path name is not necessary. These
requirements also apply to the {cmd:topf()} and {cmd:botf()} options.

{p 5 5}If you omit the {cmd:show} option, the table is displayed on 
the screen and the table code is sent straight to a text file. If you 
want to see the table code then {cmd:code} (or {cmd:all}) must be chosen.
If you want nothing displayed on the screen, choose the {cmd:none}
option, but note that the file message always appears.

{p 5 5}{cmd:format(}{it:%fmt ...}{cmd:)} specifies how the
cells are to be formatted. The default setting is {cmd:%9.0fc} for most tables,
except for the second column of the {cmd:double} table, where {cmd:%9.1f} is
the default. Note also that when you are producing oneway tables, in which
there may be several columns of different summary statistics, you may specify 
as many formats as there are columns. If you specify more formats than columns,
the extra ones are ignored. If you specify fewer formats than columns, then you 
may find some of your columns displayed to 6 decimal points.

{p 5 5}The {cmd:total|total} option allows you to specify words like 
"All categories", or "All persons", to appear where {it:Stata} would normally
place the word Total. Two words or phrases (pipe delimited) must be entered:
the first word or phrase specifies the term to be used for rows (vertical 
variables) and the second word specifies the term to be used for the final 
column (the horizontal variable).

{p 5 5}The {cmd:n} option allows you to include information on the sample size
(or population estimates) in the body of the table. This can be useful when the
table only contains percentages. There are three sub-options and they must
all be specified. The first sub-option determines where the information on the
{it:n} will appear in the table. You can either:

{p 10 10 5}
1. include an additional column showing the {it:n} by specifying {it:col} 
as the {cmd:pos} sub-option; or

{p 10 10 5}
2. include a label following the value label with words such as {it:(n=125)} by
specifying {it:lab} as the {cmd:pos} sub-option.

{p 5 5}
The form of words describing the {it:n} is specified 
in the {cmd:label} sub-option. Specifying {it:d} (for default) makes the column 
heading (if {it:col} has been chosen) show "n". If you have
specified {it:lab} in the {cmd:pos} sub-option, the default label is "(n=#)". 
{cmd:tabout8} replaces the "#" with the
actual count in the final table. If you specify {it:lab} in the {cmd:pos} 
sub-option, you 
might notice that {cmd:tabout8}'s screen display does not match
the text file output. (Because the value 
labels are usually abbreviated for the screen display, there was no point in 
adding further words to the value labels. The extra column (when the {it:col} 
sub-option is chosen) does show in the screen display.)

{p 5 5}
If you do not want the default label, you can specify your own. Simply enter
a phrase using the "#" symbol for where the actual count is to occur. For example,
you might enter "[count is #]" or "(sample size = #)".

{p 5 5}
The third sub-option specifies a weight to be used in calculating the sample
size. The default (specified with {it:d}) is to use no weighting at all. This
equates to a sample size count. If you wish to show population estimates,
you might specify a weight variable, such as {it:wt}. Note that {cmd:tabout8} always
uses Stata's {cmd:iweight} option for this weighting.

{p 5 5}
To produce a column showing the sample size, the syntax would be: 
{it:n(col|d|d)}. The syntax for population estimates would be:
{it:n(col|N|wt)}. 
Note that the sub-options must be separated with the pipe delimiter 
(or other user-chosen delimiter).

{p 5 5}
To produce a label showing the sample size, the syntax would be:
{it:n(lab|d|d)}. The syntax for population estimates would be:
{it:n(lab|(N = #)|wt)}. 

{p 5 5}{cmdab:notot:als} suppresses the row totals which are repeated
in the panels in stacked tables. In the case of row percentages, these
totals are often the same and their repetition can be tedious and take up
valuable page space. Issuing the {cmdab:notot:als} option removes all these 
row totals from the table. The {cmdab:notot:als} option must have a 
"total variable" inside its parenthesis. A "total variable" can be any variable
you wish. It is called a "total variable" because it is used when you want to
have a single total row, such as at the bottom of the 
stacked tables. To do this, add the "total variable" to your vertical variable 
list. Place it first in the list if you want it to display at the top of the
table and last the vertical list if you want it to display at the bottom. 
If you do not want any totals shown 
in the table, simply omit the "total variable" from your 
vertical variable list (but it must still appear inside the parenthesis for
the {cmdab:notot:als} option). If this sounds a bit complicated, the following
example makes it clear.

{p 5 5}
For example, first create a "total variable" (gen allpersons = 1) and define
some labels (la var allpersons "All persons"; la def allpersons 1 "All persons";
la val allpersons allpersons).  The variable label is what will be displayed, the
value label is needed because {cmd:tabout8} insists that all values are labelled.
Next include this variable in your vertical variable 
list as the last variable (if you want it at the bottom) or as the first variable
(if you want it at the top). For example: tabout8 gender age race region allpersons
... etc . Finally, include the {cmdab:notot:als} option as follows: notot(allpersons).
This will produce a table in which all the row totals in your stacked table
are suppressed, and an entry for "All persons" will appear at
the bottom of the table.

{p 5 5}For housekeeping reasons, {cmd:tabout8} makes use of @@ symbols on the line
where the total variable will be shown. These do not appear in the final table.
If for some reason, you have used two @@ symbols in any of your labels, you may 
have problems. Simply change the @@ symbols and everything will be fine.


{p 5 5}If you select TeX output, {cmd:tabout8} automatically enters the \ 
symbol before any % or & symbols in your headers and in your variable or value
labels.

{p 5 5}{cmd:labelwidth}, {cmd:colwidth} and {cmd:tablewidth} options 
only affect the display on the screen and don't influence the text file output. 
{cmd:labelwidth} sets the width of the labels for the vertical
variables (the default is 20 and the range is 8 to 60). {cmd:colwidth} sets
the width of the columns (the default is 11 and the range is 6 to 30).
{cmd:tablewidth} sets the width of the horizontal lines in the display, and 
changes the system setting for the linesize (how much text is shown before it 
wraps around). Note that the system setting is returned to its original setting
when {cmd:tabout8} finishes. If for some reason, linesize does not return
to its original setting, you can do this manually by typing:
{it:set linesize #}, 
where # is the number which suits your screen display. Note that reducing the 
size of {cmd:colwidth} may dislocate the position of the headers, but since this
only affects the screen display (and not the output to the text file), this is
not a problem.

{p 5 5}The {cmd:lines} option only applies to TeX output, and determines
whether single lines, double lines, no lines, or empty space, should be used
to separate vertical variables. It can be used in conjunction with the
{cmd:bt} option. Note that with tab-delimited output, specifying {cmd:blank}
 here produces an extra carriage return between panels in stacked tables. 

{p 5 5}The {cmd:noborder} option only applies to HTML output, and 
determines whether the table and cells should be surrounded by borders.
This only applies when the {cmd:body} option is turned on.

{title:Blank cells}

{p 5 5}Unlike {help tabulate}, {cmd:tabout8} uses all available values
of the horizontal variable to produce its cross-tabulations. This can
lead to some blank cells being shown. (See {help tabcount} for a program
that does this for both variables.) The reason for this is that stacked
tables need to have all their columns aligned properly, and some panels may
not have frequency counts for all of the values of the horizontal variable.
If this proves unsuitable for your tables, you can simply
restrict the values for the horizontal variable using an {cmd:if} statement.

{title:Problems and warnings}

{p 5 5}{cmd:tabout8} requires that all variables in the {it:varlist} have value
labels attached and that none of them are string variables. If you try to run 
{cmd:tabout8} in violation of these requirements, {cmd:tabout8} will exit and 
you will receive a warning message.

{p 5 5}
{cmd:tabout8} works well in LaTeX, under which it was developed. 
Nevertheless, it can no doubt be improved, and I would welcome suggestions.
{cmd:tabout8} can certainly be improved for HTML, and I would also welcome advice
on this. 

{p 5 5}
Copying the tab delimited output from the screen in {it:Stata} into 
spreadsheets and 
word processors is uneven in its results. Sometimes the tabs copy correctly,
sometimes they don't. Inspection of the tab delimited files 
in a text editor shows all of the tabs in the correct places. I would appreciate 
feedback from users for any improvements in this area.

{p 5 5}
You may have problems with {cmd:tabout8} if any of your variables use a value of 
-9, or if any of your labels use underscores (|_|). {cmd:tabout8} uses both -9 
and |_| for its own housekeeping. The simplest strategy is for you to for you to 
avoid -9 in your values and to remove the 
underscores from your labels (note, that I am not talking about variable names, 
only labels, as well as value labels). Of course, you can easily modify the code
in the {cmd:tabout8} ado file, using a search and replace operation on the -9 to 
replace it with a different obscure number.


{p 5 5}
If you are using {it: Intercooled Stata}, you might also have 
problems if you are 
constructing large tables and your value labels are very long. This may happen 
because {cmd:tabout8} processes tables using strings, 
and {it:Intercooled Stata} is 
restricted to strings of length 80 characters. This can also be a problem with
passing arguments to the {cmd:topf()} and {cmd:botf()} files, if the strings
are too long. Please contact me if you run into problems with these string
limits.


{title:Examples}

{p 5 5} The following example uses {it:Stata}'s auto dataset, but first modifies
it to make it more useful for cross-tabulations. The code for these
changes is shown first, so that the syntax for {cmd:tabout8} makes sense (and
also so that you can run the example yourself). The output produced by these
tables is illustrated in the files on the Internet at 
{browse "http://www.acirrt.com/watson/tabout8":examples}.

{p 1 1}
Load the auto dataset and make some changes:

{cmd}
sysuse auto, clear
recode weight (min/2499=1 "Low") ///
              (2500/3499=2 "Medium") ///
              (3500/max=3 "High"), ///
              gen(weight2)
la var weight2 "Weight category"
recode gear_ratio (min/2.49=1 "Low") /// 
                   (2.5/2.99=2 "Middle") ///
                   (3/3.49=3 "Upper") ///
                   (3.5/max=4 "Highest"), gen(torque)
                   
la var torque "Category of gear ratio"
la def foreign 0 "Domestic origin" 1 "Foreign origin", modify
la val foreign foreign
la var foreign "Manufacturing origin"
recode headroom (min/1.9=1 "Minimal headroom") ///
                (2/3.9=2 "Adequate headroom") ///
                (4/max=3 "Excellent headroom"), gen(roomy)
la var roomy "Roominess of the vehicle"
gen wt=uniform()*1000
la var weight "Weight"
la var mpg "Mileage"
la var length "Length"
la var displacement "Capacity"

{text}

{p 1 1}
First, some tab-delimited output:

{cmd}
tabout8 torque [iw=wt] using cars.txt, ///
replace show(all) cells(fcount fper fcum) format(%9.0fc %9.1f %9.2f)

tabout8 torque weight2 roomy foreign [iw=wt] using cars.txt, ///
   append show(all) cells(fcount fper fcum) format(%9.0fc %9.1f %9.2f) oneway

tabout8 torque weight2 roomy foreign [iw=wt] using cars.txt, ///
   append show(all) cells(fcount fper fcum) format(%9.0fc %9.1f %9.2f)

tabout8 torque foreign [iw=wt] using cars.txt, ///
   append show(all) c(row) f(%9.1f) total(All categories|All cars)

tabout8 torque foreign using cars.txt, ///
   append show(all) c(count) f(%9.0f) ///
   stats(chi2 2 3)

tabout8 torque weight2 roomy foreign [iw=wt] using cars.txt, ///
   append show(all) c(row) f(%9.1f)

tabout8 torque weight2 roomy foreign [aw=wt] using cars.txt, ///
   append show(all) c(mean mpg) f(%9.1f) ///
   header3(_|(mean mpg)|(mean mpg)|(mean mpg))

tabout8 torque weight2 roomy foreign [aw=wt] using cars.txt, append show(all)  ///
   c(mean mpg p50 weight sd length max disp) ///
   f(%9.1f %9.0f %9.2f %9.0f) ///
   header1(_|Various characteristics of interest) ///
   header3(_|(mn mpg)|(med lbs)|(sd in)|(max cu in)) ///

tabout8 torque weight2 roomy foreign [aw=wt] using cars.txt, append show(all)  ///
   c(iqr price r9010 price r9050 price r1050 price)  ///
   f(%9.0f %9.1f %9.1f %9.1f) ///
   header1(_|Distribution aspects of car prices) ///
   header2(_|iqr|90/10 ratio|90/50 ratio|10/50 ratio) ///

tabout8 torque weight2 roomy foreign [aw=wt] using cars.txt, append show(all)  ///
   c(iqr price r9010 price r8050 price r1050 price)  ///
   f(%9.0f %9.1f %9.1f %9.1f) ///
   header1(_|Distribution aspects of car prices) ///
   header2(_|iqr|90/10 ratio|90/50 ratio|10/50 ratio) ///
{text}

{p 1 1}
Now the same tables for HTML output:

{cmd}
tabout8 torque [iw=wt] using cars.htm, rep style(html) /// 
   c(fcount fper fcum) f(%9.0fc %9.1f %9.2f) font(bold)   ///
   topstr(Examples of HTML tables using tabout8|Gear ratio, simple frequencies) ///
   psymb(#) topf(main_top.htm) ///
   botf(example_bot.htm) 

tabout8 torque weight2 roomy foreign [iw=wt] using cars.htm, app ///
   style(html) c(fcount fper fcum) f(%9.0fc %9.1f %9.2f) oneway font(bold)   ///
   topstr(Various characteristics, simple frequencies) ///
   psymb(#) topf(example_top.htm) ///
   botf(example_bot.htm) 


tabout8 torque weight2 roomy foreign [iw=wt] using cars.htm, app ///
   style(html) c(fcount fper fcum) f(%9.0fc %9.1f %9.2f) font(bold)   ///
   topstr(Various characteristics, simple frequencies) ///
   psymb(#) topf(example_top.htm) ///
   botf(example_bot.htm) 


tabout8 torque foreign [iw=wt] using cars.htm, app ///
   style(html) c(row) f(%9.1f) font(bold)   ///
   topstr(Gear ratio by origin) ///
   total(All categories|All cars) ///
   psymb(#) topf(example_top.htm) ///
   botf(example_bot.htm) 

tabout8 torque foreign using cars.htm, app ///
   style(html) c(count) f(%9.0f) font(bold) stats(chi2 2 3)  ///
   topstr(Gear ratio by origin, with chi-square results) ///
   psymb(#) topf(example_top.htm) ///
   botf(example_bot.htm) 

tabout8 torque weight2 roomy foreign [iw=wt] using cars.htm, app ///
   style(html) c(row) f(%9.1f) font(italic)   ///
   topstr(Various characteristics by origin) ///
   psymb(#) topf(example_top.htm) ///
   botf(example_bot.htm) 


tabout8 torque weight2 roomy foreign [iw=wt] using cars.htm, app ///
   style(html) c(double) f(%9.0fc %9.1f) font(bold)   ///
   topstr(Various characteristics by origin) ///
   psymb(#) topf(example_top.htm) ///
   botf(example_bot.htm) 


tabout8 torque weight2 roomy foreign [aw=wt] using cars.htm, app ///
   style(html) c(mean mpg) f(%9.1f) font(bold)   ///
   topstr(Average fuel consumption by origin) ///
   botstr(Stata Dataset|All cars.) psymb(#) topf(example_top.htm) ///
   botf(example_bot.htm) 

tabout8 torque weight2 roomy foreign [aw=wt] using cars.htm, app ///
   style(html) c(mean mpg p50 weight sd length max disp) oneway ///
   f(%9.1f %9.0f %9.2f %9.0f) font(bold)   ///
   topstr(Summary statistics according to gear ratio) ///
   psymb(#) topf(example_top.htm) ///
   botf(main_bot.htm) 
{text}

{p 1 1}
Finally, the same tables for LaTeX output:

{cmd}
tabout8 torque [iw=wt] using cars1.tex, rep style(tex) /// 
   c(fcount fper fcum) f(%9.0fc %9.1f %9.2f) font(bold) bt ///
   topstr(10cm|cars1|Gear ratio, simple frequencies) ///
   botstr(Stata Dataset|All cars.) psymb(#) topf(example_top.tex) ///
   botf(example_bot.tex) 

tabout8 torque weight2 roomy foreign [iw=wt] using cars2.tex, rep ///
   style(tex) c(fcount fper fcum) f(%9.0fc %9.1f %9.2f) oneway font(bold) bt ///
   topstr(10cm|cars2|Various characteristics, simple frequencies) ///
   botstr(Stata Dataset|All cars.) psymb(#) topf(example_top.tex) ///
   botf(example_bot.tex) 

tabout8 torque weight2 roomy foreign [iw=wt] using cars3.tex, rep ///
   style(tex) c(fcount fper fcum) f(%9.0fc %9.1f %9.2f) font(bold) bt ///
   topstr(12cm|cars3|Various characteristics, simple frequencies) ///
   botstr(Stata Dataset|All cars.) psymb(#) topf(example_top.tex) ///
   botf(example_bot.tex) 

tabout8 torque foreign [iw=wt] using cars4.tex, rep ///
   style(tex) c(row) f(%9.1f) font(bold) bt ///
   topstr(10cm|cars4|Gear ratio by origin) ///
   total(All categories|All cars) ///
   botstr(Stata Dataset|All cars.) psymb(#) topf(example_top.tex) ///
   botf(example_bot.tex) 

tabout8 torque foreign using cars5.tex, rep ///
   style(tex) c(count) f(%9.0f) font(bold) bt stats(chi2 2 3) ///
   topstr(10cm|cars5|Gear ratio by origin, with chi-square results) ///
   botstr(Stata Dataset|All cars.) psymb(#) topf(example_top.tex) ///
   botf(example_bot.tex) 

tabout8 torque weight2 roomy foreign [iw=wt] using cars6.tex, rep ///
   style(tex) c(row) f(%9.1f) font(italic) bt ///
   topstr(12cm|cars6|Various characteristics by origin) ///
   botstr(Stata Dataset|All cars.) psymb(#) topf(example_top.tex) ///
   botf(example_bot.tex) 


tabout8 torque weight2 roomy foreign [iw=wt] using cars7.tex, rep ///
   style(tex) c(double) f(%9.0fc %9.1f) font(bold) bt ///
   topstr(14cm|cars7|Various characteristics by origin) ///
   botstr(Stata Dataset|All cars.) psymb(#) topf(example_top.tex) ///
   botf(example_bot.tex) 


tabout8 torque weight2 roomy foreign [aw=wt] using cars8.tex, rep ///
   style(tex) c(mean mpg) f(%9.1f) font(bold) bt ///
   header3(_|(mean mpg)|(mean mpg)|(mean mpg)) ///
   topstr(14cm|cars8|Average fuel consumption by origin) ///
   botstr(Stata Dataset|All cars.) psymb(#) topf(example_top.tex) ///
   botf(example_bot.tex) 


tabout8 torque weight2 roomy foreign [aw=wt] using cars9.tex, rep ///
   style(tex) c(mean mpg p50 weight sd length max disp) oneway ///
   f(%9.1f %9.0f %9.2f %9.0f) font(bold) bt ///
   header1(_|\multicolumn{4}{c}{\textbf{Various characteristics of interest}}) ///
   header3(_|(mn mpg)|(med lbs)|(sd in)|(max cu in)) ///
   topstr(14cm|cars9|Summary statistics according to gear ratio) ///
   botstr(Stata Dataset|All cars.) psymb(#) topf(example_top.tex) ///
   botf(example_bot.tex) 


tabout8 torque weight2 roomy foreign [aw=wt] using cars10.tex, rep ///
   style(tex) c(iqr price r9010 price r9050 price r1050 price) oneway ///
   f(%9.0f %9.1f %9.1f %9.1f) font(bold) bt ///
   header1(_|\multicolumn{4}{c}{\textbf{Distribution aspects of car prices }}) ///
   header2(_|iqr|90/10 ratio|90/50 ratio|10/50 ratio) ///
   topstr(14cm|cars10|Summary statistics according to gear ratio) ///
   botstr(Stata Dataset|All cars.) psymb(#) topf(example_top.tex) ///
   botf(example_bot.tex) 
{text}



{title:Future developments}

{p 5 5}{cmd:tabout8} only provides chi2 statistics. Future versions will
extend this. Suggestions for improvements, and reports of bugs, are most welcome. Please email.

{title:Acknowledgements}

{p 5 5}Thanks to Stephen Jenkins, Chris Wallace, Herve Stolowy, Nick Cox, 
Andrew Felton and Giorgio Ricchiuti for useful suggestions and feedback.
Thanks also to Ben Jann for writing the wonderful 
{net "describe http://fmwww.bc.edu/RePEc/bocode/e/estout":estout} , which 
provided the inspiration for {cmd:tabout8}.


{title:Author}

   Ian Watson
   acirrt
   University of Sydney
   Australia
   i.watson@econ.usyd.edu.au

Version 1.2.0 13mar2005
