Announcement

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

  • exporting pvalues (computed using ritest) to final regression table using esttab

    Hi,

    I am new to Stata. I need to export the pvalues that I have computed using ritest (randomization inference), which I have saved in a matrix, to the final regression table alongside the std errors and coefficients. The following is the code I have for now.

    Code:
    ...
    
    eststo: quietly areg GAD7_line_average_el CBT_el IHT_el GAD7_line_average, absorb(factcode) robust 
    
    sum GAD7_line_average_el if PC==1
    estadd scalar Control_Mean = r(mean)
    
    * Randomization Inference GAD-7 *
    
    ritest CBT _b[CBT], reps(100) seed(125) strata(factcode): quietly areg GAD7_line_average_el CBT_el IHT_el GAD7_line_average, absorb(factcode) robust
    
    matrix pvalues_CBT_GAD7 = r(p)
    mat colnames pvalues_CBT_GAD7 = "Prevalence of Anxiety (GAD-7>=8)"
    mat rownames pvalues_CBT_GAD7 = "Skills Training"
    
    ritest IHT _b[IHT], reps(100) seed(125) strata(factcode): quietly areg GAD7_line_average_el CBT_el IHT_el GAD7_line_average, absorb(factcode) robust
    
    matrix pvalues_IHT_GAD7 = r(p)
    mat colnames pvalues_IHT_GAD7 = "Prevalence of Anxiety (GAD-7>=8)"
    mat rownames pvalues_IHT_GAD7 = "Health Education" 
    
    ** Regressing PHQ9 **
    
    eststo: quietly areg PHQ9_line_average_el CBT_el IHT_el PHQ9_line_average, absorb(factcode) robust 
    sum PHQ9_line_average_el if PC==1
    estadd scalar Control_Mean = r(mean)
    
    * Randomization Inference PHQ-9 *
    
    ritest CBT _b[CBT], reps(100) seed(125) strata(factcode): quietly areg PHQ9_line_average_el CBT_el IHT_el PHQ9_line_average, absorb(factcode) robust 
    
    matrix pvalues_CBT_PHQ9 = r(p)
    mat colnames pvalues_CBT_PHQ9 = "Prevalence of Depression (PHQ-9>=10)"
    mat rownames pvalues_CBT_PHQ9 = "Skills Training"
    
    ritest IHT _b[IHT], reps(100) seed(125) strata(factcode): quietly areg PHQ9_line_average_el CBT_el IHT_el PHQ9_line_average, absorb(factcode) robust 
    
    matrix pvalues_IHT_PHQ9 = r(p)
    mat colnames pvalues_IHT_PHQ9 = "Prevalence of Depression (PHQ-9>=10)"
    mat rownames pvalues_IHT_PHQ9 = "Health Education" 
    
    matrix pvalues = pvalues_CBT_GAD7,pvalues_CBT_PHQ9\pvalues_IHT_GAD7,pvalues_IHT_PHQ9
    
    estadd matrix pvalues = pvalues
    
    ** Tabulating the output **
    
    esttab using table8_RI.csv, cells(b(fmt(2) star) se(fmt(2) par) pvalues(fmt(2) par([ ]))) label title(Table 8: Impact on Workers'Psychological Well-Being) nonumbers mtitles ("Prevalence of Anxiety (GAD-7>=8)" "Prevalence of Depression (PHQ-9>=10)") star(* 0.1 ** 0.05 *** 0.01) coeflabels(CBT_el "Skills Training" IHT_el "Health Education" Control_Mean "Control Mean") keep(CBT_el* IHT_el*) stats(Control_Mean N ar2, fmt(2 0 2) labels("Control Mean" "N" "Adj. R-sq")) 
    
    eststo clear
    Ideally, the output should be in the following format (the values in square brackets is what I need)

    Click image for larger version

Name:	table 8.jpg
Views:	1
Size:	40.3 KB
ID:	1682701

  • #2
    Does this example help?

    Code:
    sysuse auto, clear
    
    eststo reg1 : reg price trunk
    
    ritest trunk _b[trunk], reps(100) seed(12345) : `e(cmdline)'
    matrix pboot = r(p)
    mat colnames pboot = trunk
    estadd matrix pboot = pboot : reg1
    
    esttab reg1, cells(b se(par) pboot(par([ ]))) label nocons

    Comment


    • #3
      @Nils Enevoldsen thank you! How would I replicate the above that you had mentioned when running for multiple regressions as in my case? Since I would have mutiple matrices to save the data each time I run a ritest. I am sorry I am a little confused about this.

      Comment


      • #4
        Code:
        *** (2) Run the regressions ***
        
        ** Regressing GAD7 **
        
        eststo reg1: quietly areg GAD7_line_average_el CBT_el IHT_el GAD7_line_average, absorb(factcode) robust
        
        sum GAD7_line_average_el if PC==1
        estadd scalar Control_Mean = r(mean)
        
        * Randomization Inference GAD-7 *
        
        ritest CBT_el _b[CBT_el], reps(100) seed(125) strata(factcode): quietly areg GAD7_line_average_el CBT_el IHT_el GAD7_line_average, absorb(factcode) robust
        
        matrix pvalues_CBT_GAD7 = r(p)
        mat colnames pvalues_CBT_GAD7 = "pvalue Skills Training"
        mat rownames pvalues_CBT_GAD7 = "Skills Training"
        
        
        ritest IHT_el _b[IHT_el], reps(100) seed(125) strata(factcode): quietly areg GAD7_line_average_el CBT_el IHT_el GAD7_line_average, absorb(factcode) robust
        
        matrix pvalues_IHT_GAD7 = r(p)
        mat colnames pvalues_IHT_GAD7 = "pvalue Health Education"
        mat rownames pvalues_IHT_GAD7 = "Health Education"
        
        matrix pvalues_GAD7 = pvalues_CBT_GAD7,pvalues_IHT_GAD7
        estadd matrix pvalues_GAD7 : reg1
        
        ** Regressing PHQ9 **
        
        eststo reg2: quietly areg PHQ9_line_average_el CBT_el IHT_el PHQ9_line_average, absorb(factcode) robust
        sum PHQ9_line_average_el if PC==1
        estadd scalar Control_Mean = r(mean)
        
        * Randomization Inference PHQ-9 *
        
        ritest CBT_el _b[CBT_el], reps(100) seed(125) strata(factcode): quietly areg PHQ9_line_average_el CBT_el IHT_el PHQ9_line_average, absorb(factcode) robust
        
        matrix pvalues_CBT_PHQ9 = r(p)
        mat colnames pvalues_CBT_PHQ9 = "pvalue Skills Training"
        mat rownames pvalues_CBT_PHQ9 = "Skills Training"
        
        ritest IHT_el _b[IHT_el], reps(100) seed(125) strata(factcode): quietly areg PHQ9_line_average_el CBT_el IHT_el PHQ9_line_average, absorb(factcode) robust
        
        matrix pvalues_IHT_PHQ9 = r(p)
        mat colnames pvalues_IHT_PHQ9 = "pvalue Health Education"
        mat rownames pvalues_IHT_PHQ9 = "Health Education"
        
        matrix pvalues_PHQ9 = pvalues_CBT_PHQ9,pvalues_IHT_PHQ9
        estadd matrix pvalues_PHQ9 : reg2
        
        ** Tabulating the output **
        
        esttab reg1 reg2, cells("b(fmt(2) star)" "se(fmt(2) par)" "pvalues_GAD7(fmt(2) par([ ]))" "pvalues_PHQ9(fmt(2) par([ ]))") label title(Table 8: Impact on Workers'Psychological Well-Being) nonumbers mtitles ("Prevalence of Anxiety (GAD-7>=8)" "Prevalence of Depression (PHQ-9>=10)" "pvalues GAD7" "pvalues PHQ9") star(* 0.1 ** 0.05 *** 0.01) coeflabels(CBT_el "Skills Training" IHT_el "Health Education" Control_Mean "Control Mean") stats(Control_Mean N ar2, fmt(2 0 2) labels("Control Mean" "N" "Adj. R-sq")) drop(_cons GAD7_line_average PHQ9_line_average)
        
        eststo clear
        @Nils Enevoldsen when the code is run in the manner you had mentioned the table output is displayed as below. However, I want the output to be in the form of the table I had posted earlier in #1

        Attached Files
        Last edited by Sanj Ari; 22 Sep 2022, 10:32.

        Comment

        Working...
        X