Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: data manipulation - generating pairs of a list


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: data manipulation - generating pairs of a list
Date   Fri, 20 Aug 2004 20:18:06 +0100

In addition to other answers, please see 

http://www.stata.com/support/faqs/data/pairs.html

In this case, the problem appears simpler
than that discussed in the FAQ. In addition, 
no loops appear needed. 

local nobs = _N 
expand `nobs' 
bysort country1 : gen temp = _n 
gen country2 = country1[`nobs' * temp]
drop if country2 >= country1

Nick 
n.j.cox@durham.ac.uk 

Mark Manger
 
> I'm struggling with a data manipulation problem: I have a 
> dataset with list
> of observations on a string variable and want to create pairwise
> combinations. My dataset looks like this:
> 
> country1
> A
> B
> C
> 
> I need the possible combinations so that the new dataset looks like
> 
> country1 country2
> A B
> A C
> C B
> 
> I could take the same list in two different datasets and then use the
> command "cross", but that gives me 3! combinations:
> 
> AB AC BA BC CA CB
> 
> For my purposes, AB and BA are identical. How do I create the list?

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index