Suppose the following hypothetical dataset
Each Variable1 has one or more values in Variable2 assigned to it. Given the current sorting, I would like to create a variable that indicates if those entries of Variable2 that occur more than once are all grouped below each other.
For example, focusing on Variable1 = 1 we observe that Variable2 takes on the value 3 multiple, i.e. 4 times in total. As in the current sorting, the entries with the value 3 are not grouped below each other but are "interrupted" by the values 5 and 7, the new variable should take on the value 1 for Variable2 = 3.
For Variable1 = 2, the Value 1 occurs multiple times in Variable2. However, in the current sorting, the two entries with the value 1 are sorted below each other so that the newly generated variable should not take on the value 1.
In a nutshell: How do I indicate if the same values for Variable2 are all sorted below each other without changing the current order?
Thank you!
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long(Variable1 Variable2) 1 3 1 3 1 5 1 7 1 3 1 3 1 8 2 1 2 1 2 2 2 3 2 5 end
For example, focusing on Variable1 = 1 we observe that Variable2 takes on the value 3 multiple, i.e. 4 times in total. As in the current sorting, the entries with the value 3 are not grouped below each other but are "interrupted" by the values 5 and 7, the new variable should take on the value 1 for Variable2 = 3.
For Variable1 = 2, the Value 1 occurs multiple times in Variable2. However, in the current sorting, the two entries with the value 1 are sorted below each other so that the newly generated variable should not take on the value 1.
In a nutshell: How do I indicate if the same values for Variable2 are all sorted below each other without changing the current order?
Thank you!

Comment