Announcement

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

  • How can I use tabulate to generate percentages of overall sample?

    I want to generate percentages of my total no. in group over total no. in my dataset.

    The closest I've gotten is using the following command

    Code:
    tab visit HS5_ if rescuetrt==1, row
    
      RECODE of |
        avisit2 |                               HS5_
       (AVISIT) |         0          1          2          3          4          5 |     Total
    ------------+------------------------------------------------------------------+----------
       BASELINE |        46          1        332        370         88         25 |       862
                |      5.34       0.12      38.52      42.92      10.21       2.90 |    100.00
    ------------+------------------------------------------------------------------+----------
         WEEK 4 |         0         52        423        299         72         15 |       861
                |      0.00       6.04      49.13      34.73       8.36       1.74 |    100.00
    ------------+------------------------------------------------------------------+----------
         WEEK 8 |         0         73        434        271         65         17 |       860
                |      0.00       8.49      50.47      31.51       7.56       1.98 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 12 |         2        100        424        251         67         18 |       862
                |      0.23      11.60      49.19      29.12       7.77       2.09 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 16 |         0        109        426        241         65         20 |       861
                |      0.00      12.66      49.48      27.99       7.55       2.32 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 20 |         0        127        422        235         57         21 |       862
                |      0.00      14.73      48.96      27.26       6.61       2.44 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 24 |         0        132        414        209         52         14 |       821
                |      0.00      16.08      50.43      25.46       6.33       1.71 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 28 |         0        136        422        194         43         14 |       809
                |      0.00      16.81      52.16      23.98       5.32       1.73 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 32 |         0        146        397        211         42         16 |       812
                |      0.00      17.98      48.89      25.99       5.17       1.97 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 36 |         0        151        397        201         39         14 |       802
                |      0.00      18.83      49.50      25.06       4.86       1.75 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 40 |         0        154        385        205         34         15 |       793
                |      0.00      19.42      48.55      25.85       4.29       1.89 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 44 |         0        154        413        188         44         18 |       817
                |      0.00      18.85      50.55      23.01       5.39       2.20 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 48 |         0        155        393        199         41         14 |       802
                |      0.00      19.33      49.00      24.81       5.11       1.75 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 52 |         0        167        400        192         42         15 |       816
                |      0.00      20.47      49.02      23.53       5.15       1.84 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 56 |         0        169        390        192         39         15 |       805
                |      0.00      20.99      48.45      23.85       4.84       1.86 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 60 |         0        170        396        190         39         17 |       812
                |      0.00      20.94      48.77      23.40       4.80       2.09 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 64 |         0        178        394        179         41         14 |       806
                |      0.00      22.08      48.88      22.21       5.09       1.74 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 68 |         0        167        398        189         39         17 |       810
                |      0.00      20.62      49.14      23.33       4.81       2.10 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 72 |         0        176        398        178         35         17 |       804
                |      0.00      21.89      49.50      22.14       4.35       2.11 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 76 |         0        189        387        179         35         18 |       808
                |      0.00      23.39      47.90      22.15       4.33       2.23 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 80 |         1        186        379        190         29         15 |       800
                |      0.13      23.25      47.38      23.75       3.62       1.88 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 84 |         0        189        379        181         41         15 |       805
                |      0.00      23.48      47.08      22.48       5.09       1.86 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 88 |         0        192        378        190         34         16 |       810
                |      0.00      23.70      46.67      23.46       4.20       1.98 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 92 |         0        194        383        184         32         19 |       812
                |      0.00      23.89      47.17      22.66       3.94       2.34 |    100.00
    ------------+------------------------------------------------------------------+----------
        WEEK 96 |         0        185        389        175         38         17 |       804
                |      0.00      23.01      48.38      21.77       4.73       2.11 |    100.00
    ------------+------------------------------------------------------------------+----------
       WEEK 100 |         0        197        404        201         38         22 |       862
                |      0.00      22.85      46.87      23.32       4.41       2.55 |    100.00
    ------------+------------------------------------------------------------------+----------
          Total |        49      3,849     10,357      5,494      1,191        438 |    21,378
                |      0.23      18.00      48.45      25.70       5.57       2.05 |    100.00
    As you can see my total numbers decline somewhat through the weeks however percentage is 100% as they calculate the row percentages. How can I include % of overall number in my dataset in the table?

  • #2
    Would the option - column - or the command apply to your needs? If not, maybe the command - egen - would do the trick, and you could present the result in a table afterwards
    Last edited by Marcos Almeida; 03 Feb 2017, 08:48.
    Best regards,

    Marcos

    Comment


    • #3
      I think what Ms. Hussein wants is the -cell- option to the -tab- command. She can use it in addition to, or instead of, the -row- option.

      Comment


      • #4
        Originally posted by Clyde Schechter View Post
        I think what Ms. Hussein wants is the -cell- option to the -tab- command. She can use it in addition to, or instead of, the -row- option.
        Hi, yes cell is the option I'd like. I realised my issue - my data is in 'long' format which makes total obs 10x the number of actual participants, which is why my % are off. Is there anyway I can control for this without having to reshape my data to wide? Thanks

        Comment


        • #5
          Code:
          help egen
          for the tag() function perhaps. (I don't see any precise explanation here of your data structure, or of where the 10x comes from, so I am guessing.)

          Comment


          • #6
            Originally posted by Nick Cox View Post
            Code:
            help egen
            for the tag() function perhaps. (I don't see any precise explanation here of your data structure, or of where the 10x comes from, so I am guessing.)
            thanks, egen tag is helpful. How could I generate a table with percentages using tag, I could only find options to generate frequency tables. Thanks!

            Comment

            Working...
            X