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" <[email protected]>
To   <[email protected]>
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

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

[email protected] 

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:
> For my purposes, AB and BA are identical. How do I create the list?

*   For searches and help try:

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