Hello Statalist,
I have data on different subjects, who are assigned either to group A or B. Each of them has a specific partner, let's say subject id 16499 is in group A and subject id 16424 is in group B, and they both form a pair (but they constitute two different observations since they are different subjects). Variable "partner" shows who is each subject's partner. Let's say I have an X-variable with non-missing values for group A subjects, but missing for group B subjects. And I have Y-variable with non-missing values for group B subjects but missing for group A subjects. I want the value of Y-variable of subject B01 to replace the missing value of X-variable of subject A01.
As an example:
The final outcome should be subject A01 having the missing value of "returned" replaced by the value of "returned" of his partner, in this case B01.
NOTE: Please note that it is possible that one single subject is assigned two different partners. So A11 might have B11 and B13 as partners and I need to duplicate the observation for A11 as he has two paired subjects, and therefore two different values of the var "returned".
NOTE 2: Note also that the number correspondence might be different and not in order as in the example. So that not all A01 subjects are matched/paired to B01 subjects. We can have subject A20 matched to B02.
These two notes make the work with Stata observation numbers difficult, or I have not found a way to work with it.
Hope it makes sense. Thanks a lot in advance.
Francisco
I have data on different subjects, who are assigned either to group A or B. Each of them has a specific partner, let's say subject id 16499 is in group A and subject id 16424 is in group B, and they both form a pair (but they constitute two different observations since they are different subjects). Variable "partner" shows who is each subject's partner. Let's say I have an X-variable with non-missing values for group A subjects, but missing for group B subjects. And I have Y-variable with non-missing values for group B subjects but missing for group A subjects. I want the value of Y-variable of subject B01 to replace the missing value of X-variable of subject A01.
As an example:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long child_id str3 code str1 group byte(sent returned) str3 partner 16499 "A01" "A" 0 . "B01" 16424 "B01" "B" . 0 "A01" 16443 "A03" "A" 1 . "B03" 16426 "B03" "B" . 1 "A03" 16428 "A05" "A" 1 . "B05" 16444 "B05" "B" . 1 "A05" 16429 "A07" "A" 0 . "B07" 16436 "B07" "B" . 0 "A07" 16431 "A09" "A" 0 . "B09" 16433 "B09" "B" . 0 "A09" 16423 "A11" "A" 1 . "B11" 16421 "B11" "B" . 3 "A11" 16450 "B13" "B" . 7 "A11" end
NOTE: Please note that it is possible that one single subject is assigned two different partners. So A11 might have B11 and B13 as partners and I need to duplicate the observation for A11 as he has two paired subjects, and therefore two different values of the var "returned".
NOTE 2: Note also that the number correspondence might be different and not in order as in the example. So that not all A01 subjects are matched/paired to B01 subjects. We can have subject A20 matched to B02.
These two notes make the work with Stata observation numbers difficult, or I have not found a way to work with it.
Hope it makes sense. Thanks a lot in advance.
Francisco
Comment