Announcement

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

  • Tabulation with percentage

    Hi,

    I would like to obtain a table with the cross-tabulation reported below but with the count (i.e. 40,290; 8,125 etc) reported as percentage (%) of the total figure (i.e. 474,025 ).

    Could you please help me to amend my command below to get the % figures accordingly?

    Thanks,
    Mohamud

    Code:
    tab avex strata

    Code:
               |                                         Strata
          avex |       302        303        304        305       1103       1203       1204       1303 |     Total
    -----------+----------------------------------------------------------------------------------------+----------
       1.46587 |         0          0          0          0          0          0          0          0 |    21,496 
      3.169218 |         0          0          0      9,710          0          0          0          0 |     9,710 
      3.260634 |         0          0          0          0          0          0          0          0 |    15,530 
      3.923852 |         0      8,125          0          0          0          0          0          0 |     8,125 
        4.1981 |    40,290          0          0          0          0          0          0          0 |    40,290 
      4.260475 |         0          0     73,515          0          0          0          0          0 |    73,515 
      4.421704 |         0          0          0          0          0          0          0          0 |   107,017 
      4.612422 |         0          0          0          0          0          0          0          0 |    92,694 
      5.102622 |         0          0          0          0          0          0          0          0 |    13,317 
      5.244775 |         0          0          0          0          0          0          0          0 |     9,198 
      5.443166 |         0          0          0          0          0          0          0          0 |    17,819 
      6.105625 |         0          0          0          0          0          0          0          0 |    52,383 
      7.141977 |         0          0          0          0      2,796          0          0          0 |     2,796 
        7.2193 |         0          0          0          0          0          0      3,817          0 |     3,817 
      9.532184 |         0          0          0          0          0          0          0      3,932 |     3,932 
      11.78654 |         0          0          0          0          0      2,386          0          0 |     2,386 
    -----------+----------------------------------------------------------------------------------------+----------
         Total |    40,290      8,125     73,515      9,710      2,796      2,386      3,817      3,932 |   474,025

  • #2
    as shown in the help file, you appear to want:
    Code:
     
     tab avex strata, cell nofreq
    note that my addition of the "nofreq" is a guess; if you want both frequencies and cell percentages, eliminate the "nofreq" part; note that tab also offers "row" and "column" percentages thru the "row" and "column" options

    Comment


    • #3
      Thanks Rich.

      Comment


      • #4
        Is there any (official or user-written) command to report percentages of cells while retain the row total (the last column)?

        Comment


        • #5
          Code:
          . sysuse auto, clear
          (1978 automobile data)
          
          . tab rep78 foreign, row cell
          
          +-----------------+
          | Key             |
          |-----------------|
          |    frequency    |
          | row percentage  |
          | cell percentage |
          +-----------------+
          
              Repair |
              record |      Car origin
                1978 |  Domestic    Foreign |     Total
          -----------+----------------------+----------
                   1 |         2          0 |         2 
                     |    100.00       0.00 |    100.00 
                     |      2.90       0.00 |      2.90 
          -----------+----------------------+----------
                   2 |         8          0 |         8 
                     |    100.00       0.00 |    100.00 
                     |     11.59       0.00 |     11.59 
          -----------+----------------------+----------
                   3 |        27          3 |        30 
                     |     90.00      10.00 |    100.00 
                     |     39.13       4.35 |     43.48 
          -----------+----------------------+----------
                   4 |         9          9 |        18 
                     |     50.00      50.00 |    100.00 
                     |     13.04      13.04 |     26.09 
          -----------+----------------------+----------
                   5 |         2          9 |        11 
                     |     18.18      81.82 |    100.00 
                     |      2.90      13.04 |     15.94 
          -----------+----------------------+----------
               Total |        48         21 |        69 
                     |     69.57      30.43 |    100.00 
                     |     69.57      30.43 |    100.00 
          
          .

          Comment


          • #6
            Thank you Nick Cox. Yes, I know -tabulate, cell-, but what I want to get is a table like this:
            Code:
                Repair |
                Record |       Car type
                  1978 |  Domestic    Foreign |     Total (freq)
            -----------+----------------------+----------
                     1 |    100.00       0.00 |    2 
                     2 |    100.00       0.00 |    8
                     3 |     90.00      10.00 |    30 
                     4 |     50.00      50.00 |    18 
                     5 |     18.18      81.82 |    11 
            -----------+----------------------+----------
                 Total |     69.57      30.43 |    100.00

            Comment


            • #7
              Maybe it seems ugly, weird, irregular, abnormal, anyway, I need this fashion of table (sometimes).

              Comment


              • #8
                you can get that with this:
                Code:
                ta rep78 for, row nofreq

                Comment


                • #9
                  Dear Rich Goldstein that's not what I want.

                  Comment


                  • #10
                    it is exactly the same as what you say you want, and show in #6 above:
                    Code:
                    . ta rep78 for, row nofreq
                    
                        Repair |
                        record |      Car origin
                          1978 |  Domestic    Foreign |     Total
                    -----------+----------------------+----------
                             1 |    100.00       0.00 |    100.00 
                             2 |    100.00       0.00 |    100.00 
                             3 |     90.00      10.00 |    100.00 
                             4 |     50.00      50.00 |    100.00 
                             5 |     18.18      81.82 |    100.00 
                    -----------+----------------------+----------
                         Total |     69.57      30.43 |    100.00
                    since this is exactly what you show, and say you want, your comment in #9 is more than a bit confusing

                    Comment


                    • #11
                      What I posted in #6 is:
                      Code:
                          Repair |
                          Record |       Car type
                            1978 |  Domestic    Foreign |     Total (freq)
                      -----------+----------------------+----------
                               1 |    100.00       0.00 |    2 
                               2 |    100.00       0.00 |    8
                               3 |     90.00      10.00 |    30 
                               4 |     50.00      50.00 |    18 
                               5 |     18.18      81.82 |    11 
                      -----------+----------------------+----------
                           Total |     69.57      30.43 |    100.00
                      So what I WANT is a Frankenstein: its cells are row percentages (tabulate, row), and its marginal column is total count (tabulate, freq).

                      Comment


                      • #12
                        apologies for misreading #6

                        Comment


                        • #13
                          Probably -tabout- Ian Watson could do this work with some work of columns deleting.
                          https://www.statalist.org/forums/for...eq-and-percent

                          Comment


                          • #14
                            Try this:


                            Code:
                            sysuse auto, clear
                            quietly {
                              table (rep78) (foreign), statistic(percent, across(foreign)) statistic(frequency) nformat(%5.2f percent) nformat(%5.0f frequency)
                              collect layout (rep78) (foreign[0 1]#result[percent] foreign[.m]#result[frequency])
                              collect label levels foreign .m "Total (freq)", modify
                              collect style header result, title(hide) level(hide)
                            }
                            collect preview
                            Click image for larger version

Name:	StataTable.png
Views:	1
Size:	13.7 KB
ID:	1786983

                            Comment


                            • #15
                              Thank you very much Modesto Escobar. I don't like -collect-, I think collect and putexcel alike commands lack the stylistic grace of Stata code.

                              Comment

                              Working...
                              X