Announcement

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

  • Summary statistics for quintiles

    Hi,

    I would like to create a table in stata, which describes summary statistics for quintiles of a variable separately.
    I already created quintiles of the variable by using the command xtile.
    The table should have the following layout:

    quintile 1 quintile 2 quintile 3 quintile 4 quintile 5
    n
    mean
    age
    ...


    Thanks a lot for your help!

  • #2
    Here is one way:
    Code:
    . sysuse auto,clear
    (1978 automobile data)
    
    . xtile  quintile_price = price, nq(5)
    
    . table (var) (quintile_price), stat(count price) stat(mean price)
    
    -----------------------------------------------------------------------------------------------
                                   |                       5 quantiles of price                    
                                   |         1          2        3          4          5      Total
    -------------------------------+---------------------------------------------------------------
    Price                          |                                                               
      Number of non-missing values |        15         15       15         15         14         74
      Mean                         |  3834.067   4397.267   5052.6   6301.733   11603.14   6165.257
    -----------------------------------------------------------------------------------------------

    Comment


    • #3
      Thanks Scott! Perfect, that works out

      One more thing: I tried to export the table to a word document with asdoc and putword, but both time errors occured.

      putexcel:

      putdocx begin
      putdocx paragraph
      table (var) ...
      putdocx table Table1=etable
      → error: variable var not found r(111);

      asdoc:
      asdoc table (var) ... , save (summary)
      → error: variable var not found r(111);

      Can you help me with that?
      Thanks!


      Comment


      • #4
        You can either export the table with -collect export- or within a putdocx with -putdocx collect-

        Code:
        sysuse auto,clear
        xtile  quintile_price = price, nq(5)
        collect:  table (var) (quintile_price), stat(count price) stat(mean price)
        collect export mytable.docx, replace
        
        
        sysuse auto,clear
        xtile  quintile_price = price, nq(5)
        table (var) (quintile_price), stat(count price) stat(mean price)
        putdocx begin
        collect style putdocx, layout(autofitcontents) ///
        title("Table 1: Quintiles")
        putdocx collect
        putdocx save myreport.docx, replace

        Comment


        • #5
          Thank you, that works perfectly!

          Comment


          • #6
            Hi Scott,
            one more question: I tried to format the table to two decimals, but when I add the format option to the code, an error occurs.
            Thats how I did it:

            table (var) (quintile_price), stat(count price) stat(mean price), nformat(%12.2)

            Comment


            • #7
              do NOT add that comma prior to the "nformat()" option

              Comment

              Working...
              X