user2146441
user2146441

Reputation: 228

Output pvalues as stars in manually run ttest/Add standard ttest with stars

This question is a follow on from one I'm not having luck with over on Statalist: http://www.statalist.org/forums/forum/general-stata-discussion/general/5559-using-estpost-estout-esttab-to-format-summary-stats

I have the following data that I'm creating a two-way crosstab with mean, median etc.

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

I can use `esttab' to produce a nicely formatted output of the two-way crosstab with stats.

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

How can I also add the `ttest' results above to the output? The only way I've found of doing it so far is by specifying a matrix and adding the results manually which is not very elegant.

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

I would like to format the pvalues as stars and add them to the value in the mean column: similar to what eststo and esttab do for co-efficients, t-stats and p-values in the output.

How can I either add the ttest to the first code sample, disregarding the matrix approach I tried or format the pvalues as stars and concatenate them to the mean column in the long-winded workaround I have above?

Upvotes: 1

Views: 1096

Answers (1)

dimitriy
dimitriy

Reputation: 9460

You can use estpost to add the results and then use esttab. Here is an example.

Upvotes: 1

Related Questions