Announcement

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

  • Order of lincom output within a regression results table

    Dear all
    I was wondering whether it is possible to determine the order of estimates AND lincom output of a regression? Actually, I know this is possible for regression coefficients using the order command. However, I do not know how to do this for the lincom output.
    I am estimating the following regression:
    reg Cln c.TW#i.Poor c.TS#i.Poor c.TK#i.Poor c.TR#i.Poor if xURBAN ==0 , cluster(DISTRICT)
    eststo main_all
    lincom c.TW#1.Poor-c.TW#0.Poor
    estadd local TWdiff_p=round(r(p),0.0001)
    lincom c.TS#1.Poor-c.TS#0.Poor
    estadd local TSdiff_p=round(r(p),0.0001)
    lincom c.TK#1.Poor-c.TK#0.Poor
    estadd local TKdiff_p=round(r(p),0.0001)
    lincom c.TR#1.Poor-c.TR#0.Poor
    estadd local TRdiff_p=round(r(p),0.0001)
    This regression reports the TW, TS, TK and TR coefficients separately for Poor and Nonpoor. In addition, I would like to report the p value of significant difference of the estimates for Poor(1) and Non-Poor(0) that I obtain using lincom after each interaction. Is there a way to do this automatically?

    Thank you a lot.

    Best,

    Barbora

  • #2
    You can add these as stats and define the order there, see

    https://www.statalist.org/forums/for...gression-table

    Comment


    • #3
      Dear Andrew,
      thanks a lot for engaging. I actually am able to add the lincom output into the same regression. However, I am having difficulties to define their position. All the lincom output appears at the bottom of the table. However, i would like to position the p value of the significant difference of the effect of TW between Poor and Non-Poor below them. And the same for the effct of TS.
      Is there a way to do this?

      Comment


      • #4
        There is a difference between coefficients and scalars. You cannot add the lincom results as coefficients of the model they are based on, but you can add them as scalars (at the bottom of the table). Alternatively, you can add them as coefficients of a different model. Here is a reproducible example of the latter.

        Code:
        sysuse auto, clear
        reg price i.foreign#(c.weight c.mpg c.rep78), cluster(make)
        eststo est1
        margins, expression(_b[0.foreign#c.weight]-_b[1.foreign#c.weight]) post
        *CREATE PROGRAM TO RENAME COLNAME
        program colrename, eclass
        mat b= e(b)
        mat colname b = "difference"
        erepost b = b, rename
        end
        colrename
        eststo est2
        esttab, order(0.foreign#c.weight 1.foreign#c.weight difference) nonumbers noobs
        Res.:

        Code:
        --------------------------------------------
                            price                   
        --------------------------------------------
        0.foreign#~t        3.864***                
                           (4.38)                   
        
        1.foreign#~t        7.205***                
                           (4.38)                   
        
        difference                         -3.341***
                                          (-3.34)   
        
        0.foreign#~g        127.7                   
                           (0.99)                   
        
        1.foreign#~g        97.63                   
                           (1.16)                   
        
        0.foreign~78        72.69                   
                           (0.21)                   
        
        1.foreign~78       -746.1                   
                          (-1.69)                   
        
        _cons             -9537.1                   
                          (-1.94)                   
        --------------------------------------------
        t statistics in parentheses
        * p<0.05, ** p<0.01, *** p<0.001

        Comment


        • #5
          this is great! thank you!

          Comment


          • #6
            Is there a way to have the difference for other interactions all in one column?
            Cause otherwise if everything is stored as a new regression the table will become giant.
            Last edited by Barbora Sedova; 30 Sep 2019, 16:19.

            Comment


            • #7
              Yes... with a bit of rigging.

              Code:
              sysuse auto, clear
              eststo clear
              *RUN INITIAL REGRESSION AND STORE ESTIMATES
              reg price i.foreign#(c.weight c.mpg c.rep78), cluster(make)
              eststo est1
              
              *SAVE LINCOM COEFFICIENTS
              local interactionvars "c.weight c.mpg c.rep78" 
              local i=1
              foreach var of local interactionvars{
              qui reg price i.foreign#(c.weight c.mpg c.rep78), cluster(make)
              margins, expression(_b[0.foreign#`var']-_b[1.foreign#`var']) post
              scalar b`i'= _b[_cons]
              scalar V`i'= e(V)[1,1]
              local ++i
              }
              
              *GENERATE REGRESSION WITH COEFFICIENTS EQUAL TO LINCOM ESTIMATES (if 3)
              forval i=1/3{
              gen zreg`i'=0
              }
              reg price zreg*, nocons
              
              *DEFINE PROGRAM TO REPLACE COEF. & VARIANCE MATRIX
              program repostbV, eclass
              mat b= e(b)
              mat V= e(V)
              forval i=1/3{
              mat b[1,`i']= b`i'
              mat V[`i',`i']= V`i'
              }
              *RENAME COLUMNS (3 IN TOTAL HERE)
              mat colname b = difference1 difference2 difference3
              erepost b = b, rename
              erepost V = V, rename
              end
              
              *RUN REPOST COMMAND
              repostbV
              
              *STORE RESULTS
              eststo est2
              
              *OUTPUT RESULTS (ORDERED)
              esttab, order(0.foreign#c.weight 1.foreign#c.weight ///
              difference1 0.foreign#c.mpg 1.foreign#c.mpg difference2 ///
              0.foreign#c.rep78 1.foreign#c.rep78 difference3) ///
              nonumbers noobs mtitle("price" "")coeflabel(difference1 ///
              "difference" difference2 "difference" difference3 "difference")

              Res.:

              Code:
              --------------------------------------------
                                  price                  
              --------------------------------------------
              0.foreign#~t        3.864***                
                                 (4.38)                  
              
              1.foreign#~t        7.205***                
                                 (4.38)                  
              
              difference                         -3.341**
                                                (-3.34)  
              
              0.foreign#~g        127.7                  
                                 (0.99)                  
              
              1.foreign#~g        97.63                  
                                 (1.16)                  
              
              difference                          30.04  
                                                 (0.42)  
              
              0.foreign~78        72.69                  
                                 (0.21)                  
              
              1.foreign~78       -746.1                  
                                (-1.69)                  
              
              difference                          818.8  
                                                 (1.48)  
              
              _cons             -9537.1                  
                                (-1.94)                  
              --------------------------------------------
              t statistics in parentheses
              * p<0.05, ** p<0.01, *** p<0.001
              Last edited by Andrew Musau; 30 Sep 2019, 18:50.

              Comment


              • #8
                Thank you very much. Actually, the code does not seem to function for me. I get several error messages.
                For instance, I get an error message when I run the command:
                Warning: expression() does not contain predict() or xb().
                Warning: prediction constant over observations.

                This is after:
                foreach var of local interactionvars{ qui reg price i.foreign#(c.weight c.mpg c.rep78), cluster(make) margins, expression(_b[0.foreign#`var']-_b[1.foreign#`var']) post scalar b`i'= _b[_cons] scalar V`i'= e(V)[1,1] local ++i }


                Or I get the following message:


                *RUN REPOST COMMAND

                .
                . repostbV
                V1 not found




                Do you know what can be causing this? Thanks!
                Last edited by Barbora Sedova; 01 Oct 2019, 10:45.

                Comment


                • #9
                  Also, here is another problem that appears when I run the command:
                  reg price zreg*, nocons
                  note: zreg1 omitted because of collinearity
                  note: zreg2 omitted because of collinearity
                  note: zreg3 omitted because of collinearity

                  Comment


                  • #10
                    These errors are of no consequence, ignore them. If you run the whole block of code in a do file, you should get the table displayed at the bottom of #7.

                    Comment


                    • #11
                      Actually, the table that I get is the following:


                      --------------------------------------------
                      price
                      --------------------------------------------
                      0.foreign#~t 3.864***
                      (4.38)

                      1.foreign#~t 7.205***
                      (4.38)

                      difference


                      0.foreign#~g 127.7
                      (0.99)

                      1.foreign#~g 97.63
                      (1.16)

                      difference


                      0.foreign~78 72.69
                      (0.21)

                      1.foreign~78 -746.1
                      (-1.69)

                      difference


                      zreg1 0
                      (.)

                      zreg2 0
                      (.)

                      zreg3 0
                      (.)

                      _cons -9537.1
                      (-1.94)
                      --------------------------------------------
                      t statistics in parentheses
                      * p<0.05, ** p<0.01, *** p<0.001

                      .

                      Comment


                      • #12
                        Sorry, I should have mentioned that the code uses erepost from SSC, written by Ben Jann. First

                        Code:
                        ssc install erepost
                        Then run the code.

                        Comment

                        Working...
                        X