这个问题是我在Statalist上没有运气的问题: http://www.statalist.org/forums/forum/general-stata-discussion/general/5559-using-estpost-estout-esttab-to-format-summary-stats
我有以下数据,我正在创建一个带均值,中位数等的双向交叉表。
clear
input eventtime prefflag winner stakechange
1 1 1 10
1 2 1 5
2 1 0 50
2 2 0 31
2 1 1 51
2 2 1 20
1 1 0 10
2 2 1 10
2 1 0 5
3 2 0 8
4 2 0 8
5 2 0 8
5 2 1 8
3 1 1 8
4 1 1 8
5 1 1 8
5 1 1 8
end
我可以使用`esttab'来生成带有统计信息的双向交叉表的格式良好的输出。
eststo clear
bysort winner: eststo: estpost tabstat stakechange, by(eventtime) statistics(mean p25 p50 p75 count) columns(statistics) listwise nototal
bysort winner eventtime: ttest stakechange = 1
esttab, replace noisily cells("mean(fmt(2)) count(fmt(0)) p25(fmt(2)) p50(fmt(2)) p75(fmt(2))") noobs nomtitle nonumber
esttab using "test.tex", replace noisily cells("mean(fmt(2)) count(fmt(0)) p25(fmt(2)) p50(fmt(2)) p75(fmt(2))") noobs nomtitle nonumber
如何将上面的'ttest'结果添加到输出中?到目前为止我发现它的唯一方法是指定一个矩阵并手动添加结果,这不是很优雅。
eststo clear
matrix res = J(4,12,.)
local acrossvars = 6
local rown ""
foreach eventtime of numlist 2 3 4 5 {
foreach num of numlist 1 0 {
local i = `eventtime'
qui ttest stakechange = 1 if eventtime == `eventtime' & winner == `num'
matrix res[(`eventtime'-1),(`num' * `acrossvars')+1] = r(mu_1)
matrix res[(`eventtime'-1),(`num' * `acrossvars')+2] = r(p)
matrix res[(`eventtime'-1),(`num' * `acrossvars')+3] = r(N_1)
qui summarize stakechange if eventtime == `eventtime' & winner == `num', detail
matrix res[(`eventtime'-1),(`num' * `acrossvars')+4] = r(p25)
matrix res[(`eventtime'-1),(`num' * `acrossvars')+5] = r(p50)
matrix res[(`eventtime'-1),(`num' * `acrossvars')+6] = r(p75)
if (`num' ==1) local rown "`rown' `eventtime'"
}
}
matrix rownames res = `rown'
matrix colnames res = Mean Prob Count P25 P50 P75 Mean Prob Count P25 P50 P75
matlist res, underscore cspec(o4&o2 %10s & ///
%8.4g & %8.3g & %8.0g & %8.3g & %8.3g & %8.3g & ///
%8.4g & %8.3g & %8.0g & %8.3g & %8.3g & %8.3g ///
o2& ) rspec(&&&&&&) ///
rowtitle ("Eventtime")
我想将pvalues格式化为星号并将其添加到mean
列中的值:类似于eststo
和esttab
对系数的影响,t-stats和输出中的p值。
如何将ttest添加到第一个代码示例中,忽略我尝试的矩阵方法或将pvalues格式化为星号并将它们连接到我上面的冗长解决方法中的平均列?