Announcement

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

  • Latex output for summary statistics and regression results together

    Hello! I am want to show the results of both the mean values (with sd) and difference (with se) to be outputted in the same latex table. In the below code they are separate and the colums and rows are also switched. Anyhelp on how they can be shown alongside would be very useful. Please note I cannot use ttest since I have to weight the regressions.

    Code:
    sysuse auto.dta, clear
                
                *code to create multiple dummies as an example
                set seed 12345
                generate rannum = uniform()
                sort rannum
                gen grp1 = 1 in 1/25
                    replace grp1 = 0 if grp1 != 1
                gen grp2 = 1 in 26/50
                    replace grp2 = 0 if grp2 != 1
                gen grp3 = 1 in 51/74
                    replace grp2 = 0 if grp2 != 1
                
                eststo est1: estpost sum price mpg rep78 [aweight= weight] if grp1 == 1
                eststo est2: estpost sum price mpg rep78 [aweight= weight] if grp2 == 1
                eststo est3: estpost sum price mpg rep78 [aweight= weight] if grp3 == 1
                
                eststo est4: reg price grp1 grp2 [aweight= weight], robust
                eststo est5: reg mpg grp1 grp2 [aweight= weight], robust
                eststo est6: reg rep78 grp1 grp2 [aweight= weight], robust
                
                esttab, main(mean) aux(sd) label nodepvar nostar nonote
                
                esttab, main(b) aux(se) label nodepvar nostar nonote

  • #2
    Hello all, should I provide more details for the query to be clear? I have mostly been thinking that regression results would have to be manually saved in the ttest format.

    Comment


    • #3
      estout is from SSC (FAQ Advice #12). Thanks for the data example. Consider using the mean command which is an estimation command instead of summarize. mean accepts weights as well.


      Code:
      sysuse auto.dta, clear
                  
                  *code to create multiple dummies as an example
                  set seed 12345
                  generate rannum = uniform()
                  sort rannum
                  gen grp1 = 1 in 1/25
                      replace grp1 = 0 if grp1 != 1
                  gen grp2 = 1 in 26/50
                      replace grp2 = 0 if grp2 != 1
                  gen grp3 = 1 in 51/74
                      replace grp2 = 0 if grp2 != 1
                  
                  eststo est1: mean price mpg rep78 [aweight= weight] if grp1 == 1
                  eststo est2: mean price mpg rep78 [aweight= weight] if grp2 == 1
                  eststo est3: mean price mpg rep78 [aweight= weight] if grp3 == 1
                  
                  eststo est4: reg price grp1 grp2 [aweight= weight], robust
                  eststo est5: reg mpg grp1 grp2 [aweight= weight], robust
                  eststo est6: reg rep78 grp1 grp2 [aweight= weight], robust
                  
                  esttab, main(mean) aux(sd) label nodepvar nostar nonote
                  
                  esttab, main(b) aux(se) label nodepvar nostar nonote
      Res.:

      Code:
      .             esttab, main(b) aux(se) label nodepvar nostar nonote
      
      --------------------------------------------------------------------------------------------------
                                    (1)          (2)          (3)          (4)          (5)          (6)
                                   est1         est2         est3         est4         est5         est6
      --------------------------------------------------------------------------------------------------
      Price                      6439.3       6901.6       6322.1                                       
                                (730.8)      (765.5)      (494.6)                                       
      
      Mileage (mpg)               20.12        21.38        18.71                                       
                                (0.969)      (1.418)      (0.894)                                       
      
      Repair Record 1978          3.034        3.522        3.337                                       
                                (0.177)      (0.164)      (0.240)                                       
      
      grp1                                                               449.4        1.388       -0.303
                                                                       (940.0)      (1.264)      (0.294)
      
      grp2                                                               556.5        2.440        0.185
                                                                       (992.3)      (1.565)      (0.286)
      
      Constant                                                          6231.9        18.83        3.337
                                                                       (528.7)      (0.840)      (0.240)
      --------------------------------------------------------------------------------------------------
      Observations                   22           24           23           74           74           69
      --------------------------------------------------------------------------------------------------
      
      .

      Comment


      • #4
        Thank you very much for your time! I wanted to show the table like below (the way ttests output them):

        Note: I have edited the below tab;e manually to represent what I wanted to achieve

        Code:
            
         .             esttab, main(b) aux(se) label nodepvar nostar nonote
        
          --------------------------------------------------------------------------------------------------                              
                                          (1)          (2)          (3)          (4)          (5)            
                                    est1         est2         est3         (1)-(3)      (2)-(3)        
         --------------------------------------------------------------------------------------------------
        Price                      6439.3       6901.6       6322.1         449.4        556.5            
                                    (730.8)      (765.5)      (494.6)        (940.0)      (992.3)                      
        Mileage (mpg)             20.12        21.38        18.71         1.388       2.440          
                               (0.969)      (1.418)      (0.894)        (1.264)     (1.565)                        
        Repair Record 197         3.034        3.522        3.337        -0.303       0.185                      
                                 (0.177)      (0.164)      (0.240)        (0.294)     (0.286)                      
         --------------------------------------------------------------------------------------------------
         
         
         
           
        Last edited by Tanvi Goyal; 22 Jun 2023, 01:34.

        Comment


        • #5
          deleted

          Comment


          • #6
            Search the forum for mentions of appendmodels and erepost. Something similar to https://www.statalist.org/forums/sea...ndmodels%22%7D. You will have some cutting to do, it may not be worth it if it is a one-time thing. I am travelling, so I won't have time to illustrate a solution.

            Comment


            • #7
              Thank you very much, I will try this now. I was able to build a matrix from scratch, but I didn't manage to get the significance stars in.

              Comment


              • #8
                Code:
                sysuse auto.dta, clear
                            
                            *code to create multiple dummies as an example
                            set seed 12345
                            generate rannum = uniform()
                            sort rannum
                            gen grp1 = 1 in 1/25
                                replace grp1 = 0 if grp1 != 1
                            gen grp2 = 1 in 26/50
                                replace grp2 = 0 if grp2 != 1
                            gen grp3 = 1 in 51/74
                                replace grp2 = 0 if grp2 != 1
                            
                            eststo est1: mean price mpg rep78 [aweight= weight] if grp1 == 1
                            eststo est2: mean price mpg rep78 [aweight= weight] if grp2 == 1
                            eststo est3: mean price mpg rep78 [aweight= weight] if grp3 == 1
                            eststo est4: reg price grp1 grp2 [aweight= weight], robust
                            eststo est5: reg mpg grp1 grp2 [aweight= weight], robust
                            eststo est6: reg rep78 grp1 grp2 [aweight= weight], robust
                            
                            local i 0
                            forval e=4/6{
                                local ++i
                                est restore est`e'
                                margins, dydx(grp1) post
                                *RENAME COEFFICIENT
                                mat b=e(b)
                                local colname=cond(`e'==4, "price", cond(`e'==5, "mpg", "rep78"))
                                mat colname b= `colname'
                                erepost b=b, rename
                                est sto grp1_`i'
                                est restore est`e'
                                margins, dydx(grp2) post
                                *RENAME COEFFICIENT
                                mat b=e(b)
                                local colname=cond(`e'==4, "price", cond(`e'==5, "mpg", "rep78"))
                                mat colname b= `colname'
                                erepost b=b, rename
                                est sto grp2_`i'
                            }
                           
                
                *PROGRAM TO APPEND MODELS
                capt prog drop appendmodels
                *! version 1.0.0  14aug2007  Ben Jann
                program appendmodels, eclass
                    // using first equation of model
                    version 8
                    syntax namelist
                    tempname b V tmp
                    foreach name of local namelist {
                        qui est restore `name'
                        mat `tmp' = e(b)
                        local eq1: coleq `tmp'
                        gettoken eq1 : eq1
                        mat `tmp' = `tmp'[1,"`eq1':"]
                        local cons = colnumb(`tmp',"_cons")
                        if `cons'<. & `cons'>1 {
                            mat `tmp' = `tmp'[1,1..`cons'-1]
                        }
                        mat `b' = nullmat(`b') , `tmp'
                        mat `tmp' = e(V)
                        mat `tmp' = `tmp'["`eq1':","`eq1':"]
                        if `cons'<. & `cons'>1 {
                            mat `tmp' = `tmp'[1..`cons'-1,1..`cons'-1]
                        }
                        capt confirm matrix `V'
                        if _rc {
                            mat `V' = `tmp'
                        }
                        else {
                            mat `V' = ///
                            ( `V' , J(rowsof(`V'),colsof(`tmp'),0) ) \ ///
                            ( J(rowsof(`tmp'),colsof(`V'),0) , `tmp' )
                        }
                    }
                    local names: colfullnames `b'
                    mat coln `V' = `names'
                    mat rown `V' = `names'
                    eret post `b' `V'
                    eret local cmd "whatever"
                end
                
                *APPEND THE MODELS
                eststo G1: appendmodels grp1_1 grp1_2 grp1_3
                eststo G2: appendmodels grp2_1 grp2_2 grp2_3
                
                esttab est1 est2 est3 G1 G2, mlab(none) noobs
                Res.:

                Code:
                . 
                . esttab est1 est2 est3 G1 G2, mlab(none) noobs
                
                --------------------------------------------------------------------------------------------
                                      (1)             (2)             (3)             (4)             (5)   
                --------------------------------------------------------------------------------------------
                price              6439.3***       6901.6***       6322.1***        449.4           556.5   
                                   (8.81)          (9.02)         (12.78)          (0.48)          (0.56)   
                
                mpg                 20.12***        21.38***        18.71***        1.388           2.440   
                                  (20.76)         (15.08)         (20.94)          (1.10)          (1.56)   
                
                rep78               3.034***        3.522***        3.337***       -0.303           0.185   
                                  (17.13)         (21.51)         (13.93)         (-1.03)          (0.65)   
                --------------------------------------------------------------------------------------------
                t statistics in parentheses
                * p<0.05, ** p<0.01, *** p<0.001

                Comment

                Working...
                X