Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Generating all possible combinations of pairs


From   "Svend Juul" <[email protected]>
To   <[email protected]>
Subject   Re: st: Generating all possible combinations of pairs
Date   Wed, 27 Sep 2006 13:10:31 +0200

Karin wrote:

I have some repeated paired observations and would like to generate
all possible combinations of pairs.

The data looks like this :-
Pair  Subject  Var
101        1  134
101        2  563
101        2  455
102        1  345
102        1  363
102        1  299
102        2  647
102        2  352

I wish to generate data that looks like this :-
Pair  Var1  Var2
101   134   563
101   134   455
102   345   647
102   345   352
102   363   647
102   363   352
102   299   647
102   299   352
----------------------------------------------------------------

This is a case for -joinby-:

clear
input pair subject var
101  1  134
101  2  563
101  2  455
102  1  345
102  1  363
102  1  299
102  2  647
102  2  352
end

sort pair
preserve
keep if subject==2
rename var var2
save x2.dta , replace
restore
keep if subject==1
rename var var1
joinby pair using x2.dta
drop subject
sort pair var1 var2
list

Hope this helps
Svend

__________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone: +45 8942 6090
Home:  +45 8693 7796
Email: [email protected]
__________________________________________ 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index