I am having trouble figuring out how to generate a variable with the count of the number of repeated values in a row (across a set of ordered variables) in a dataset that looks like this below. Not the total number of Xs across a set of variables, but the total number that appear next to each other in order. For example, I want to know how many ones are repeated in a row, how many 2s repeated, 3s, etc.
Example: For the first record_id of 2, I want to create a variable that has a value of 6 representing the number of 1s that are repeated in a row, a second variable with the value of 2 for the number of 2s in a row, etc.
Appreciate any ideas anyone might have!
Example: For the first record_id of 2, I want to create a variable that has a value of 6 representing the number of 1s that are repeated in a row, a second variable with the value of 2 for the number of 2s in a row, etc.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int record_id byte(fint1 fint2 fint3 fint4 fint5 fint6 fint7 fint8 fint9 fint10 fint11) 2 3 1 1 1 1 1 1 2 2 1 2 3 5 4 4 5 4 4 5 4 4 4 4 6 4 1 2 2 1 2 3 2 2 5 4 7 3 1 1 1 1 1 2 1 1 1 1 11 4 2 2 2 2 2 2 3 3 2 2 15 1 1 1 2 1 2 1 1 1 1 3 19 2 1 1 2 1 1 2 2 1 1 1 20 3 1 1 1 1 1 1 1 1 1 1 21 4 1 1 1 2 2 1 2 2 2 1 26 1 1 3 3 3 3 4 4 3 3 3 27 3 1 1 1 1 1 1 1 2 2 3 28 3 2 3 2 2 2 2 2 2 3 4 31 3 2 1 1 1 1 1 1 1 1 1 34 1 1 1 1 1 1 1 1 1 1 1 43 2 1 1 1 1 1 2 2 2 1 1 end
Comment