Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generating a variable from different number of rounds

    Hi Everyone,
    I have the following data. This is from an experiment with two treatments and many sessions. I wanted to create a variable that indicates whether the participant is leader in at least one round or not. Player is the leader if P2_id_ingroup==3 and is indicated by leader_inround. The problem is that rounds are same i.e. 8 for all the sessions however number of players are different in each session. For session 1 and 2 there are 18 subjects and for session 3 and 4 there are 24 subjects. Also, 18 participants in session 1 are different from 18 participants in session 2. That implies that P2 in session 1 is different from P2 in session 2 as participant code is also different. I would highly appreciate if you can help me to code

    1) dummy variable that indicates whether the player is leader in at least one round in the session.
    2) categorical variable that indicates the player is leader in how many rounds in the session.
    3) dummy variable that indicates when the player becomes leader for the first time in the session.

    Thank you.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str8 participant_code str3 participant_label byte treatment float session byte(p2_round p2_id_ingroup) float leader_inround
    "ugc9fskp" "P1"  1 1 1 3 1
    "v3lo7uk7" "P2"  1 1 1 1 .
    "j6u4u304" "P3"  1 1 1 1 .
    "e74x5ot1" "P4"  1 1 1 3 1
    "646gkzh7" "P5"  1 1 1 1 .
    "a7c2ojjt" "P6"  1 1 1 2 .
    "tx0lo9wr" "P7"  1 1 1 2 .
    "2k102kxp" "P8"  1 1 1 1 .
    "g8zjnm51" "P9"  1 1 1 2 .
    "lj8ajth8" "P10" 1 1 1 3 1
    "iwd1v5zl" "P11" 1 1 1 2 .
    "zdn23vzw" "P12" 1 1 1 3 1
    "q70udihu" "P13" 1 1 1 3 1
    "wqq3dir0" "P14" 1 1 1 1 .
    "8dxn3jyd" "P15" 1 1 1 2 .
    "2f2kbz0g" "P16" 1 1 1 1 .
    "rth8zlky" "P17" 1 1 1 2 .
    "i7x0agit" "P18" 1 1 1 3 1
    "ugc9fskp" "P1"  1 1 2 3 1
    "v3lo7uk7" "P2"  1 1 2 3 1
    "j6u4u304" "P3"  1 1 2 2 .
    "e74x5ot1" "P4"  1 1 2 2 .
    "646gkzh7" "P5"  1 1 2 1 .
    "a7c2ojjt" "P6"  1 1 2 1 .
    "tx0lo9wr" "P7"  1 1 2 1 .
    "2k102kxp" "P8"  1 1 2 3 1
    "g8zjnm51" "P9"  1 1 2 2 .
    "lj8ajth8" "P10" 1 1 2 1 .
    "iwd1v5zl" "P11" 1 1 2 1 .
    "zdn23vzw" "P12" 1 1 2 2 .
    "q70udihu" "P13" 1 1 2 3 1
    "wqq3dir0" "P14" 1 1 2 2 .
    "8dxn3jyd" "P15" 1 1 2 3 1
    "2f2kbz0g" "P16" 1 1 2 1 .
    "rth8zlky" "P17" 1 1 2 3 1
    "i7x0agit" "P18" 1 1 2 2 .
    "ugc9fskp" "P1"  1 1 3 3 1
    "v3lo7uk7" "P2"  1 1 3 3 1
    "j6u4u304" "P3"  1 1 3 2 .
    "e74x5ot1" "P4"  1 1 3 3 1
    "646gkzh7" "P5"  1 1 3 2 .
    "a7c2ojjt" "P6"  1 1 3 3 1
    "tx0lo9wr" "P7"  1 1 3 1 .
    "2k102kxp" "P8"  1 1 3 1 .
    "g8zjnm51" "P9"  1 1 3 1 .
    "lj8ajth8" "P10" 1 1 3 1 .
    "iwd1v5zl" "P11" 1 1 3 2 .
    "zdn23vzw" "P12" 1 1 3 1 .
    "q70udihu" "P13" 1 1 3 3 1
    "wqq3dir0" "P14" 1 1 3 1 .
    "8dxn3jyd" "P15" 1 1 3 2 .
    "2f2kbz0g" "P16" 1 1 3 2 .
    "rth8zlky" "P17" 1 1 3 3 1
    "i7x0agit" "P18" 1 1 3 2 .
    "ugc9fskp" "P1"  1 1 4 3 1
    "v3lo7uk7" "P2"  1 1 4 2 .
    "j6u4u304" "P3"  1 1 4 1 .
    "e74x5ot1" "P4"  1 1 4 1 .
    "646gkzh7" "P5"  1 1 4 3 1
    "a7c2ojjt" "P6"  1 1 4 2 .
    "tx0lo9wr" "P7"  1 1 4 1 .
    "2k102kxp" "P8"  1 1 4 2 .
    "g8zjnm51" "P9"  1 1 4 3 1
    "lj8ajth8" "P10" 1 1 4 2 .
    "iwd1v5zl" "P11" 1 1 4 3 1
    "zdn23vzw" "P12" 1 1 4 3 1
    "q70udihu" "P13" 1 1 4 1 .
    "wqq3dir0" "P14" 1 1 4 2 .
    "8dxn3jyd" "P15" 1 1 4 3 1
    "2f2kbz0g" "P16" 1 1 4 1 .
    "rth8zlky" "P17" 1 1 4 1 .
    "i7x0agit" "P18" 1 1 4 2 .
    "ugc9fskp" "P1"  1 1 5 2 .
    "v3lo7uk7" "P2"  1 1 5 1 .
    "j6u4u304" "P3"  1 1 5 2 .
    "e74x5ot1" "P4"  1 1 5 1 .
    "646gkzh7" "P5"  1 1 5 2 .
    "a7c2ojjt" "P6"  1 1 5 3 1
    "tx0lo9wr" "P7"  1 1 5 1 .
    "2k102kxp" "P8"  1 1 5 1 .
    "g8zjnm51" "P9"  1 1 5 3 1
    "lj8ajth8" "P10" 1 1 5 3 1
    "iwd1v5zl" "P11" 1 1 5 3 1
    "zdn23vzw" "P12" 1 1 5 1 .
    "q70udihu" "P13" 1 1 5 1 .
    "wqq3dir0" "P14" 1 1 5 3 1
    "8dxn3jyd" "P15" 1 1 5 2 .
    "2f2kbz0g" "P16" 1 1 5 2 .
    "rth8zlky" "P17" 1 1 5 2 .
    "i7x0agit" "P18" 1 1 5 3 1
    "ugc9fskp" "P1"  1 1 6 2 .
    "v3lo7uk7" "P2"  1 1 6 2 .
    "j6u4u304" "P3"  1 1 6 1 .
    "e74x5ot1" "P4"  1 1 6 1 .
    "646gkzh7" "P5"  1 1 6 3 1
    "a7c2ojjt" "P6"  1 1 6 2 .
    "tx0lo9wr" "P7"  1 1 6 1 .
    "2k102kxp" "P8"  1 1 6 3 1
    "g8zjnm51" "P9"  1 1 6 1 .
    "lj8ajth8" "P10" 1 1 6 3 1
    "iwd1v5zl" "P11" 1 1 6 3 1
    "zdn23vzw" "P12" 1 1 6 2 .
    "q70udihu" "P13" 1 1 6 1 .
    "wqq3dir0" "P14" 1 1 6 3 1
    "8dxn3jyd" "P15" 1 1 6 2 .
    "2f2kbz0g" "P16" 1 1 6 3 1
    "rth8zlky" "P17" 1 1 6 2 .
    "i7x0agit" "P18" 1 1 6 1 .
    "ugc9fskp" "P1"  1 1 7 3 1
    "v3lo7uk7" "P2"  1 1 7 2 .
    "j6u4u304" "P3"  1 1 7 3 1
    "e74x5ot1" "P4"  1 1 7 2 .
    "646gkzh7" "P5"  1 1 7 2 .
    "a7c2ojjt" "P6"  1 1 7 1 .
    "tx0lo9wr" "P7"  1 1 7 1 .
    "2k102kxp" "P8"  1 1 7 2 .
    "g8zjnm51" "P9"  1 1 7 1 .
    "lj8ajth8" "P10" 1 1 7 1 .
    "iwd1v5zl" "P11" 1 1 7 1 .
    "zdn23vzw" "P12" 1 1 7 3 1
    "q70udihu" "P13" 1 1 7 2 .
    "wqq3dir0" "P14" 1 1 7 3 1
    "8dxn3jyd" "P15" 1 1 7 2 .
    "2f2kbz0g" "P16" 1 1 7 1 .
    "rth8zlky" "P17" 1 1 7 3 1
    "i7x0agit" "P18" 1 1 7 3 1
    "ugc9fskp" "P1"  1 1 8 2 .
    "v3lo7uk7" "P2"  1 1 8 1 .
    "j6u4u304" "P3"  1 1 8 2 .
    "e74x5ot1" "P4"  1 1 8 3 1
    "646gkzh7" "P5"  1 1 8 1 .
    "a7c2ojjt" "P6"  1 1 8 2 .
    "tx0lo9wr" "P7"  1 1 8 2 .
    "2k102kxp" "P8"  1 1 8 1 .
    "g8zjnm51" "P9"  1 1 8 3 1
    "lj8ajth8" "P10" 1 1 8 1 .
    "iwd1v5zl" "P11" 1 1 8 2 .
    "zdn23vzw" "P12" 1 1 8 3 1
    "q70udihu" "P13" 1 1 8 3 1
    "wqq3dir0" "P14" 1 1 8 1 .
    "8dxn3jyd" "P15" 1 1 8 3 1
    "2f2kbz0g" "P16" 1 1 8 1 .
    "rth8zlky" "P17" 1 1 8 3 1
    "i7x0agit" "P18" 1 1 8 2 .
    "8gyp9aek" "P1"  2 2 1 1 .
    "ymk83fij" "P2"  2 2 1 1 .
    "gq7aeudh" "P3"  2 2 1 3 1
    "3ry2ekkc" "P4"  2 2 1 2 .
    "yuhyvyqw" "P5"  2 2 1 1 .
    "9sa00db8" "P6"  2 2 1 3 1
    "0t3z7tpu" "P7"  2 2 1 2 .
    "p5yteosh" "P8"  2 2 1 1 .
    "ksjy2tdn" "P9"  2 2 1 2 .
    "iw1vxmec" "P10" 2 2 1 3 1
    "oh9jy3xi" "P11" 2 2 1 3 1
    "r18neau3" "P12" 2 2 1 2 .
    "turpb06j" "P13" 2 2 1 2 .
    "ykxegp2o" "P14" 2 2 1 2 .
    "3uggynkm" "P15" 2 2 1 1 .
    "wvxqqan9" "P16" 2 2 1 3 1
    "wnzamb0p" "P17" 2 2 1 3 1
    "auuyrfcb" "P18" 2 2 1 1 .
    "8gyp9aek" "P1"  2 2 2 2 .
    "ymk83fij" "P2"  2 2 2 1 .
    "gq7aeudh" "P3"  2 2 2 1 .
    "3ry2ekkc" "P4"  2 2 2 1 .
    "yuhyvyqw" "P5"  2 2 2 3 1
    "9sa00db8" "P6"  2 2 2 3 1
    "0t3z7tpu" "P7"  2 2 2 1 .
    "p5yteosh" "P8"  2 2 2 2 .
    "ksjy2tdn" "P9"  2 2 2 2 .
    "iw1vxmec" "P10" 2 2 2 1 .
    "oh9jy3xi" "P11" 2 2 2 2 .
    "r18neau3" "P12" 2 2 2 2 .
    "turpb06j" "P13" 2 2 2 3 1
    "ykxegp2o" "P14" 2 2 2 3 1
    "3uggynkm" "P15" 2 2 2 1 .
    "wvxqqan9" "P16" 2 2 2 3 1
    "wnzamb0p" "P17" 2 2 2 3 1
    "auuyrfcb" "P18" 2 2 2 2 .
    "8gyp9aek" "P1"  2 2 3 2 .
    "ymk83fij" "P2"  2 2 3 1 .
    "gq7aeudh" "P3"  2 2 3 3 1
    "3ry2ekkc" "P4"  2 2 3 1 .
    "yuhyvyqw" "P5"  2 2 3 2 .
    "9sa00db8" "P6"  2 2 3 3 1
    "0t3z7tpu" "P7"  2 2 3 1 .
    "p5yteosh" "P8"  2 2 3 1 .
    "ksjy2tdn" "P9"  2 2 3 2 .
    "iw1vxmec" "P10" 2 2 3 2 .
    "oh9jy3xi" "P11" 2 2 3 1 .
    "r18neau3" "P12" 2 2 3 3 1
    "turpb06j" "P13" 2 2 3 1 .
    "ykxegp2o" "P14" 2 2 3 3 1
    "3uggynkm" "P15" 2 2 3 3 1
    "wvxqqan9" "P16" 2 2 3 3 1
    "wnzamb0p" "P17" 2 2 3 2 .
    "auuyrfcb" "P18" 2 2 3 2 .
    "8gyp9aek" "P1"  2 2 4 3 1
    "ymk83fij" "P2"  2 2 4 1 .
    "gq7aeudh" "P3"  2 2 4 3 1
    "3ry2ekkc" "P4"  2 2 4 2 .
    "yuhyvyqw" "P5"  2 2 4 2 .
    "9sa00db8" "P6"  2 2 4 2 .
    "0t3z7tpu" "P7"  2 2 4 2 .
    "p5yteosh" "P8"  2 2 4 1 .
    "ksjy2tdn" "P9"  2 2 4 3 1
    "iw1vxmec" "P10" 2 2 4 3 1
    "oh9jy3xi" "P11" 2 2 4 1 .
    "r18neau3" "P12" 2 2 4 2 .
    "turpb06j" "P13" 2 2 4 1 .
    "ykxegp2o" "P14" 2 2 4 3 1
    "3uggynkm" "P15" 2 2 4 1 .
    "wvxqqan9" "P16" 2 2 4 2 .
    "wnzamb0p" "P17" 2 2 4 3 1
    "auuyrfcb" "P18" 2 2 4 1 .
    "8gyp9aek" "P1"  2 2 5 1 .
    "ymk83fij" "P2"  2 2 5 3 1
    "gq7aeudh" "P3"  2 2 5 1 .
    "3ry2ekkc" "P4"  2 2 5 3 1
    "yuhyvyqw" "P5"  2 2 5 3 1
    "9sa00db8" "P6"  2 2 5 2 .
    "0t3z7tpu" "P7"  2 2 5 1 .
    "p5yteosh" "P8"  2 2 5 2 .
    "ksjy2tdn" "P9"  2 2 5 2 .
    "iw1vxmec" "P10" 2 2 5 2 .
    "oh9jy3xi" "P11" 2 2 5 1 .
    "r18neau3" "P12" 2 2 5 3 1
    "turpb06j" "P13" 2 2 5 3 1
    "ykxegp2o" "P14" 2 2 5 2 .
    "3uggynkm" "P15" 2 2 5 1 .
    "wvxqqan9" "P16" 2 2 5 2 .
    "wnzamb0p" "P17" 2 2 5 3 1
    "auuyrfcb" "P18" 2 2 5 1 .
    "8gyp9aek" "P1"  2 2 6 2 .
    "ymk83fij" "P2"  2 2 6 3 1
    "gq7aeudh" "P3"  2 2 6 2 .
    "3ry2ekkc" "P4"  2 2 6 3 1
    "yuhyvyqw" "P5"  2 2 6 3 1
    "9sa00db8" "P6"  2 2 6 1 .
    "0t3z7tpu" "P7"  2 2 6 3 1
    "p5yteosh" "P8"  2 2 6 1 .
    "ksjy2tdn" "P9"  2 2 6 1 .
    "iw1vxmec" "P10" 2 2 6 1 .
    "oh9jy3xi" "P11" 2 2 6 2 .
    "r18neau3" "P12" 2 2 6 2 .
    "turpb06j" "P13" 2 2 6 3 1
    "ykxegp2o" "P14" 2 2 6 2 .
    "3uggynkm" "P15" 2 2 6 3 1
    "wvxqqan9" "P16" 2 2 6 1 .
    "wnzamb0p" "P17" 2 2 6 1 .
    "auuyrfcb" "P18" 2 2 6 2 .
    "8gyp9aek" "P1"  2 2 7 1 .
    "ymk83fij" "P2"  2 2 7 2 .
    "gq7aeudh" "P3"  2 2 7 3 1
    "3ry2ekkc" "P4"  2 2 7 1 .
    "yuhyvyqw" "P5"  2 2 7 2 .
    "9sa00db8" "P6"  2 2 7 1 .
    "0t3z7tpu" "P7"  2 2 7 3 1
    "p5yteosh" "P8"  2 2 7 2 .
    "ksjy2tdn" "P9"  2 2 7 1 .
    "iw1vxmec" "P10" 2 2 7 3 1
    "oh9jy3xi" "P11" 2 2 7 1 .
    "r18neau3" "P12" 2 2 7 2 .
    "turpb06j" "P13" 2 2 7 3 1
    "ykxegp2o" "P14" 2 2 7 2 .
    "3uggynkm" "P15" 2 2 7 3 1
    "wvxqqan9" "P16" 2 2 7 3 1
    "wnzamb0p" "P17" 2 2 7 2 .
    "auuyrfcb" "P18" 2 2 7 1 .
    "8gyp9aek" "P1"  2 2 8 1 .
    "ymk83fij" "P2"  2 2 8 2 .
    "gq7aeudh" "P3"  2 2 8 3 1
    "3ry2ekkc" "P4"  2 2 8 2 .
    "yuhyvyqw" "P5"  2 2 8 2 .
    "9sa00db8" "P6"  2 2 8 2 .
    "0t3z7tpu" "P7"  2 2 8 3 1
    "p5yteosh" "P8"  2 2 8 1 .
    "ksjy2tdn" "P9"  2 2 8 1 .
    "iw1vxmec" "P10" 2 2 8 3 1
    "oh9jy3xi" "P11" 2 2 8 1 .
    "r18neau3" "P12" 2 2 8 3 1
    "turpb06j" "P13" 2 2 8 2 .
    "ykxegp2o" "P14" 2 2 8 1 .
    "3uggynkm" "P15" 2 2 8 1 .
    "wvxqqan9" "P16" 2 2 8 3 1
    "wnzamb0p" "P17" 2 2 8 2 .
    "auuyrfcb" "P18" 2 2 8 3 1
    "o0cwu276" "P1"  1 3 1 3 1
    "kxcl3yul" "P2"  1 3 1 1 .
    "78dhqp17" "P3"  1 3 1 2 .
    "h0t6bdl8" "P4"  1 3 1 2 .
    "9pvchi8e" "P5"  1 3 1 3 1
    "kkfghqok" "P6"  1 3 1 2 .
    "mh8k0yu6" "P7"  1 3 1 3 1
    "fz15mmc4" "P8"  1 3 1 2 .
    "8uuuwl0q" "P9"  1 3 1 1 .
    "84bec4hr" "P10" 1 3 1 2 .
    "8bxi6m9j" "P11" 1 3 1 1 .
    "n3mqm2li" "P12" 1 3 1 3 1
    "5m91hlhp" "P13" 1 3 1 2 .
    "w30qwp1l" "P14" 1 3 1 3 1
    "87usecxd" "P15" 1 3 1 3 1
    "oxvgyvph" "P16" 1 3 1 3 1
    "xwnja9ev" "P17" 1 3 1 3 1
    "668mlqsi" "P18" 1 3 1 1 .
    "l79u42xw" "P19" 1 3 1 2 .
    "1ya0ms13" "P20" 1 3 1 1 .
    "jwppdg48" "P21" 1 3 1 2 .
    "9lkkwnzc" "P22" 1 3 1 1 .
    "euqxrc45" "P23" 1 3 1 1 .
    "qr8xni99" "P24" 1 3 1 1 .
    "o0cwu276" "P1"  1 3 2 2 .
    "kxcl3yul" "P2"  1 3 2 2 .
    "78dhqp17" "P3"  1 3 2 3 1
    "h0t6bdl8" "P4"  1 3 2 1 .
    "9pvchi8e" "P5"  1 3 2 1 .
    "kkfghqok" "P6"  1 3 2 3 1
    "mh8k0yu6" "P7"  1 3 2 3 1
    "fz15mmc4" "P8"  1 3 2 3 1
    "8uuuwl0q" "P9"  1 3 2 3 1
    "84bec4hr" "P10" 1 3 2 1 .
    "8bxi6m9j" "P11" 1 3 2 1 .
    "n3mqm2li" "P12" 1 3 2 1 .
    "5m91hlhp" "P13" 1 3 2 3 1
    "w30qwp1l" "P14" 1 3 2 1 .
    "87usecxd" "P15" 1 3 2 2 .
    "oxvgyvph" "P16" 1 3 2 2 .
    "xwnja9ev" "P17" 1 3 2 1 .
    "668mlqsi" "P18" 1 3 2 2 .
    "l79u42xw" "P19" 1 3 2 2 .
    "1ya0ms13" "P20" 1 3 2 2 .
    "jwppdg48" "P21" 1 3 2 1 .
    "9lkkwnzc" "P22" 1 3 2 3 1
    "euqxrc45" "P23" 1 3 2 2 .
    "qr8xni99" "P24" 1 3 2 3 1
    "o0cwu276" "P1"  1 3 3 1 .
    "kxcl3yul" "P2"  1 3 3 2 .
    "78dhqp17" "P3"  1 3 3 1 .
    "h0t6bdl8" "P4"  1 3 3 2 .
    "9pvchi8e" "P5"  1 3 3 1 .
    "kkfghqok" "P6"  1 3 3 3 1
    "mh8k0yu6" "P7"  1 3 3 1 .
    "fz15mmc4" "P8"  1 3 3 3 1
    "8uuuwl0q" "P9"  1 3 3 2 .
    "84bec4hr" "P10" 1 3 3 2 .
    "8bxi6m9j" "P11" 1 3 3 3 1
    "n3mqm2li" "P12" 1 3 3 1 .
    "5m91hlhp" "P13" 1 3 3 2 .
    "w30qwp1l" "P14" 1 3 3 3 1
    "87usecxd" "P15" 1 3 3 3 1
    "oxvgyvph" "P16" 1 3 3 2 .
    "xwnja9ev" "P17" 1 3 3 3 1
    "668mlqsi" "P18" 1 3 3 3 1
    "l79u42xw" "P19" 1 3 3 1 .
    "1ya0ms13" "P20" 1 3 3 3 1
    "jwppdg48" "P21" 1 3 3 2 .
    "9lkkwnzc" "P22" 1 3 3 2 .
    "euqxrc45" "P23" 1 3 3 1 .
    "qr8xni99" "P24" 1 3 3 1 .
    "o0cwu276" "P1"  1 3 4 2 .
    "kxcl3yul" "P2"  1 3 4 3 1
    "78dhqp17" "P3"  1 3 4 2 .
    "h0t6bdl8" "P4"  1 3 4 3 1
    "9pvchi8e" "P5"  1 3 4 1 .
    "kkfghqok" "P6"  1 3 4 1 .
    "mh8k0yu6" "P7"  1 3 4 2 .
    "fz15mmc4" "P8"  1 3 4 3 1
    "8uuuwl0q" "P9"  1 3 4 2 .
    "84bec4hr" "P10" 1 3 4 3 1
    "8bxi6m9j" "P11" 1 3 4 2 .
    "n3mqm2li" "P12" 1 3 4 1 .
    "5m91hlhp" "P13" 1 3 4 1 .
    "w30qwp1l" "P14" 1 3 4 3 1
    "87usecxd" "P15" 1 3 4 2 .
    "oxvgyvph" "P16" 1 3 4 2 .
    "xwnja9ev" "P17" 1 3 4 1 .
    "668mlqsi" "P18" 1 3 4 1 .
    "l79u42xw" "P19" 1 3 4 3 1
    "1ya0ms13" "P20" 1 3 4 3 1
    "jwppdg48" "P21" 1 3 4 2 .
    "9lkkwnzc" "P22" 1 3 4 1 .
    "euqxrc45" "P23" 1 3 4 3 1
    "qr8xni99" "P24" 1 3 4 1 .
    "o0cwu276" "P1"  1 3 5 1 .
    "kxcl3yul" "P2"  1 3 5 1 .
    "78dhqp17" "P3"  1 3 5 3 1
    "h0t6bdl8" "P4"  1 3 5 1 .
    "9pvchi8e" "P5"  1 3 5 3 1
    "kkfghqok" "P6"  1 3 5 1 .
    "mh8k0yu6" "P7"  1 3 5 2 .
    "fz15mmc4" "P8"  1 3 5 2 .
    "8uuuwl0q" "P9"  1 3 5 2 .
    "84bec4hr" "P10" 1 3 5 2 .
    "8bxi6m9j" "P11" 1 3 5 3 1
    "n3mqm2li" "P12" 1 3 5 1 .
    "5m91hlhp" "P13" 1 3 5 3 1
    "w30qwp1l" "P14" 1 3 5 2 .
    "87usecxd" "P15" 1 3 5 1 .
    "oxvgyvph" "P16" 1 3 5 2 .
    end
    Last edited by Muhammad Arslan Iqbal; 10 May 2022, 19:51.

  • #2
    I can give you the first two:
    Code:
    replace leader_inround = 0 if missing(leader_inround)
    
    isid participant_code p2_round, sort
    
    by participant_code: egen wanted1 = max(leader_inround)
    by participant_code: egen wanted2 = total(leader_inround)
    I do not understand the word "when" in your third request. There is no evident time sequence to refer to here. Please explain.

    Note: coding leader_inround, or for that matter any yes/no variable, as 1/missing in Stata is a bad idea. That may work well in spreadsheets, but it is a recipe for errors in Stata. The preferred coding of such variables in Stata is 0 = no, 1 = yes. Use of that avoids errors and simplifies code considerably. That is the rational for the first command in my solution.

    Comment


    • #3
      Thank you Clyde for helping me out on this. I will be careful next time about the missing values. The code worked for first two variables. For the third, I want to generate a dummy variable participant_code level variable that takes value 1 for the first instance of leader_inround==1 for that participant. Some players might become the leader for the first time in P2_round==1 others might become leader for the first time in P2_round==8 for instance. That is why I used the words "when the player becomes the leader i.e. leader_inround==1 for the first time" out of 8 rounds.

      Comment


      • #4
        I have tried the following code and it seems to work:
        Code:
        bysort participant_code (p2_round): gen cum_leader_tillnow = sum(leader_inround)
        bysort participant_code: gen byte leader_firsttime = cum_leader_tillnow == 1  & cum_leader_tillnow[_n - 1] != cum_leader_tillnow

        Comment

        Working...
        X