Hi Everyone,
I am working with the following experiment data, where I have provided a sample below. The variables are
participantcode:
Unique for each person in a treatment,
Treatment :
Each person has only one treatment,
Round:
Number of rounds for each person where max = 8 and each person has an observation for each round,
P2_group_id:
In each round, three players make a group and this is the group ID. In each round, players are randomly rematched again and new groups are formed,
P2_player_id:
In each group, this variable represents the randomly assigned id within the group. Hence, a person may have different P2_player_id in each round because it is round specific id.
T1_success:
Number of correct answers. These scores are given and does not change across rounds. However, the data on that is entered only in Round 1 for each unique player (Is it better to auto fill it in the remaining rounds for a player using unique id of the player?).
sessioncode:
Unique for each sessions. Two different sessions may have the same treatment but with different people.
Problem:
1) I want to create a variable that ranks the players in each group for each round based on their number of correct answers. Specifically, in the case of tie when all three scored the same, I want the rank to be the same as P2_player_id. If the first rank is clear but tie is for the second and third place then second rank will be given to the player with lower P2_player_id among the two. Similarly, if the tie is for the first and second position, the first rank is given to person with lower P2_player_id among the two.
While doing so, I want to make sure that I do that for all groups. Groups do not have unique id, they have the numbers. Hence, I need to use the "by" condition. I think of it as starting by sorting data first by session_code, then Round, and then P2_group_id
2) Following from above, I also want to create three dummy variables for each group that reports whether there was any kind of tie in scores (i.e. tie for all three ranks, tie for first and second position, tie for second and third position).
I would highly appreciate your help or useful suggestions to create these variables.
I am working with the following experiment data, where I have provided a sample below. The variables are
participantcode:
Unique for each person in a treatment,
Treatment :
Each person has only one treatment,
Round:
Number of rounds for each person where max = 8 and each person has an observation for each round,
P2_group_id:
In each round, three players make a group and this is the group ID. In each round, players are randomly rematched again and new groups are formed,
P2_player_id:
In each group, this variable represents the randomly assigned id within the group. Hence, a person may have different P2_player_id in each round because it is round specific id.
T1_success:
Number of correct answers. These scores are given and does not change across rounds. However, the data on that is entered only in Round 1 for each unique player (Is it better to auto fill it in the remaining rounds for a player using unique id of the player?).
sessioncode:
Unique for each sessions. Two different sessions may have the same treatment but with different people.
Problem:
1) I want to create a variable that ranks the players in each group for each round based on their number of correct answers. Specifically, in the case of tie when all three scored the same, I want the rank to be the same as P2_player_id. If the first rank is clear but tie is for the second and third place then second rank will be given to the player with lower P2_player_id among the two. Similarly, if the tie is for the first and second position, the first rank is given to person with lower P2_player_id among the two.
While doing so, I want to make sure that I do that for all groups. Groups do not have unique id, they have the numbers. Hence, I need to use the "by" condition. I think of it as starting by sorting data first by session_code, then Round, and then P2_group_id
2) Following from above, I also want to create three dummy variables for each group that reports whether there was any kind of tie in scores (i.e. tie for all three ranks, tie for first and second position, tie for second and third position).
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str8 participantcode byte(P2_group_id P2_player_id Round T1_success Treatment) str8 sessioncode "xp5dr3wz" 3 2 1 33 3 "30z0wyr2" "zwd8oerg" 4 1 1 45 3 "30z0wyr2" "kdrn04zt" 2 3 1 31 3 "30z0wyr2" "kz0pah98" 3 3 1 43 3 "30z0wyr2" "zvg9zop4" 1 2 1 35 3 "30z0wyr2" "uabc3w2i" 1 3 1 31 3 "30z0wyr2" "hidkbh57" 4 3 1 36 3 "30z0wyr2" "4s8fggab" 3 1 1 39 3 "30z0wyr2" "mgb7nktz" 4 2 1 35 3 "30z0wyr2" "261sg8w7" 2 2 1 36 3 "30z0wyr2" "mo19or6c" 1 1 1 24 3 "30z0wyr2" "7unz5s7y" 2 1 1 39 3 "30z0wyr2" "xp5dr3wz" 2 3 2 . 3 "30z0wyr2" "zwd8oerg" 1 2 2 . 3 "30z0wyr2" "kdrn04zt" 3 1 2 . 3 "30z0wyr2" "kz0pah98" 1 1 2 . 3 "30z0wyr2" "zvg9zop4" 3 3 2 . 3 "30z0wyr2" "uabc3w2i" 1 3 2 . 3 "30z0wyr2" "hidkbh57" 3 2 2 . 3 "30z0wyr2" "4s8fggab" 2 1 2 . 3 "30z0wyr2" "mgb7nktz" 4 1 2 . 3 "30z0wyr2" "261sg8w7" 4 3 2 . 3 "30z0wyr2" "mo19or6c" 4 2 2 . 3 "30z0wyr2" "7unz5s7y" 2 2 2 . 3 "30z0wyr2" "xp5dr3wz" 3 1 3 . 3 "30z0wyr2" "zwd8oerg" 2 3 3 . 3 "30z0wyr2" "kdrn04zt" 3 2 3 . 3 "30z0wyr2" "kz0pah98" 4 3 3 . 3 "30z0wyr2" "zvg9zop4" 4 1 3 . 3 "30z0wyr2" "uabc3w2i" 1 1 3 . 3 "30z0wyr2" "hidkbh57" 1 2 3 . 3 "30z0wyr2" "4s8fggab" 2 1 3 . 3 "30z0wyr2" "mgb7nktz" 2 2 3 . 3 "30z0wyr2" "261sg8w7" 4 2 3 . 3 "30z0wyr2" "mo19or6c" 3 3 3 . 3 "30z0wyr2" "7unz5s7y" 1 3 3 . 3 "30z0wyr2" "xp5dr3wz" 3 2 4 . 3 "30z0wyr2" "zwd8oerg" 3 1 4 . 3 "30z0wyr2" "kdrn04zt" 3 3 4 . 3 "30z0wyr2" "kz0pah98" 2 3 4 . 3 "30z0wyr2" "zvg9zop4" 4 3 4 . 3 "30z0wyr2" "uabc3w2i" 1 3 4 . 3 "30z0wyr2" "hidkbh57" 4 2 4 . 3 "30z0wyr2" "4s8fggab" 4 1 4 . 3 "30z0wyr2" "mgb7nktz" 2 1 4 . 3 "30z0wyr2" "261sg8w7" 1 1 4 . 3 "30z0wyr2" "mo19or6c" 2 2 4 . 3 "30z0wyr2" "7unz5s7y" 1 2 4 . 3 "30z0wyr2" "xp5dr3wz" 1 2 5 . 3 "30z0wyr2" "zwd8oerg" 3 1 5 . 3 "30z0wyr2" "kdrn04zt" 4 1 5 . 3 "30z0wyr2" "kz0pah98" 2 3 5 . 3 "30z0wyr2" "zvg9zop4" 4 3 5 . 3 "30z0wyr2" "uabc3w2i" 2 1 5 . 3 "30z0wyr2" "hidkbh57" 3 2 5 . 3 "30z0wyr2" "4s8fggab" 1 1 5 . 3 "30z0wyr2" "mgb7nktz" 1 3 5 . 3 "30z0wyr2" "261sg8w7" 3 3 5 . 3 "30z0wyr2" "mo19or6c" 2 2 5 . 3 "30z0wyr2" "7unz5s7y" 4 2 5 . 3 "30z0wyr2" "xp5dr3wz" 1 2 6 . 3 "30z0wyr2" "zwd8oerg" 3 1 6 . 3 "30z0wyr2" "kdrn04zt" 1 1 6 . 3 "30z0wyr2" "kz0pah98" 2 2 6 . 3 "30z0wyr2" "zvg9zop4" 4 1 6 . 3 "30z0wyr2" "uabc3w2i" 2 1 6 . 3 "30z0wyr2" "hidkbh57" 4 2 6 . 3 "30z0wyr2" "4s8fggab" 2 3 6 . 3 "30z0wyr2" "mgb7nktz" 3 3 6 . 3 "30z0wyr2" "261sg8w7" 3 2 6 . 3 "30z0wyr2" "mo19or6c" 1 3 6 . 3 "30z0wyr2" "7unz5s7y" 4 3 6 . 3 "30z0wyr2" "xp5dr3wz" 4 3 7 . 3 "30z0wyr2" "zwd8oerg" 2 1 7 . 3 "30z0wyr2" "kdrn04zt" 3 2 7 . 3 "30z0wyr2" "kz0pah98" 3 3 7 . 3 "30z0wyr2" "zvg9zop4" 2 2 7 . 3 "30z0wyr2" "uabc3w2i" 3 1 7 . 3 "30z0wyr2" "hidkbh57" 4 1 7 . 3 "30z0wyr2" "4s8fggab" 2 3 7 . 3 "30z0wyr2" "mgb7nktz" 1 1 7 . 3 "30z0wyr2" "261sg8w7" 1 3 7 . 3 "30z0wyr2" "mo19or6c" 4 2 7 . 3 "30z0wyr2" "7unz5s7y" 1 2 7 . 3 "30z0wyr2" "xp5dr3wz" 1 3 8 . 3 "30z0wyr2" "zwd8oerg" 1 2 8 . 3 "30z0wyr2" "kdrn04zt" 1 1 8 . 3 "30z0wyr2" "kz0pah98" 3 3 8 . 3 "30z0wyr2" "zvg9zop4" 3 2 8 . 3 "30z0wyr2" "uabc3w2i" 4 2 8 . 3 "30z0wyr2" "hidkbh57" 2 3 8 . 3 "30z0wyr2" "4s8fggab" 4 3 8 . 3 "30z0wyr2" "mgb7nktz" 2 2 8 . 3 "30z0wyr2" "261sg8w7" 4 1 8 . 3 "30z0wyr2" "mo19or6c" 2 1 8 . 3 "30z0wyr2" "7unz5s7y" 3 1 8 . 3 "30z0wyr2" "vrgiyaxr" 2 2 1 42 1 "b7nsfswp" "lofv3veu" 7 3 1 34 1 "b7nsfswp" "4h9uvhn9" 4 2 1 30 1 "b7nsfswp" "bpvpb0k8" 2 3 1 60 1 "b7nsfswp" end
I would highly appreciate your help or useful suggestions to create these variables.

Comment