2
votes

I am trying to use the community-contributed command frmttable in Stata to generate a table summary statistics of date variables.

However, when I execute the command, the summary statistics are not in the date format, but rather are integers. I would like them to be displayed in a MDY format: %dtNN/DD/CCYY

The problem is shown below:

                                               Step Dates
                                          -------------------
                                           Step       Date  
                                          -------------------
                                           Step 1    17,206 
                                           Step 2    17,241 
                                           Step 3    17,258 
                                           Step 4    17,619 
                                           Step 5    17,958 
                                           Step 6    18,401 
                                           Step 7    18,464 
                                           Step 8    18,976 
                                           Step 9    18,965 
                                           Step 10   19,243 
                                           Step 11   19,064 
                                          -------------------

I am not considering other table exporting commands since frmttable gives me the most flexibility. I am also trying to export the table into LaTeX.

Example data can be found below:

* Example generated by -dataex-. To install: ssc install dataex
clear
input double Step_n float Date
  2 17206
  2 17234
  3 17241
  3 17339
  4 17258
  4 17626
  5 17619
  5 17619
  5 18155
  6 17958
  6 19339
  7 18401
  7 18662
  8 18464
  8 19001
8.5 18976
8.5 19267
  9 18965
9.5 19243
 10 19064
 10 20227
end
format %tdNN/DD/CCYY Date

The code I used is the following:

matrix m1 = J(11,1,.)
local i = 1

foreach s of numlist 2/8 8.5 9 9.5 10 {
    quietly summarize Date if Step_n==`s' 
    matrix m1[`i',1]=r(min)
    local i = `i' + 1
}

matrix rownames m1 = "Step 1" "Step 2" "Step 3" "Step 4" ///
    "Step 5" "Step 6" "Step 7" "Step 8" "Step 9" "Step 10" "Step 11"

matrix list m1, format(%tdNN/DD/CCYY)

frmttable using m1.tex, statmat(m1) title("Step Dates") ///
    sdec(0) ctitle("Step","Date") replace tex
1

1 Answers

3
votes

The community-contributed command frmttable is used to produce tables for summary statistics, the format of which can be specified by the sfmt() option.

However, as its help file suggests, in its current version this does not support date formats:

"...fmtgrid has the form fmt[,fmt...] [\ fmt[,fmt...] ...]], where fmt is either e, f, fc, g, or gc..."

An attempt to run frmttable with such a format specified confirms this:

. frmttable, statmat(m1) sfmt(%tdNN/DD/CCYY)

sfmt contains elements other than "e","f","g","fc", and "gc"
r(198);

The community-contributed command esttab offers an out-of-the-box solution:

esttab matrix(m1, fmt(%tdNN/DD/CCYY)), nomtitles ///
                                       collabel("Date") ///
                                       title("Step Dates") ///
                                       tex

\begin{table}[htbp]\centering
\caption{Step Dates}
\begin{tabular}{l*{1}{c}}
\hline\hline
            &     Date   \\
\hline
Step 1      &  02/09/2007\\
Step 2      &  03/16/2007\\
Step 3      &  04/02/2007\\
Step 4      &  03/28/2008\\
Step 5      &  03/02/2009\\
Step 6      &  05/19/2010\\
Step 7      &  07/21/2010\\
Step 8      &  12/15/2011\\
Step 9      &  12/04/2011\\
Step 10     &  09/07/2012\\
Step 11     &  03/12/2012\\
\hline\hline
\end{tabular}
\end{table}