【问题标题】:Display summary statistics in date format using frmttable使用 frmttable 以日期格式显示汇总统计信息
【发布时间】:2019-08-13 19:38:21
【问题描述】:

我正在尝试在 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

【问题讨论】:

    标签: latex stata


    【解决方案1】:

    community-contributed 命令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);
    

    community-contributed 命令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}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-19
      • 2021-12-06
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      • 2019-12-30
      相关资源
      最近更新 更多