I have a somewhat odd task that I'm attempting to figure out the best way to handle. Imagine I have 5 variables, and I basically want to produce a matrix that counts the number of respondents/IDs that fall into each bucket.
The first column is the combination of var1-var4. So '0011' would mean var1=0, var2=0, var3=1, var4=1. And then these are broken out by the 'freq' variable categories.
And then all I'd want is to count the number of respondents that have each possible combination of var1-var4. So in the below table, 4 respondents had a 0 on all four variables (0000) and freq=never.
I have no clue how to even start wrapping my head around how to do this. But I think the resulting table would look something like this:
The first column is the combination of var1-var4. So '0011' would mean var1=0, var2=0, var3=1, var4=1. And then these are broken out by the 'freq' variable categories.
And then all I'd want is to count the number of respondents that have each possible combination of var1-var4. So in the below table, 4 respondents had a 0 on all four variables (0000) and freq=never.
I have no clue how to even start wrapping my head around how to do this. But I think the resulting table would look something like this:
var group | freq never | freq once | freq more than once |
0000 | 4 | 1 | 0 |
0011 | 0 | 0 | 1 |
0100 | 0 | 1 | 0 |
1000 | 0 | 1 | 1 |
1010 | 0 | 1 | 0 |
1110 | 1 | 0 | 0 |
2100 | 1 | 0 | 0 |
Code:
* Define the data with 'input' clear input id var1 var2 var3 var4 str15 freq 1 0 0 0 0 "never" 2 0 0 0 0 "never" 3 0 0 0 0 "never" 4 0 0 0 0 "once" 5 0 0 1 1 "more than once" 6 0 0 0 0 "never" 7 0 1 0 0 "once" 8 1 0 0 0 "once" 9 1 0 0 0 "never" 10 1 0 1 0 "once" 11 1 1 1 0 "never" 12 2 1 0 0 "never" end
Comment