Announcement

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

  • trouble organizing multiple one-way frequency tables

    I have around 21 survey questions that all have 4 types of answers 1 = Rarely, 2 = Sometimes, 3 = Always, 0 = No, 99 = NA. I would like to show percentages of 0,1,2,3,99 for each question but organized in a more condensed format than a bunch of individual frequency tables. mrtab seems to only like displaying a range or certain acceptable value not multiple types of values. What should I be doing?

  • #2
    mrtab is from SSC, superseding the original SJ publication.

    tabm is from SSC -- tab_chi package.

    Minimal example:

    Code:
    clear
    set obs 100 
    set seed 2803 
    forval j = 1/7 { 
        gen q`j' = runiformint(0, 5)
        replace q`j' = 99 if q`j' == 5 
    }
    
    tabm q* 
    
              |                              values
      variable |         0          1          2          3          4         99 |     Total
    -----------+------------------------------------------------------------------+----------
            q1 |        15         20         17         15         14         19 |       100 
            q2 |        15         15         12         17         19         22 |       100 
            q3 |        15         12         14         14         23         22 |       100 
            q4 |        19         18         16         14         13         20 |       100 
            q5 |        19         19         12         13         21         16 |       100 
            q6 |        13         17         17         13         16         24 |       100 
            q7 |        14         13         22         16         18         17 |       100 
    -----------+------------------------------------------------------------------+----------
         Total |       110        114        110        102        124        140 |       700 
    
    .

    Comment


    • #3
      tabdisp after calculating the percentages is another option.

      Code:
      clear
      set obs 210
      set seed 06152022
      gen response=runiformint(0,10)
      replace response=99 if response>3
      lab def choices  1 "Rarely" 2 "Sometimes" 3 "Always" 0 "No" 99 "NA"
      lab values response choices 
      egen individual=seq(), block(10)
      bys ind: gen question=_n
      
      *START HERE
      bys question response: gen percent=_N
      bys question: replace percent=(percent/_N)*100
      tabdisp response question, cell(percent) format(%2.1f)
      Res.:

      Code:
      . tabdisp response question, cell(percent) format(%2.1f)
      
      ----------------------------------------------------------------------
                |                          question                         
       response |    1     2     3     4     5     6     7     8     9    10
      ----------+-----------------------------------------------------------
             No |  4.8        19.0   9.5  19.0   9.5  19.0  19.0   9.5  23.8
         Rarely |  9.5   9.5   9.5  19.0  14.3   9.5   9.5   4.8            
      Sometimes |  4.8   9.5   4.8   4.8   4.8   9.5   4.8  19.0  14.3  23.8
         Always |       19.0   9.5  23.8   4.8   9.5   9.5   9.5   9.5  14.3
             NA | 81.0  61.9  57.1  42.9  57.1  61.9  57.1  47.6  66.7  38.1
      ----------------------------------------------------------------------

      Comment


      • #4
        thankyou!

        Comment

        Working...
        X