Announcement

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

  • tabm and percentages

    Hello,

    This is a question that has come up after my last couple posts on the Statalist and is now a question I have more generally because I feel that it may be beneficial in the future as well in addition to my current dilemna.

    The general question is; is there a possibility, when using -tabm-, to force Stata to generate percentages in the output table?

    For the sake of an example, I have this code to generate results of question responses where it could be a "1" or "2" response:

    Code:
    preserve
    keep q10a q10b q10c q10d q10e q10f
    findname, all(inlist(@, 1, 2, .))
    tabm `r(varlist)'
    restore
    And it produces this table:
    variable 1 2 Total
    q10a 101 54 155
    q10b 111 20 131
    q10c 90 30 120
    q10d 150 6 156
    q10e 125 26 151
    q10f 105 15 120
    Is there a way, using -tabm-, to get that table to have the percentage of "1" responses out of the total? So for q10a, the new percentage column would say 65.16%...I do not see any guidance on percentages in the -help tabm- file. And is there a general consensus way to do this with -tabm- generally? Thank you.
    Last edited by Todd Motiwalla; 31 Jul 2019, 10:51.

  • #2
    I don't think a general consensus, even if it exists, would move anything here. What matters is the code and the help. And "force" a command to do anything? That's too violent for my taste.

    The help for tabm tells you that you can specify tabulate_options where

    tabulate_options are options allowed with tabulate for two-way or one-way tables.

    You don't give a data example we can use, but those options include row and column. in your case.

    Please note the permanent request in the FAQ Advice to explain where community-contributed commands you refer to come from. In this case, findname is from the Stata Journal and tabm is from tab_chi (SSC).



    Comment


    • #3
      Nick Cox Apologies, 'force' may not have been correct word choice! And will remember to explain where the commands come from in the future.


      Here is some data, and if I use the command in my original post (which came from guidance of yours on an earlier post) then I can produce a table like the one in the original post.

      However this does not show percentages, which I could hand calculate I suppose but would be preferable to figure out a way for Stata to put in table.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input byte(Q35A Q35B Q35C Q35D Q35E)
      4 4 4 4 4
      4 4 3 3 4
      1 1 1 1 3
      1 1 2 1 4
      3 4 3 3 3
      1 1 1 2 2
      1 4 1 2 1
      4 2 3 3 2
      2 3 4 2 4
      3 2 1 2 2
      3 4 2 3 2
      2 1 2 3 4
      1 1 1 1 1
      1 1 1 1 1
      . . . . .
      3 2 2 1 2
      3 3 4 3 3
      1 1 5 2 4
      2 3 2 2 2
      3 2 4 2 1
      4 3 3 4 3
      1 1 1 3 3
      1 1 1 1 1
      3 4 1 1 1
      2 2 3 4 4
      5 4 3 2 3
      2 2 5 2 5
      1 1 2 2 1
      3 3 2 4 3
      1 1 1 1 2
      1 1 1 1 4
      1 2 2 2 2
      1 2 2 2 2
      5 1 1 1 2
      2 4 2 4 3
      2 3 1 2 3
      4 3 1 2 3
      1 1 1 1 2
      5 1 1 1 1
      2 3 2 4 2
      1 3 1 2 3
      1 1 4 3 4
      1 1 1 2 4
      4 3 4 3 4
      2 1 3 2 1
      3 4 2 3 3
      1 1 1 1 4
      1 1 1 1 3
      1 1 3 3 2
      2 1 3 3 2
      3 2 4 3 2
      4 4 3 4 2
      3 2 4 3 1
      1 1 1 1 1
      2 2 1 1 1
      1 1 1 1 4
      2 3 4 3 2
      1 3 2 1 4
      3 4 1 2 3
      1 1 5 4 4
      4 3 2 4 4
      2 3 4 3 3
      2 3 4 3 4
      3 1 2 1 2
      2 2 2 4 5
      1 1 1 2 2
      3 2 2 4 3
      3 4 4 3 4
      2 2 3 3 2
      4 4 3 4 4
      1 3 1 2 3
      4 3 4 4 4
      4 3 4 4 4
      1 1 3 4 3
      3 2 2 1 2
      1 1 1 2 .
      1 1 1 2 1
      1 1 2 3 2
      3 1 4 1 1
      2 1 1 2 2
      3 2 3 4 3
      1 1 1 1 2
      4 3 2 3 4
      1 1 1 2 4
      3 2 3 2 1
      3 2 4 3 2
      3 2 4 3 2
      3 2 3 4 3
      2 1 3 2 4
      3 2 2 4 2
      4 4 4 4 4
      2 2 2 2 4
      3 4 3 4 5
      1 1 2 1 2
      1 2 1 2 2
      1 3 1 1 4
      4 3 3 4 3
      3 4 2 3 2
      5 4 2 3 4
      2 2 2 2 2
      end
      Last edited by Todd Motiwalla; 31 Jul 2019, 12:55. Reason: Edited because of an issue with my copy/paste for dataex

      Comment

      Working...
      X