Announcement

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

  • using etable to collect results from nlcom

    Dear Stata Users,

    I would like to use etable to collect some results from several nlcom commands and turn them into a nice table.
    Can anyone tell me how to add significance stars and change the row label from "_nl_1" to something nicer?

    I included options in my etable command that should do those things, but they do not seem to be working.
    It would also be useful to know how to add the s.e.

    Thanks,
    Jeremy

    Code:
    sysuse nlsw88.dta, clear
    
    *examine: race ---> experience ---> wages
    gsem (c.ttl_exp <- i.race ) (wage <- c.ttl_exp i.race)  
    est store model1
        
    *calculate the indirect effect of black on wages and post it to the results    
    nlcom _b[ttl_exp:2.race]*(_b[wage:ttl_exp]), post
    est store iblack
    
    est restore model1
    nlcom _b[ttl_exp:3.race]*(_b[wage:ttl_exp]), post
    est store other
    
    est dir
    
    *make a table of the indirect effects
    etable, estimates(black other) column(estimates) /// 
         title(Mediation tests: race-->exp--> wages) ///
         cstat(_r_b, nformat(%4.3f) label(Indirect_Effect)) ///
         showstars showstarsnote
    
    
    
    Mediation tests: race-->exp--> wages
    ----------------------------------
                           black other
    ----------------------------------
    _nl_1                  0.084 0.043
    Number of observations  2246  2246
    ----------------------------------
    ** p<.01, * p<.05

  • #2

    The stars code in etable is working, your example lacks any p-values that meet the labeling rules.

    etable hides the levels of the result dimension from the headers. You can use collect style header to show your custom label; however, I would suggest you add a label for the _nl_1 level in dimension colname instead.

    Here is a modified version of the above example; my changes/additions are highlighted in blue.
    Code:
    sysuse nlsw88.dta, clear
    
    *examine: race ---> experience ---> wages
    gsem (c.ttl_exp <- i.race ) (wage <- c.ttl_exp i.race)
    est store model1
    
    *calculate the indirect effect of black on wages and post it to the results
    nlcom _b[ttl_exp:2.race]*(_b[wage:ttl_exp]), post
    est store black        // [sic] original post shows "iblack"
    
    est restore model1
    nlcom _b[ttl_exp:3.race]*(_b[wage:ttl_exp]), post
    est store other
    
    est dir
    
    *make a table of the indirect effects
    etable, estimates(black other) column(estimates) ///
         title(Mediation tests: race-->exp--> wages) ///
         cstat(_r_b, nformat(%4.3f) label(Indirect_Effect)) ///
         cstat(_r_p, nformat(%4.3f)) ///
         showstars showstarsnote
    
    * query the layout to see what dimensions are being used in the row
    * specification
    collect layout
    * add a label to use in the row header
    collect label levels colname _nl_1 "Indirect Effect", modify
    * replay the table showing this new label
    collect preview
    
    * see what the rules are for showing labels for significant stars
    collect query stars
    * use bigger p-value cutoffs to show that the labeling logic is working
    collect stars _r_p .1 "**" .5 "*", attach(_r_b) dimension
    collect preview
    Here is the resulting table.
    Code:
    Mediation tests: race-->exp--> wages
    ------------------------------------
                            black  other
    ------------------------------------
    Indirect Effect        0.084 * 0.043
                           0.262   0.886
    Number of observations  2246    2246
    ------------------------------------

    Comment


    • #3
      Thank you Jeff! What if I also wanted to label the 2nd line of results "P-value" and put them in parentheses?

      Comment


      • #4
        I find it redundant to have both p-values and significance stars. Choose one. You normally will want to include a note at the foot of the table to indicate the statistic in parentheses. Otherwise, the same way you label the "Indirect effect" should also work for the p-value. The wanted code is highlighted.

        Code:
        sysuse nlsw88.dta, clear
        
        *examine: race ---> experience ---> wages
        gsem (c.ttl_exp <- i.race ) (wage <- c.ttl_exp i.race)
        est store model1
        
        *calculate the indirect effect of black on wages and post it to the results
        nlcom _b[ttl_exp:2.race]*(_b[wage:ttl_exp]), post
        est store black        // [sic] original post shows "iblack"
        
        est restore model1
        nlcom _b[ttl_exp:3.race]*(_b[wage:ttl_exp]), post
        est store other
        
        est dir
        
        *make a table of the indirect effects
        etable, estimates(black other) column(estimates) ///
             title(Mediation tests: race-->exp--> wages) ///
             cstat(_r_b, nformat(%4.3f) label(Indirect_Effect)) ///
             cstat(_r_p, nformat(%4.3f)) ///
             showstars showstarsnote note({it:p}-values in parentheses)
        
        * query the layout to see what dimensions are being used in the row
        * specification
        collect layout
        * add a label to use in the row header
        collect label levels colname _nl_1 "Indirect Effect", modify
        * replay the table showing this new label
        collect preview
        
        * see what the rules are for showing labels for significant stars
        collect query stars
        * use bigger p-value cutoffs to show that the labeling logic is working
        collect stars _r_p .1 "**" .5 "*", attach(_r_b) dimension
        
        *Place statistic within parentheses
        collect style cell result[_r_p], sformat("(%s)")
        
        collect preview
        Res.:

        Code:
        . collect preview
        
        Mediation tests: race-->exp--> wages
        ----------------------------------------
                                 black    other
        ----------------------------------------
        Indirect Effect          0.084 *   0.043
                               (0.262)   (0.886)
        Number of observations    2246      2246
        ----------------------------------------
        ** p<.1, * p<.5
        p-values in parentheses

        Comment


        • #5
          Fantastic! Thank you Andrew! One last little detail . . . I can't seem to find where the "Number of observations" label is stored. I would rather just have "N" as the label.

          Comment


          • #6
            Code:
            sysuse nlsw88.dta, clear
            
            *examine: race ---> experience ---> wages
            gsem (c.ttl_exp <- i.race ) (wage <- c.ttl_exp i.race)
            est store model1
            
            *calculate the indirect effect of black on wages and post it to the results
            nlcom _b[ttl_exp:2.race]*(_b[wage:ttl_exp]), post
            est store black        // [sic] original post shows "iblack"
            
            est restore model1
            nlcom _b[ttl_exp:3.race]*(_b[wage:ttl_exp]), post
            est store other
            
            est dir
            
            *make a table of the indirect effects
            etable, estimates(black other) column(estimates) ///
                 title(Mediation tests: race-->exp--> wages) ///
                 cstat(_r_b, nformat(%4.3f) label(Indirect_Effect)) ///
                 cstat(_r_p, nformat(%4.3f)) ///
                 showstars showstarsnote note({it:p}-values in parentheses)
            
            * query the layout to see what dimensions are being used in the row
            * specification
            collect layout
            * add a label to use in the row header
            collect label levels colname _nl_1 "Indirect Effect", modify
            * replay the table showing this new label
            collect preview
            
            * see what the rules are for showing labels for significant stars
            collect query stars
            * use bigger p-value cutoffs to show that the labeling logic is working
            collect stars _r_p .1 "**" .5 "*", attach(_r_b) dimension
            
            *Place statistic within parentheses
            collect style cell result[_r_p], sformat("(%s)")
            
            *Relabel Number of observations
            collect label levels result N "N", modify
            
            collect preview
            Res.:

            Code:
            . collect preview
            
            Mediation tests: race-->exp--> wages
            ---------------------------------
                              black    other 
            ---------------------------------
            Indirect Effect   0.084 *   0.043
                            (0.262)   (0.886)
            N                  2246      2246
            ---------------------------------
            ** p<.1, * p<.5
            p-values in parentheses

            Comment

            Working...
            X