I have data from a survey. I want to create a grouping variable but struggling to write the code. Using the following definition, I want to create a categorical variable (high vs. low group):
High group: IDs with a score of 4 or 5 on at least four of the five questions (belong1 through belong5) and without a score of 1 or 3 on any question.
Low group: Everyone else not included in the high group.
The data is shown below.
High group: IDs with a score of 4 or 5 on at least four of the five questions (belong1 through belong5) and without a score of 1 or 3 on any question.
Low group: Everyone else not included in the high group.
The data is shown below.
Code:
clear input byte(id belong1 belong2 belong3 belong4 belong5) 1 4 1 2 1 5 2 5 4 3 5 1 3 1 5 2 4 3 4 2 2 2 3 2 5 3 2 3 4 2 6 4 5 4 2 3 7 3 5 2 2 5 8 1 4 2 2 4 9 2 3 1 2 3 10 5 2 2 2 2 11 3 2 5 3 2 12 4 1 4 3 1 13 5 3 3 4 5 14 2 3 2 4 3 15 1 2 1 4 2 16 5 2 4 4 2 17 2 2 5 5 2 18 4 2 5 5 2 19 5 5 4 1 5 20 5 5 2 1 5 21 3 2 1 2 2 22 3 3 1 5 3 23 3 3 3 1 3 24 5 5 2 4 4 25 2 4 4 2 4 26 1 3 5 4 5 27 4 3 1 2 3 28 1 2 2 3 2 29 5 4 3 2 1 30 5 5 5 3 1 31 5 3 4 2 3 32 3 4 5 3 4 33 3 5 4 5 5 34 4 3 4 5 3 35 4 4 3 4 4 end
Comment