### Tabstat in LaTeX

Stata command latabstat generates LaTeX code for tabstat. You can use Stata's findit command to download the program from the internet. Please see our webpage on how to use findit to search for programs and additional help for more details. The use of latabstat is similar to tabstat. We will show some examples here.

Example 1: Group means of variables

use http://www.ats.ucla.edu/stat/stata/notes/hsb2
(highschool and beyond (200 cases))
tabstat math write read, by(female)
Summary statistics: mean
by categories of: female (Gender)
female |      math     write      read
-------+------------------------------
male |  52.94505  50.12088  52.82418
female |   52.3945  54.99083  51.73394
-------+------------------------------
Total |    52.645    52.775     52.23
--------------------------------------
latabstat math write read, by(female)
\begin{table}[htbp]\centering
\caption{\label{}
\textbf{} }\begin{tabular} {@{} l r r r @{}} \\ \hline
\textbf{female } & \textbf{      math} & \textbf{     write} & \textbf{      read} \\
\hline
male  &   52.94505 &   50.12088 &   52.82418 \\
female  &    52.3945 &   54.99083 &   51.73394 \\
Total  &     52.645 &     52.775 &      52.23 \\
\hline
\multicolumn{4}{@{}l}{
\footnotesize{\emph{Source:} http://www.ats.ucla.edu/stat/stata/notes/hsb2.dta}}
\end{tabular}
\end{table}

We can then copy the code above to a LaTeX file and compile it. Here is the pdf file showing the table.

Example 2: Requesting more statistics

As you can see from the example below, the syntax for requesting more statistics is the same as tabstat.
tabstat write, by(female) s(mean sd) f(%5.2f)
Summary for variables: write
by categories of: female
female |      mean        sd
-------+--------------------
male |     50.12     10.31
female |     54.99      8.13
-------+--------------------
Total |     52.77      9.48
----------------------------
latabstat write, by(female) s(mean sd) f(%5.2f)
\begin{table}[htbp]\centering
\caption{\label{}
\textbf{} }\begin{tabular} {@{} l r r @{}} \\ \hline
\textbf{female } & \textbf{      mean} & \textbf{        sd} \\
\hline
male  &      50.12 &      10.31 \\
female  &      54.99 &       8.13 \\
Total  &      52.77 &       9.48 \\
\hline
\multicolumn{3}{@{}l}{\footnotesize{\emph{Source:}
http://www.ats.ucla.edu/stat/stata/notes/hsb2.dta}}
\end{tabular}
\end{table}
We can then copy the code above to a LaTeX file and compile it. Here is the pdf file showing the table.

Example 3: Table with a title

The last example table does not have a title. We can use the option cap of  latabstat to make a title for the table.

latabstat math write read, by(female) cap(Scores by Gender)
\begin{table}[htbp]\centering
\caption{\label{}
\textbf{Scores by Gender} }\begin{tabular} {@{} l r r r @{}} \\ \hline
\textbf{female } & \textbf{      math} & \textbf{     write} & \textbf{      read} \\
\hline
male  &   52.94505 &   50.12088 &   52.82418 \\
female  &    52.3945 &   54.99083 &   51.73394 \\
Total  &     52.645 &     52.775 &      52.23 \\
\hline
\multicolumn{4}{@{}l}{
\footnotesize{\emph{Source:} http://www.ats.ucla.edu/stat/stata/notes/hsb2.dta}}
\end{tabular}
\end{table}

We can then copy the code above to a LaTeX file and compile it. Here is the pdf file showing the table.

We can also put all the examples above together in one single LaTeX file and here is the pdf file corresponding to it.

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.