Announcement

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

  • create a table with mean sd and t-test ==0

    I would like to create a table with the variables as columns and the mean, the standard deviation and the t-Statistic (different from 0) as rows.

    Do you have any suggestions how to create such a table?

    Thank you very much for your help.

    Pascal

  • #2
    I don't think there is one single command that can get you all these statistics. One possibility would be to construct a matrix manually like this.
    Code:
    sysuse auto
    local varlist price mpg weight
    local n : word count `varlist'
    matrix define A = J(`n',3,.)
    mat rownames A = `varlist'
    mat colnames A = Mean SD T
    local row = 1
    foreach var of varlist `varlist' {
        qui summarize `var'
        mat A[`row',1] = r(mean)
        mat A[`row',2] = r(sd)
        qui reg `var'
        mat A[`row',3] = _b[_cons] / _se[_cons]
        local ++row
    }
    mat list A
    
    A[3,3]
                 Mean         SD          T
     price  6165.2568  2949.4959  17.981223
       mpg  21.297297  5.7855032  31.666438
    weight  3019.4595  777.19357  33.420725

    Comment


    • #3
      Sorry, you said you want variables as columns, so that would be:
      Code:
      sysuse auto
      local varlist price mpg weight
      local n : word count `varlist'
      matrix define A = J(3,`n',.)
      mat colnames A = `varlist'
      mat rownames A = Mean SD T
      local col = 1
      foreach var of varlist `varlist' {
          qui summarize `var'
          mat A[1,`col'] = r(mean)
          mat A[2,`col'] = r(sd)
          qui reg `var'
          mat A[3,`col'] = _b[_cons] / _se[_cons]
          local ++col
      }
      mat list A

      Comment


      • #4
        Awesome! Thank you very much!

        Comment


        • #5
          You can also use asdoc for this. https://fintechprofessor.com/2018/01/31/asdoc/
          Code:
          ssc install asdoc
          
          asdoc ttest price == 0, stat(mean sd t) replace
          asdoc ttest mpg == 0, stat(mean sd t) rowappend
          asdoc ttest weight  == 0, stat(mean sd t) rowappend
          

          Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	13.3 KB
ID:	1567951
          Regards
          --------------------------------------------------
          Attaullah Shah, PhD.
          Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
          FinTechProfessor.com
          https://asdocx.com
          Check out my asdoc program, which sends outputs to MS Word.
          For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

          Comment

          Working...
          X