5

I'm using estout (esttab actually) to produce a table in Latex from Stata. I'm using the dcolumn package to align the decimal places in my table.

I want to override the alignment for a single row; to be specific the number of observations row. Is there a way of doing this? Or, equivalents, if there a way to prefix each element in a row with "\multicolumn{1}{c}{" and suffix with "}", which would override the dcolumn alignment?

Example:

\begin{table}[htbp]\centering
\caption{My Table}
\begin{tabular}{l*{3}{D{.}{.}{-1}}}
\toprule        
                    &\multicolumn{1}{c}{Mean/s.d.}&\multicolumn{1}{c}{Mean/s.d.}&\multicolumn{1}{c}{Mean/s.d.}\\
\midrule
Var A               &        8.68&        8.51&        8.92\\
                    &        2.42&        2.51&        2.26\\
Var B               &        2.14&        1.98&        2.37\\
                    &        1.33&        1.29&        1.35\\
\midrule
Observations        &       38040&       22054&       15986\\
\bottomrule
\end{tabular}
\end{table}

Thanks!

migrated from stackoverflow.com Aug 1 '11 at 4:58

This question came from our site for professional and enthusiast programmers.

4

The excellent siunitx package would make things a bit easier.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[tableposition=top]{caption}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
  \begin{table}[!ht]
    \caption{My Table}
    \centering
    \begin{tabular}{l*{3}{S}}\toprule        
                   & {Mean/s.d.} & {Mean/s.d.} &{Mean/s.d.} \\ \midrule
      Var A        & 8.68        & 8.51        & 8.92       \\
                   & 2.42        & 2.51        & 2.26       \\ \addlinespace
      Var B        & 2.14        & 1.98        & 2.37       \\
                   & 1.33        & 1.29        & 1.35       \\ \midrule 
      Observations & {38040}     & {22054}     & {15986}    \\ \bottomrule
    \end{tabular}
  \end{table}
\end{document}

The additional grouping with curly braces lets the concerned cell content appear as simple text and not as a number to be parsed. Details for customization in the package manual.

1

Have you tried playing with the layout suboption of stats? It looks like it accepts the text entry, so you might want to try something like

estout ... , stats(N , layout("\multicolumn{1}{c}{@}"))

Hm. If I try it as

    sysuse auto, clear
    reg mpg wei for
    estout , stats(N , layout("\multicolumn{1}{c}{@}"))

it seems to produce the formatting in the variables column, as well. Ah well.

  • The stats(.) option does work, but requires a slight modification: stats(N,layout("\multicolumn{1}{c}{@} label("Observations")) - this overrides the multicolumn wrapper around the variable name. Thanks StasK! – user870029 Aug 3 '11 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.