[Tex/LaTex] Estout and dcolumn: Overriding decimal alignment

dcolumnhorizontal alignmenttables

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!

Best Answer

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.