Announcement

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

  • How to produce a concise table of variable patterns?


    I am looking for a concise way of producing an indexed frequency table.
    In particular, I have observations on three variables:

    ID var1 var2 var3
    1 1 2 1
    2 2 3 1
    3 5 4 5
    4 6 6 6
    ...
    And I would like to produce a table showing only different patterns and
    their observed frequencies, ie.

    var1 var2 var3 frequency
    First pattern 1 1 1 54
    Second pattern 1 1 2 43
    -------------------------------

  • #2
    How about the following: create a new 'pattern' variable which is a string variable derived by concatenating the values held in var1, var2, var3? Then tabulate the new variable. (It's easy if the 3 vars each have a single digit as value; a little bit trickier, not much, if they can each possibly have more than one digit.) You could also convert the string variable created to numeric using encode and preserve useful labels

    PS welcome to Statalist! Following Forum etiquette (see FAQ), please register to use your real name (firstname lastname). It's easy -- hit the Contact Us link at bottom right of screen. Thank you.

    Comment


    • #3
      Nick Cox (of course) created the groups command; it does what you are asking for. Try this
      Code:
      ssc install groups
      groups var1-var3

      Comment


      • #4
        In addition, there is the native Stata command -contract-.

        Comment

        Working...
        X