Announcement

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

  • Esttab: Store value of matrix and display in tex-table

    Dear All,

    I am encountering the following issue. I want to compute a mean after a regression with the mean function ("sum" does not work with svy), and then retrieve & store the mean value to export it as tex table.
    In fact, I would like to add the values to the "stats" in the lower part of the table. My code/my first tries look like this:

    Code:
    svy: reg y1 x1 x2 x3
    estimates store t1
    svy: mean y1 if e(sample)==1
    estadd matrix m = e(b)
    estadd scalar m1 = e(b)[1,1]
    estadd local cFE \ding{51}
    estadd local sFE \ding{51}
    estadd local csFE \ding{51}
    
    svy: reg y1 x1 x2 x4
    estimates store t2
    svy: mean y1 if e(sample)==1
    estadd matrix m = e(b)
    estadd scalar m1 = e(b)[1,1]
    estadd local cFE \ding{51}
    estadd local sFE \ding{51}
    estadd local csFE \ding{51}
    
    svy: reg y1 x1 x2 x5
    estimates store t3
    svy: mean y1 if e(sample)==1
    estadd matrix m = e(b)
    estadd scalar m1 = e(b)[1,1]
    estadd local cFE \ding{51}
    estadd local sFE \ding{51}
    estadd local csFE \ding{51}
    
    esttab t1 t2 t3 using "test.tex", booktabs fragment replace ///
        se(%3.2f) b(2) label alignment(S S S S) ///
        star(* 0.10 ** 0.05 *** 0.01) nonotes nomtitles ///
        stats(m1 cFE sFE csFE N, fmt(%3.2f 0 0 0 0)

    But this code does not work, I do not manage to display the stored numerical value of the mean of each regression in the stats of the table. Might anyone have an idea by what it is caused?

    Many thanks in advance!

  • #2
    estout is from the Stata Journal/ SSC (FAQ Advice #12). You may want to check out this recent thread https://www.statalist.org/forums/for...d-post-resetxt. However, note that you will increase your chances of getting a helpful reply by providing a reproducible example that replicates the issue.

    Comment


    • #3
      Hi Andrew,

      Many thanks for your answer and your tips. I am just afraid the other threads do not help in my case.

      Here is an easily reproducible example with the auto data:

      Code:
      sysuse auto, clea
      
      reg price mpg rep78
      estimates store t1
      mean price
      estadd scalar m1 = e(b)[1,1]
      
      esttab t1, booktabs fragment replace se(%3.2f) b(2) label star(* 0.10 ** 0.05 *** 0.01) nonotes nomtitles stats(m1 N, fmt(%3.2f 0) label("Mean dep. variable" "N"))
      In this case, you can see that the value of the mean is successfully stored in the scalar m1, but not in the esttab table. However, if I do the following, it works:

      Code:
      sysuse auto, clear
      
      reg price mpg rep78
      estimates store t1
      sum price
      
      estadd scalar m1 = r(mean)
      
      esttab t1, booktabs fragment replace se(%3.2f) b(2) label star(* 0.10 ** 0.05 *** 0.01) nonotes nomtitles stats(m1 N, fmt(%3.2f 0) label("Mean dep. variable" "N"))
      However, I need the "mean" function, since I want to apply survey weights with svy. Any help is appreciated. Many thanks!

      Comment


      • #4
        Code:
        estadd scalar m1 = `=e(b)[1,1]': t1
        Last edited by Andrew Musau; 30 Nov 2021, 07:27.

        Comment


        • #5
          Implicit in Andrew's answer is that the problem with your code is that the mean command is itself an estimation command, and it creates a new set of estimates that replaces those from the regression in memory. The summarize command is not an estimation command, and after it was run the t1 estimates were still in memory and estadd added the scalar to those estimates.

          Comment


          • #6
            ...and so the quotation marks (always) let us assign the retrieved value of a matrix to certain stored estimates, like t1 here? Thank you both.

            Comment

            Working...
            X