Announcement

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

  • How to export multiple ttest results in a table of multiple columns and rows to latex?

    The table I aim to create and export to latex looks like following:




    E.g. At the Position Z, the entry is the mean of the ttest of Variable A=0, with star indicating the significance, and standard error in parenthesis, for the whole sample under Condition1.

    I tried with eststo and found out it is not very straightforward to get the table I want. Do anyone have a better idea how to do so?


    Thank you in advance!
    Last edited by Christine Lee; 02 Mar 2023, 13:06.

  • #2
    Your table is not visible. Upload pictures in .PNG format as advised in FAQ Advice #12.

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      Your table is not visible. Upload pictures in .PNG format as advised in FAQ Advice #12.
      Thank you for your notification. The picture is a PNG file but for some reason it was not displayed.
      I just made it smaller and tested it in another browser. It seems that it works this time.
      Click image for larger version

Name:	sc.png
Views:	1
Size:	8.8 KB
ID:	1704233

      Last edited by Christine Lee; 03 Mar 2023, 05:27.

      Comment


      • #4
        For means, you can use the mean command. Here is an illustration using estout from SSC assuming a single condition. You can adapt it to include additional conditions. See #8 on how you can use -mgroups()- to separate groups of models: https://www.statalist.org/forums/for...rs-with-esttab. Run the following in a do-file.

        Code:
        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 "regress"
        end
        
        sysuse auto, clear
        local i 0
        foreach var in mpg weight displacement{
            local ++i  
            eststo a`i': mean `var'
            eststo b`i': mean `var' if !foreign
            eststo c`i': mean `var' if foreign
        }
        
        eststo a: appendmodels a1 a2 a3
        eststo b: appendmodels b1 b2 b3
        eststo c: appendmodels c1 c2 c3
        
        
         
        esttab a b c, mlabels("Full sample" Domestic Foreign, lhs(Variables)) nonumbers noobs label
        Res.:

        Code:
        . esttab a b c, mlabels("Full sample" Domestic Foreign, lhs(Variables)) nonumbers noobs label
        
        --------------------------------------------------------------------
        Variables             Full sample        Domestic         Foreign  
        --------------------------------------------------------------------
        Mileage (mpg)               21.30***        19.83***        24.77***
                                  (31.67)         (30.14)         (17.58)  
        
        Weight (lbs.)              3019.5***       3317.1***       2315.9***
                                  (33.42)         (34.40)         (25.09)  
        
        Displacement .. in.)        197.3***        233.7***        111.2***
                                  (18.48)         (19.77)         (20.97)  
        --------------------------------------------------------------------
        t statistics in parentheses
        * p<0.05, ** p<0.01, *** p<0.001
        Last edited by Andrew Musau; 04 Mar 2023, 11:59.

        Comment


        • #5
          Thank you very much for your help Andrew!

          Comment

          Working...
          X