I have a question on creating blocks for individual ids in STATA. Here is my sample data. There are 10 observations of ids and output, y.
Code:
clear input byte id float y 1 .27450386 2 .00633896 3 .026175763 4 .243485 5 .27391464 6 .17234083 7 .05394611 8 .3382942 9 .2040645 10 .3772962 end
The first column is the id in our sample data, where 2nd and 3rd columns are matched ids.
Code:
clear input byte(id match1 match2) 1 4 8 2 5 9 3 6 10 4 7 1 5 8 2 6 9 3 7 10 4 8 1 5 9 2 6 10 3 7 end
My desired final result is to make a block of paired observations.
Code:
clear input byte(id match) float y 1 . .27450386 1 4 .243485 1 8 .3382942 2 . .00633896 2 5 .27391464 2 9 .2040645 3 . .026175763 3 6 .17234083 3 10 .3772962 4 . .243485 4 7 .05394611 4 1 .27450386 5 . .27391464 5 8 .3382942 5 2 .00633896 6 . .17234083 6 9 .2040645 6 3 .026175763 7 . .05394611 7 10 .3772962 7 4 .243485 8 . .3382942 8 1 .27450386 8 5 .27391464 9 . .2040645 9 2 .00633896 9 6 .17234083 10 . .3772962 10 3 .026175763 10 7 .05394611 end
That is, I need data of blocks, and each block should have all 3 observations of each matched-pair.
I believe this can be done by combining expand and merge... but I wonder if there is a more simple and easy way.
Could anyone give me advice on how to deal with it in a short, straightforward code?
0 Response to Creating blocks for ids
Post a Comment