Announcement

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

  • Descriptive statistic tables - Collect command

    I have spend a day now trying to figure out how to build descriptive statistics tables as shown on the attached file. I would like to show variables in rows and selected statistic for each in the column. Right now I am trying to get familiar with -collect but honestly I am quite lost as the -collect command isn't very intuitive to me..
    My question would be whether it is possible to put several panels within a table (as shown on the picture) using Stata commands and which commands you would recommend to built such tables in general. I know there are several user written commands out there but before wasting time on the wrong commands I would really appreciate any help.

    I tried
    Code:
     webuse auto
    collect: sum trunk weight length
    . collect layout (trunk weight length) (Mean)
    (dimension Mean not found)
    
    Collection: default
          Rows: trunk weight length
       Columns: Mean
    
    Your layout specification does not identify any items.
    Obviously, this is wrong. I tried using the Tables Builder after -collect: sum trunk weight length but I have no idea how to get the variables as rows:
    Click image for larger version

Name:	Table builder example.jpg
Views:	1
Size:	107.0 KB
ID:	1662009

    This Youtube Video appears to be helpful to some extend. Unfortunately, unlike in the video, I would like to show mean, SD etc. rather than variables in the columns.

    Any help is much appreciated



    Desired layout:
    Click image for larger version

Name:	Table example.jpg
Views:	1
Size:	117.1 KB
ID:	1662008

  • #2
    Hi Marc Pelow, have you solved this question?

    Comment


    • #3
      Emanuel, something like this might be a decent starting point?

      Code:
      clear all
      sysuse auto
      
      local vars price mpg headroom weight
      
      #delimit ;
          table , 
              statistic(mean `vars') 
              statistic(median `vars') 
              statistic(sd `vars')
              statistic(min `vars')
              statistic(max `vars')
              ;
      #delimit cr
      
      collect layout (var) (result)

      Comment


      • #4
        Hi Hemanshu Kumar, Thanks for your suggestion. It works pretty well to address Marc's question.

        I continued this thread hoping to tackle a similar challenge I have at hand. I'm trying to build a long table with many binary response variables (Yes=1; No=0), for which I would like to inform only the statistics for "Yes". I want something similar to what I get when adding -foreign- to the local macro you wrote:

        Code:
        . collect layout (var) (result)
        
        Collection: Table
              Rows: var
           Columns: result
           Table 1: 5 x 5
        
        ----------------------------------------------------------------------------------------
                       |      Mean   Median   Standard deviation   Minimum value   Maximum value
        ---------------+------------------------------------------------------------------------
        Price          |  6165.257   5006.5             2949.496            3291           15906
        Mileage (mpg)  |   21.2973       20             5.785503              12              41
        Headroom (in.) |  2.993243        3             .8459948             1.5               5
        Weight (lbs.)  |  3019.459     3190             777.1936            1760            4840
        Car origin     |  .2972973        0             .4601885               0               1
        ----------------------------------------------------------------------------------------
        But I don't get similar outcomes using the database with binary response variables I mention. I can't access to Stata right now, but will try continue the explanation tonight. Thanks for your help.
        Last edited by Emanuel Agu; 16 Aug 2022, 09:26.

        Comment


        • #5
          Sure, Emanuel. I am also just beginning to figure out the -collect- system. I'm happy to try and attack future challenges you face, so we can both learn!

          If all your variables are binary response, you might want to consider what you want to show on the table. For instance, the min and max values are not interesting.

          Comment


          • #6
            Emanuel Agu I haven't really found a ready-to-publish solution to my problem using Stata. I ended up using the following command to get close to what I wanted (variables in the rows and selected statistics in the columns):

            Code:
            asdoc tabstat $Variables, columns(stat) stats(mean sd p10 p50 p90 count) font(Times new roman) fs(12) append label
            From here, I did the desired adjustments manually in Word. Took me about 5 minutes or so.

            Comment


            • #7
              Thanks, Marc Pelow. I just read your reply. I apologize for my late reply.

              Comment


              • #8
                Hello,

                I am trying to produce summary statistics to then transfer to latex, however STATA reports an error with nomtitle. May anyone help?

                tabstat pbevreg eincentive incentive hhy nprice vwprice chinf100, c(stat) stat(sum mean sd min max n)

                est clear // clear the stored estimates
                estpost tabstat pbevreg eincentive incentive hhy nprice vwprice chinf100, c(stat) stat(sum mean sd min max n)

                ereturn list

                esttab, cells("sum mean sd min max count") nonumber
                nomtitle nonote noobs label

                Comment


                • #9
                  it appears that "nomtitle" is an option to the -esttab- command so you need to either have it on the same line (if using interactively) or, if in a do file, use something (like "///") to tell Stata that the next line is part of the current line; you can also change the delimiter; see
                  Code:
                  h comment
                  h delimit

                  Comment


                  • #10
                    Now that I do this, STATA tells me that it doesn't recognise / as a command. Do you know why?

                    Comment


                    • #11
                      you need to show EXACTLY what you typed- please read the FAQ and follow its advice

                      Comment

                      Working...
                      X