控制汇总表中每个变量的小数

时间:2019-06-12 07:40:29

标签: stata

我正在尝试使用 community-contibuted 命令estout在Stata中获取汇总表。

但是,我想指定每个变量显示的小数位数,而不是每个摘要统计信息的默认小数位数。

正如您在下面的代码中看到的那样,我知道如何控制整个摘要统计信息的小数(例如,显示的平均值不包含小数):

* Summary statistics

eststo clear
estpost tabstat length weight, stat(mean median sd min max n) columns(statistics)

esttab using summstat1.rtf, cells("mean(label(Mean) fmt(2)) p50(label(Median) 
fmt(0)) sd(label(ST. Dev) fmt(2)) min(label(Min) fmt(2)) max(label(Max) fmt(2)) 
count(label(N) fmt(0))") label title("Summary Statistics") nonumbers lines noobs replace

我具体想要的是以下内容:

  • length变量的格式为175(即无小数)
  • 要设置格式的weight变量,例如60.545(即三个小数)

当然,我可以尝试通过将因子10除以或乘以来缩放变量,但这不是我的问题,这是不希望的。

1 个答案:

答案 0 :(得分:2)

对于cells()选项中的每个摘要统计信息,您可以指定多个格式。

请考虑以下mean的简化示例:

sysuse auto, clear
eststo clear

estpost tabstat mpg price length weight, stat(mean) columns(statistics)

esttab, cells("mean(label(Mean) fmt(0 3 5 1))") 
        label title("Summary Statistics") ///
        nonumbers lines noobs 

Summary Statistics
---------------------------------

                             Mean
---------------------------------
Mileage (mpg)                  21
Price                    6165.257
Length (in.)            187.93243
Weight (lbs.)              3019.5
---------------------------------