I have a dataset that looks something like this:
ID var1 flag_same
1 3 0
1 3 0
1 2 0
1 2 0
1 2 0
2 1 0
2 2 0
3 2 1
3 2 1
I'd like to create a variable that indicates when the values of var1 for a given value of ID are completely the same - i.e., generate the variable flag_same. Any ideas about how to do this would be so helpful. It would be great if this could work for both numeric and string variables.
Best,
Erika
ID var1 flag_same
1 3 0
1 3 0
1 2 0
1 2 0
1 2 0
2 1 0
2 2 0
3 2 1
3 2 1
I'd like to create a variable that indicates when the values of var1 for a given value of ID are completely the same - i.e., generate the variable flag_same. Any ideas about how to do this would be so helpful. It would be great if this could work for both numeric and string variables.
Best,
Erika
Comment