Home Forums ASDOC : Easy Publication Quality Tables in Stata Combine the outputs of a t-test plus a summarize using asdoc

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • Edoardo
    Guest
    Post count: 118

    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

    Attaullah Shah
    Keymaster
    Post count: 69

    The mistake you are making is the declaration of the Age text as a macro, by enclosing it in the macro symbols. In fact, Age is just a text, it is not declared as a local macro with the loc command. The correct is given below.

    clear
    set obs 100
    gen mean_age = int(uniform() * 100)
    gen stupd = mod(_n,2)
    
    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
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.