Hello Statalist, this is my first post and so I will try to follow the rules as best I can.
I have presented data below. The "Question1" variable was from a question where respondents could select multiple responses, hence the commas. I found code from a previous post here that adequately splits those commas to produce a nice table:
But then I have the 'agencytype' variable. Essentially, what I am hoping to do is to "group" or categorize the different agency types into three groups: 1-6 would be AgencyA, 7-12 would be AgencyB, and 13-17 would be AgencyC. And then I would produce tabs of Question1 by each group.
Right now, the best way I can think of doing that is:
And that would give me the output for Question1 by AgencyA. I would then repeat for AgencyB and AgencyC.
But, I feel like there must be some more efficient way of doing this, or something I am not thinking of.
My data is below. Thank you in advance for the help.
I have presented data below. The "Question1" variable was from a question where respondents could select multiple responses, hence the commas. I found code from a previous post here that adequately splits those commas to produce a nice table:
Code:
split Question1, p(,) destring tabm Question1?, transpose
Right now, the best way I can think of doing that is:
Code:
tabm Question1? if agencytype ==1 | agencytype ==2 | agencytype ==3 | agencytype ==4 | agencytype ==5 | agencytype ==6, transpose
But, I feel like there must be some more efficient way of doing this, or something I am not thinking of.
My data is below. Thank you in advance for the help.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte agencytype str13 Question1 3 "4" 3 "4" 2 "1,2,3" 7 "4" 1 "1,2,3,4" 5 "2" 3 "4" 11 "1,2,3" 4 "4" 1 "1,2,3,4" 10 "1,2,3,4,5" 1 "3,4,5,6" 7 "2" 5 "2" 3 "5" 5 "3,4" 5 "3" 1 "1" 1 "2,3,4" 2 "4" 12 "2,3,4,5,6" 5 "4" 9 "4" 5 "3" 3 "4" 1 "4,5,6" 5 "3,4" 1 "1,2,3,4,5,6" 3 "4" 3 "3,4" 17 "1,2,3,4,5,6" 5 "3" 2 "2" 1 "1,2,3,4,5,6" 5 "3" 9 "1,2,3,4,5,6" 3 "3" 17 "1,2,3" 5 "3" 2 "3" 3 "4" 11 "1,2,3" 4 "4" 1 "1,2,3,4" 1 "1" 1 "2,3,4" 2 "4" 12 "2,3,4,5,6" 5 "4" 9 "4" 11 "1,2,3,4,5,6" 3 "4" 4 "4" 4 "3" 9 "2" 9 "7" 1 "1" 17 "4" 2 "4" 4 "4,5" 5 "3" 2 "1,2,3" 2 "4" 8 "1,2,3" 17 "1,2,3" 5 "3" 3 "1,2,3,4,6" end
Comment