Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to add the marks of significance level to a correlation table

    I am writing some syntaxes by using -esttab- to automatically create a correlation table with mean and sd of variables and save it to a .rft file. But I am not able to mark the significance level (i.e., multiple stars - * if p<.05, ** if p<.01, and *** if p<.001), can anyone help me?

    My codes are as below
    Code:
    use https://stats.idre.ucla.edu/stat/data/hsbdemo, clear
    
    ************Correlation Table************
    local varList read write math science
    
    estpost correlate `varList', matrix 
    
    matrix b = e(b)
    estpost sum `varList'
    foreach stat in mean sd {
        matrix tmp = e(`stat')
        matrix coleq tmp = `stat'
        matrix b = b, tmp
    }
    
    ereturn post b
    esttab ., ///
            order(mean: sd:) unstack b(2) ///
            nolz noobs not compress ///
            label replace 
    eststo clear

    I did NOT add the "nostar" to the esttab, so, I expected it to give me the stars. But the results are as below:


    Code:
    ----------------------------------------------------------------------------------------------
                           (1)                                                                    
                                                                                                  
                          mean           sd    reading~e    writing~e    math sc~e    science~e   
    ----------------------------------------------------------------------------------------------
    reading score        52.23        10.25         1.00                                          
    writing score        52.77         9.48          .60          1.00                             
    math score           52.65         9.37          .66           .62          1.00                
    science score        51.85         9.90          .63           .57           .63          1.00   
    ----------------------------------------------------------------------------------------------
    * p<0.05, ** p<0.01, *** p<0.001
    What I expected was like the table below (I added the stars by hands for the purpose of demonstration), anyone knows how to achieve it?

    Code:
    ----------------------------------------------------------------------------------------------
                           (1)                                                                    
                                                                                                  
                          mean           sd    reading~e    writing~e    math sc~e    science~e   
    ----------------------------------------------------------------------------------------------
    reading score        52.23        10.25         1.00                                          
    writing score        52.77         9.48          .60***          1.00                             
    math score           52.65         9.37          .66***           .62***          1.00                
    science score        51.85         9.90          .63***           .57***           .63***          1.00   
    ----------------------------------------------------------------------------------------------
    * p<0.05, ** p<0.01, *** p<0.001
Working...
X