Announcement

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

  • Descriptive statistics for two categories

    Hey statistic pros,

    I try to make a descriptive statistic for my logistic regression. It should be in two categories successful and failed, like at the picture. The only code I could find is
    tabstat foundedumaxba foundedumaxhi nvfourec nvpromasa netwinfem netwinfpro netwforpro, statistics (n mean sd) by(grosaledu)

    But I want to have the categories horizontal and the independent variables vertical. Do you know what code I have to use to get a table like the one at the picture?

    Thanks a lot for your support in advanced.

    Maja
    Attached Files

  • #2
    Hi Maja, this is a question that's also confusing me for a long time. I am learning by reading and practicing. Given that you don't post your data, I would use auto.dta as the toy example.
    This is a link that might be helpful:
    http://fintechprofessor.com/2018/09/...stata-ms-word/
    Code:
    sysuse auto,clear
    asdoc, row(Dependent variable:domestic or foreign, Domestic mean/frequency, Domestic SD, Foreign mean/frequency, Foreign SD) title(Summary staticis) save(myfile) replace
    asdoc, row( Model independent variables, \i, \i, \i, \i) append
    foreach var of varlist price mpg rep78 headroom trunk weight length turn {
    qui sum `var' if foreign==0
    local mf=`r(mean)'/`r(N)'
    asdoc, accum(`mf', `r(sd)')
    qui sum `var' if foreign==1
    local mf=`r(mean)'/`r(N)'
    asdoc, accum(`mf', `r(sd)')
    asdoc, row(`var', $accum)
    }
    2B or not 2B, that's a question!

    Comment


    • #3
      Hi Liu,

      it works thanks a lot you saved my day. One further question do you know how I can add the t-test (or the stars as a sign for a significant difference) for the differences of means of the two categories?

      Thanks a lot

      Maja

      Comment


      • #4
        Originally posted by Maja Ennemoser View Post
        Hi Liu,

        it works thanks a lot you saved my day. One further question do you know how I can add the t-test (or the stars as a sign for a significant difference) for the differences of means of the two categories?

        Thanks a lot

        Maja
        Yes, it's not a difficult task like this:
        Code:
        sysuse auto,clear
        asdoc, row(Dependent variable:domestic or foreign, Domestic mean/frequency, Domestic SD, Foreign mean/frequency, Foreign SD, t-test) title(Summary staticis) save(myfile) replace
        asdoc, row( Model independent variables, \i, \i, \i, \i, \i) append
        foreach var of varlist price mpg rep78 headroom trunk weight length turn{
          qui sum `var' if foreign==0
          local mf=`r(mean)'/`r(N)'
          asdoc, accum(`mf', `r(sd)')
          qui sum `var' if foreign==1
          local mf=`r(mean)'/`r(N)'
          asdoc, accum(`mf', `r(sd)')
          ttest `var', by(foreign)
          local t=round(abs(`r(t)'),0.001)
          local t=substr("`t'",1,5)
          if `r(p)'<=0.01 {
              local star "***"
          }
          else if `r(p)'<=0.05{
          local star "**"
          }
          else if `r(p)'<=0.1{
          local star "*"
          }
          else {
          local star " "
          }
         local tstar `t'`star'
        asdoc, accum(`tstar')
        asdoc, row(`var', $accum)
        }
        But I face some difficulty when deleting the code of this line:
        Code:
          local t=substr("`t'",1,5)
        That is the last line would show more decimals than expected. I don't know what's wrong yet. If anyone knows, please let me know. I would be grateful.
        Last edited by Liu Qiang; 18 May 2019, 07:45.
        2B or not 2B, that's a question!

        Comment


        • #5
          Thanks a lot Liu, you've been extremely helpful.

          Comment


          • #6
            Liu Qiang You have shown some dexterity with option row of asdoc. You have commented that the t macro show more decimal places than expected. Actually, you can format macros for decimal points using the extended macro function. So
            Code:
            sysuse auto, clear
            ttest price = 0
            
            . loc t = `r(t)'
            
            . dis `t'
            17.981223
            
            
            . loc t : di %9.3f = `r(t)'
            
            . dis `t'
            17.981
            
            . loc t : di %9.2f = `r(t)'
            
            . dis `t'
            17.98

            Regards
            --------------------------------------------------
            Attaullah Shah, PhD.
            Associate Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
            www.FinTechProfessor.com
            If you use MS Word, do check my asdoc program that easily sends Stata output to MS Word

            Comment


            • #7
              Originally posted by Attaullah Shah View Post
              Liu Qiang You have shown some dexterity with option row of asdoc. You have commented that the t macro show more decimal places than expected. Actually, you can format macros for decimal points using the extended macro function. So
              Code:
              sysuse auto, clear
              ttest price = 0
              
              . loc t = `r(t)'
              
              . dis `t'
              17.981223
              
              
              . loc t : di %9.3f = `r(t)'
              
              . dis `t'
              17.981
              
              . loc t : di %9.2f = `r(t)'
              
              . dis `t'
              17.98
              Many thanks, Professor Attaullah Shah I am still very unskilled in using Stata. By learning and practicing, I wish the huge gap between me and many outstanding professors here could be narrowed in the future.

              The revised code:
              Code:
              sysuse auto,clear
              asdoc, row(Dependent variable:domestic or foreign, Domestic mean/frequency, Domestic SD, Foreign mean/frequency, Foreign SD, t-test) title(Summary staticis) save(myfile) replace
              asdoc, row( Model independent variables, \i, \i, \i, \i, \i) append
              foreach var of varlist price mpg rep78 headroom trunk weight length turn{
                qui sum `var' if foreign==0
                local mf=`r(mean)'/`r(N)'
                asdoc, accum(`mf', `r(sd)')
                qui sum `var' if foreign==1
                local mf=`r(mean)'/`r(N)'
                asdoc, accum(`mf', `r(sd)')
                ttest `var', by(foreign)
                local t : di %9.3f = abs(`r(t)')
                if `r(p)'<=0.01 {
                    local star "***"
                }
                else if `r(p)'<=0.05{
                local star "**"
                }
                else if `r(p)'<=0.1{
                local star "*"
                }
                else {
                local star " "
                }
               local tstar `t'`star'
              asdoc, accum(`tstar')
              asdoc, row(`var', $accum)
              }
              Last edited by Liu Qiang; 20 May 2019, 19:54.
              2B or not 2B, that's a question!

              Comment

              Working...
              X