【以下回答由 GPT 生成】
可以使用esttab命令将描述性统计结果和回归结果导出为一个表格,并且在回归结果表格中添加一行均值结果。具体步骤如下:
-
首先,安装estout包,它提供了更多的功能和选项来定制输出表格。在Stata中运行以下命令安装:
ssc install estout
-
然后,将描述性统计结果和回归结果保存在不同的变量中。在Stata中运行以下命令:
sysuse auto, clear
eststo clear
eststo: quietly summarize mpg, d
eststo: quietly regress price mpg weight, vce(robust)
-
接下来,使用esttab命令导出表格,并使用r(mean)函数计算不同类人群的Y均值。在Stata中运行以下命令:
esttab, cells("count(mean fmt_0) b(star fmt_2)") ///
b(A, label("(A) Y")) ///
b(B, label("(B) Y")) ///
b(C, label("(C) Y")) ///
label ///
collabels("Descriptive Statistics" "Regression Results") ///
title("Descriptive and Regression Results") ///
drop(_cons) ///
addstat("Mean Y") ///
stats(r(mean)) ///
/// specify variable formats, e.g., fmt_0, fmt_1, etc.
/// specify coefficients formats, e.g., fmt_0, fmt_1, etc.
///
/// add other options for customization of the table
以上代码中的fmt_0和fmt_2是为了指定输出格式,你可以根据需要进行修改。
请注意,在运行以上代码之前,确保你已经安装了estout包,并将数据准备好。此外,你可以根据需要自定义表格的其他选项和样式。
希望以上解决方案能够帮助到你。如果有任何问题,请随时向我提问。
如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^