使用frmttable以日期格式显示摘要统计信息

时间:2019-08-13 19:38:21

标签: latex stata

我试图在Stata中使用 community-contributed 命令frmttable来生成日期变量的表摘要统计信息。

但是,当我执行命令时,摘要统计信息不是日期格式,而是整数。我希望它们以MDY格式显示:%dtNN/DD/CCYY

问题如下所示:

                                               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 
                                          -------------------

我不考虑其他表导出命令,因为frmttable给了我最大的灵活性。我还试图将表导出到LaTeX中。

示例数据可在下面找到:

* 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

我使用的代码如下:

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 个答案:

答案 0 :(得分:3)

社区贡献的命令frmttable用于生成汇总统计信息的表,其格式可以通过sfmt()选项指定。

但是,如其帮助文件所建议的那样,在当前版本中,该 支持日期格式:

  

“ ...... fmtgrid的格式为fmt [,fmt ...] [\ fmt [,fmt ...] ...]],其中fmt为e,f,fc,g,或gc ...”

尝试以指定的格式运行frmttable确认了这一点:

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

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

社区贡献命令esttab提供了一种即用型解决方案:

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}