Announcement

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

  • Displaying a Scalar in LaTeX table using esttab

    Hi,
    I have a question regarding using a locally stored scalar and exporting it to LaTeX

    I have used a stata package that corrects p-values and stores its result in e class that I have stored as follows:


    Code:
    eststo model1: reg y x, vce(cluster id)
    
    <run package that yields the e() class output and gives me corrected p-values>
    
    matrix n = e(AB)
    matrix list n
    scalar store_mat = n[1,1]
    Suppose, store_mat = 0.03

    Further, I run use the package again to get the e() matrix and store it again as follows

    Code:
    eststo model2: reg y x, vce(cluster id)
    <run package that yields the e() class output and gives me corrected p-values>
    
    matrix m = e(AB)
    matrix list m
    scalar store_mat_2= m[1,1]
    Suppose, store_mat_2 = 0.04

    Next, I want store_mat and store_mat2 to appear in my LaTeX table below the estimated coefficient, std errors, and p-value and assign stars based on the corrected p-values


    Code:
    #delimit ;
    esttab model1 model2   using "table.tex",
        replace cells(b(fmt(3) star)  se(par fmt(2)) p(par({ })) store_mat(par([ ])) store_mat_2(par([ ]))) label star(* 0.10 ** 0.05 *** 0.01)
        stats(N , label ("N") fmt(0)) style(tex)
        keep(dv)  noobs nonotes ;
    #delimit cr




    I understand that my usage of the esttab command is incorrect and i need to figure a way out to display the store_mat and store_mat_2 against respective models.
    Last edited by Patrick Que; 28 Oct 2020, 16:54.

  • #2
    esttab is from Stata Journal, as you are asked to explain in FAQ Advice #12. See

    Code:
    help estadd
    There is an illustrated example.

    Comment


    • #3
      Thanks, Andrew. My use case is different from the illustrated examples and hence I posted the question. I apologize for not mentioning it in my original post.

      Comment


      • #4
        Different how? You provide no reproducible example, but here is some technique.

        Code:
        webuse grunfeld, clear
        eststo model1: regress invest mvalue kstock
        *Hold corrected p-values in a matrix
        mat p2= (0.001, 0.91, 0.048)
        *Column names should coincide with variable names
        mat colnames p2 = mvalue kstock _cons
        estadd matrix p2
        esttab model1, cells(b(fmt(3) pvalue(p2) star)  se(par fmt(2)) p(par({ })) p2(par([ ] )))
        Res.:

        Code:
        . esttab model1, cells(b(fmt(3) pvalue(p2) star)  se(par fmt(2)) p(par({ })) p2(par([ ] )))
        
        ----------------------------
                              (1)  
                           invest  
                        b/se/p/p2  
        ----------------------------
        mvalue              0.116** 
                           (0.01)  
                          {0.000}  
                          [0.001]   
        kstock              0.231   
                           (0.03)  
                          {0.000}  
                          [0.910]   
        _cons             -42.714*  
                           (9.51)  
                          {0.000}  
                          [0.048]   
        ----------------------------
        N                     200  
        ----------------------------
        Last edited by Andrew Musau; 29 Oct 2020, 15:49.

        Comment


        • #5
          Hi Andrew,

          I have troubles adding more than one model to your example.
          Say I want to run the following estimates:

          Code:
          eststo model1: regress invest time kstock
          eststo model2: regress mvalue time kstock
          *Hold corrected p-values in a matrix
          mat p1= (0.01, 0.02, 0.03, 0.04, 0.05, 0.06)
          *Column names should coincide with variable names
          mat colnames p1 = time kstock _cons time kstock _cons
          estadd matrix p1
          esttab model1 model2, cells(b(fmt(3) pvalue(p2) star) se(par fmt(2)) p(par({ })) p1(par([ ] )))
          Attached is the (catastrophic) result I get.

          How can I get the corrected p-values of Matrix p1 at the right place?

          Thanks a lot!
          Olivia
          Attached Files

          Comment


          • #6
            Thanks for the reproducible example. Note that each model has its own set of results, so you need to define the p1 matrix for each model. As a matter of fact, that is exactly what is done for the coefficients' and variances' matrices.

            Code:
            webuse grunfeld
            eststo model1: regress invest time kstock
            *Hold corrected p-values in a matrix
            mat p1= (0.01, 0.02, 0.03)
            *Column names should coincide with variable names
            mat colnames p1 = time kstock _cons 
            estadd matrix p1
            eststo model2: regress mvalue time kstock
            *Hold corrected p-values in a matrix
            mat p1= (0.04, 0.05, 0.06)
            *Column names should coincide with variable names
            mat colnames p1 = time kstock _cons 
            estadd matrix p1
            esttab model1 model2, cells(b(fmt(3) pvalue(p1) star) se(par fmt(2)) p(par({ })) p1(par([ ] )))
            Res.:

            Code:
            . esttab model1 model2, cells(b(fmt(3) pvalue(p1) star) se(par fmt(2)) p(par({ })) p1(par([ ] )))
            
            --------------------------------------------
                                  (1)             (2)   
                               invest          mvalue   
                            b/se/p/p1       b/se/p/p1   
            --------------------------------------------
            time               -5.771*        -56.239*  
                               (2.29)         (15.96)   
                              {0.013}         {0.001}   
                              [0.010]         [0.040]   
            kstock              0.534*          2.686   
                               (0.04)          (0.31)   
                              {0.000}         {0.000}   
                              [0.020]         [0.050]   
            _cons              59.183*        930.814   
                              (23.61)        (164.22)   
                              {0.013}         {0.000}   
                              [0.030]         [0.060]   
            --------------------------------------------
            N                     200             200   
            --------------------------------------------

            Comment


            • #7
              Hi Andrew, thanks for the code above. How can I do the esttab without the "b/se/p/p1" in column title? Thanks

              Comment


              • #8
                Add the option:

                Code:
                collab(none)

                Comment


                • #9
                  Thanks a lot for the response.

                  Comment

                  Working...
                  X