Announcement

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

  • Adding lincom postestimation results to esttab regression table

    Dear Statalisters,

    I am trying to add some postestimation results from lincom to a regression table using esttab (from SJ). For this I use lincomest (from SSC) which stores the estimation results. What I would want is to have the lincomest results below the coefficients of the regression. I have tried using estadd but haven't managed to get it to work so far. Is this possible? I'm trying to avoid using scalars because then it is impossible to add significance stars.
    Code:
    sysuse auto, clear
    eststo: reg price c.mpg##foreign
    eststo: lincomest _b[mpg] + _b[1.foreign#c.mpg]
    esttab, nogaps nobase cells(b(fmt(3)) se(fmt(3)))
    
    
    --------------------------------------
                          (1)          (2)
                        price        price
                         b/se         b/se
    --------------------------------------
    mpg              -329.255            
                       74.985            
    1.foreign         -13.587            
                     2634.664            
    1.foreign#~g       78.888            
                      112.481            
    (1)                           -250.367
                                    83.840
    _cons           12600.538            
                     1527.888            
    --------------------------------------
    N                      74           74
    --------------------------------------

  • #2
    It would be difficult to combine the estimates as they pertain to two different models. However,

    I'm trying to avoid using scalars because then it is impossible to add significance stars
    this is not true. Here, what matters is sequence because you want the lincom results to be linked to your regression estimates, and you can only obtain the lincom results after the regression. This suggests that you need to run the regression at least twice, which is what I do below. With Stata's margins command, you no longer need lincomest from SSC.

    Code:
    sysuse auto, clear
    qui reg price c.mpg##foreign
    margins, expression(_b[mpg] + _b[1.foreign#c.mpg]) post
    mat r= r(table)
    eststo: reg price c.mpg##foreign
    estadd local mystat "`= cond(r[4,1]<0.01,"`:di %5.3f `=r[1,1]''***", ///
    cond(r[4,1]<0.05,"`:di %5.3f `=r[1,1]''**", ///
    cond(r[4,1]<0.1,"`:di %5.3f `=r[1,1]''*",  "`:di %5.3f `=r[1,1]''")))'"
    esttab, nogaps nobase cells(b(fmt(3)) se(fmt(3))) scalar("mystat My stat")

    Res.:

    Code:
    . esttab, nogaps nobase cells(b(fmt(3)) se(fmt(3))) scalar("mystat My stat")
    
    -------------------------
                          (1)
                        price
                         b/se
    -------------------------
    mpg              -329.255
                       74.985
    1.foreign         -13.587
                     2634.664
    1.foreign#~g       78.888
                      112.481
    _cons           12600.538
                     1527.888
    -------------------------
    N                      74
    My stat       -250.367***
    -------------------------

    Comment


    • #3
      Thank you Andrew, I didn't realize you could add significance stars like that. Very helpful.

      Comment


      • #4
        See also

        https://www.statalist.org/forums/for...dd-and-reghdfe

        for a command that does #2.

        Comment


        • #5
          Dear Andrew,

          how can I produce a similar table as you show in post 2, however if I have two or mor einteraction terms?
          Thank you!

          Comment


          • #6
            Hi Andrew, would you have any suggestions on how to include the SE in parenthesis for the linear combination from post 2? And to move these results to be located above the regression stats (r2 etc)?

            Thank you.

            Comment


            • #7
              carmen campagnolo Since this post I've made a package xlincom to assist with these kinds of things, maybe you find it useful.

              Code:
              ssc install xlincom
              sysuse auto, clear
              reg price c.mpg##foreign
              xlincom lin_com = _b[mpg] + _b[1.foreign#c.mpg], repost
              esttab, nogaps nobase eqlabels("Main" "Linear combinations", span)

              Comment


              • #8
                Wouter Wakker thanks for the response. Does this package work for Stata 16?

                I seem to get an error message when trying your code.

                xlincom lin_com = _b[mpg] + _b[1.foreign#c.mpg], repost

                lin_com: _b[mpg] + _b[1.foreign#c.mpg] = 0
                foreign#co: operator invalid
                r(198);

                end of do-file

                Would you know why this is?

                Comment


                • #9
                  This is very strange, I can run the code from #7 fine in Stata 15, 16 and 17.

                  Could you do set trace on and post the last couple of lines before getting the error when you run the code?

                  Comment


                  • #10
                    Hi Andrew Musau

                    I am using part of your code to add lincom coefficients with the associated significance stars. After the fourth line of the code below, STATA shows the following:


                    Code:
                    added macro:
                                 e(mystat) : "-0.115***"
                    but the outreg2 doesn't read the e(mystat) value in the addstat section. It gives me an error saying `invalid syntax'. Any idea on how I can fix this? My end goal is to have both coeffient and associated significance stars in the same cell, exactly like it is shown in e(mystat)


                    reghdfe att treat ebola treat_ebola if year==0, vce(robust) noabsorb
                    lincomest treat + treat_ebola
                    mat r= r(table)
                    matrix list r(table)
                    estadd local mystat "`= cond(r[4,1]<0.01,"`:di %5.3f `=r[1,1]''***", cond(r[4,1]<0.05,"`:di %5.3f `=r[1,1]''**", cond(r[4,1]<0.1,"`:di %5.3f `=r[1,1]''*", "`:di %5.3f `=r[1,1]''")))'"
                    outreg2 using table_a3, dec(3) nonotes nocons tex replace addstat(Attrition for Ebola=1, `e(mystat)') keep(treat treat_ebola) label

                    Comment


                    • #11
                      The added stars make the contents of the macro string. So you need:

                      Code:
                      addtext(Attrition for Ebola=1, `e(mystat)')

                      Comment


                      • #12
                        Thanks a bunch! Andrew Musau

                        Comment


                        • #13
                          Hi Andrew Musau there seems to be a problem

                          The code works fine but it no longer reports the treat_ebola coefficient in the second regression. I am pasting my full code below.


                          // Reg 1
                          reghdfe att treat if year==0, vce(robust) noabsorb
                          outreg2 using table_a3, replace dec(3) adjr2 nonotes tex label

                          // Reg 2
                          reghdfe gender treat ebola treat_ebola if year==0, vce(robust) noabsorb
                          lincomest treat + treat_ebola
                          mat r= r(table)
                          estadd local mystat "`= cond(r[4,1]<0.01,"`:di %5.3f `=r[1,1]''***", cond(r[4,1]<0.05,"`:di %5.3f `=r[1,1]''**", cond(r[4,1]<0.1,"`:di %5.3f `=r[1,1]''*", "`:di %5.3f `=r[1,1]''")))'"
                          outreg2 using table_a3, dec(3) nonotes nocons tex append addtext(Attrition for Ebola=1, `e(mystat)') keep(treat treat_ebola) label

                          I want something like this (figure below) with starts on "Attrition for Ebola=1"

                          Click image for larger version

Name:	exp1.JPG
Views:	1
Size:	34.9 KB
ID:	1711731


                          with the code above what I get is as follows (figure below)

                          Click image for larger version

Name:	exp2.JPG
Views:	1
Size:	32.8 KB
ID:	1711732

                          Comment


                          • #14
                            I cannot follow this. Attach some data example that reproduces the issue.

                            Comment


                            • #15
                              Andrew Musau Here you go:

                              Code:
                              * Example generated by -dataex-. For more info, type help dataex
                              clear
                              input float(year att) double(treat gender) float(ebola treat_ebola)
                              0 0 0 0 0 0
                              0 0 1 0 1 1
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 0 1 1 1 1
                              0 0 1 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 0 0
                              0 0 1 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 0 0
                              0 0 1 0 1 1
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 0 0 0 0 0
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 0 0
                              0 0 1 0 0 0
                              0 1 1 0 0 0
                              0 0 1 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 0 0
                              0 0 1 1 0 0
                              0 0 1 0 0 0
                              0 1 0 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 0 0
                              0 0 1 0 1 1
                              0 0 0 0 0 0
                              0 0 0 1 1 0
                              0 0 0 0 0 0
                              0 0 1 0 0 0
                              0 0 0 0 0 0
                              0 0 1 0 0 0
                              0 0 0 0 1 0
                              0 1 0 1 1 0
                              0 0 0 0 0 0
                              0 0 0 0 0 0
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 0 1 0 1 1
                              0 0 1 1 0 0
                              0 0 0 0 0 0
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 1 0
                              0 0 1 0 0 0
                              0 0 1 0 1 1
                              0 0 1 0 0 0
                              0 0 0 0 0 0
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 0 0
                              0 0 1 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 1 0
                              0 0 1 0 1 1
                              0 0 0 0 1 0
                              0 0 0 0 0 0
                              0 0 1 0 0 0
                              0 0 0 1 1 0
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 0 1 0 0 0
                              0 1 0 0 0 0
                              0 0 0 0 1 0
                              0 0 1 0 1 1
                              0 0 0 0 1 0
                              0 0 1 0 1 1
                              0 0 0 0 1 0
                              0 0 1 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 0 0
                              0 0 0 0 1 0
                              0 0 1 0 0 0
                              0 0 0 0 0 0
                              0 0 0 1 0 0
                              0 0 1 0 1 1
                              0 0 0 0 0 0
                              0 0 0 0 1 0
                              0 0 0 0 1 0
                              0 0 0 0 1 0
                              0 0 1 0 0 0
                              0 0 1 0 1 1
                              0 0 0 0 0 0
                              end
                              label values year year
                              label def year 0 "2015", modify
                              label values att att
                              label def att 0 "Retained", modify
                              label def att 1 "Attrited", modify
                              label values treat treat
                              label def treat 0 "Control", modify
                              label def treat 1 "Treatment", modify
                              label values gender gender
                              label def gender 0 "Female", modify
                              label def gender 1 "Male", modify

                              Comment

                              Working...
                              X