Site icon Stata.Professor : Your Partner in Research

Combine the outputs of a t-test plus a summarize using asdoc

Good morning professor Shah, I’m trying to combine the outputs of a t-test plus a summarize. using a piece of your code found on a Statalist post, I tried to replicate something like the following:
ttest mean_age, by(stupd)

*Get the relevant statistics
loc obs1 = `r(N_1)'
loc obs2 = `r(N_2)'
loc mean1 = `r(mu_1)'
loc mean2 = `r(mu_2)'
loc dif = `mean1' - `mean2'
loc stde = `r(se)'
loc pval = `r(p)'
dis `dif'

sum mean_age if stupd == 0
loc max1 = `r(max)'
loc min1 = `r(min)'

sum mean_age if stupd == 1
loc max2 = `r(max)'
loc min2 = `r(min)'

*Write these with asdoc using the row option


asdoc, row(`Age', `obs1', `obs2', `min1', `max1', `min2', `max2', `mean1', `mean2', `dif', `stde', `pval') replace
unfortunately, the output is an empty table. could you point me the mistakes I’m making? Thanks a lot in advance
Exit mobile version