Announcement

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

  • Frequency Table for Multiple Variables with the Same Value Range

    Hello,

    Is there an easy way to produce a frequency table for multiple variables that all have the same range of values?

    For example, I have Var1-Var30 which each contain possible values 1, 2, 3, 4, and 5. What I'd like to do is get a table that has for each variable the # of times each value appears in the dataset. I know I could do this individually by variable or loop it through all the variables but was wondering if there is an easy way to get just one table of frequencies.

    Thank you.

  • #2
    Here is one way of doing it

    Code:
    clear*
    
    input id    var1    var2    var3    var4    var5    var6    var7    fw
    1    5    4    2    1    1    3    4    20
    2    1    4    4    2    4    3    5    30
    3    1    4    .    1    1    3    5    40
    4    3    4    1    2    1    3    5    50
    end
    
    expand fw
    replace id=_n
    reshape long var, i(id)j(quest)
    replace var=9 if mi(var)
    la de scale 1 "oppose" 5 "support" 9 "DK/NA"
    la val var scale
    table quest var

    Comment


    • #3
      Originally posted by Oded Mcdossi View Post
      Here is one way of doing it

      Code:
      clear*
      
      input id var1 var2 var3 var4 var5 var6 var7 fw
      1 5 4 2 1 1 3 4 20
      2 1 4 4 2 4 3 5 30
      3 1 4 . 1 1 3 5 40
      4 3 4 1 2 1 3 5 50
      end
      
      expand fw
      replace id=_n
      reshape long var, i(id)j(quest)
      replace var=9 if mi(var)
      la de scale 1 "oppose" 5 "support" 9 "DK/NA"
      la val var scale
      table quest var
      This worked great. Thank you!

      Comment


      • #4
        Code:
        ssc des tab_chi
        ssc inst tab_chi
        h tabm

        Comment

        Working...
        X