Announcement

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

  • Assign answer to a question within a subgroup to another member of this subgroup

    Dear statalist members,

    I have a question regarding the following problem.
    I have survey data which consists of 28 individuals were two of those 28 individuals always formed a group. Hence, I have 14 subgroups within my dataset.
    These two individuals then belong to the same number in groupid_in_subsession3.
    For example ID 17 and 15 would be in subgroup 6 and so on.

    My question is, how can I assign the answer to the question underlying the variable p2qe from ID 17 to ID 15 and from ID 15 to ID 17 with a loop over all the subgroups.
    Or in other words, how do I assign the answer from one subgroup member to the other for both observations in the subgroup.

    Your help is highly appreciated and thanks in advance
    Carsten

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long(ID p2qe) byte groupid_in_subsession3
    17 3  6
     6 2  5
    28 3  9
     3 3  3
    25 1  1
    12 3  5
     4 3 14
    26 3  7
     2 3  2
    10 1 12
    14 1  4
    20 3  9
     7 3 11
     9 1 10
    11 2 13
    13 1  8
     8 3 14
    23 3 12
     5 1 13
    21 3 11
    19 3  2
     1 1  3
    16 1  7
    18 3  1
    22 1  8
    15 3  6
    27 2 10
    24 3  4
    end
    label values ID ID
    label def ID 1 "22xaCaI0Ij", modify
    label def ID 2 "48F0lHYX8F", modify
    label def ID 3 "55tDvsD3Ez", modify
    label def ID 4 "7rdsa9uWd3", modify
    label def ID 5 "9DvjphQ7Hp", modify
    label def ID 6 "AGc42vQkfu", modify
    label def ID 7 "GSZCL9jrz8", modify
    label def ID 8 "LbQzSvKqQh", modify
    label def ID 9 "Mgm3JMW4CJ", modify
    label def ID 10 "O1AsazarsL", modify
    label def ID 11 "OaoNOQvLAn", modify
    label def ID 12 "OgjfeHKyCP", modify
    label def ID 13 "PL2QucInwf", modify
    label def ID 14 "UMnZ5IISTd", modify
    label def ID 15 "XRdElMYZSa", modify
    label def ID 16 "a11j1BAzog", modify
    label def ID 17 "aL9ZCUqVrm", modify
    label def ID 18 "bVimpYzTvL", modify
    label def ID 19 "d1AaPYBJ9f", modify
    label def ID 20 "ecB6oXdBqe", modify
    label def ID 21 "iznb1ZmD4d", modify
    label def ID 22 "pOoCZTR31j", modify
    label def ID 23 "reb70xgopQ", modify
    label def ID 24 "ua82vgl8sq", modify
    label def ID 25 "usdTiatLLK", modify
    label def ID 26 "v2oI45cVPv", modify
    label def ID 27 "x1FREH4zYb", modify
    label def ID 28 "y0BHWBOaMr", modify
    label values p2qe p2qe
    label def p2qe 1 "yes", modify
    label def p2qe 2 "no", modify
    label def p2qe 3 "maybe", modify

  • #2
    Code:
    bys groupid_in_subsession3 (ID): gen wanted=cond(_n==1, p2qe[2], p2qe[1])
    lab values wanted p2qe

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      Code:
      bys groupid_in_subsession3 (ID): gen wanted=cond(_n==1, p2qe[2], p2qe[1])
      lab values wanted p2qe
      Thank you so much for your help.
      It works perfectly.


      With kind regards
      Carsten

      Comment

      Working...
      X