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

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


From   Stas Kolenikov <[email protected]>
To   [email protected]
Subject   Re: st: data manipulation - generating pairs of a list
Date   Fri, 20 Aug 2004 17:06:50 -0400 (EDT)

> 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?

If you have numeric IDs of your countries, then you can clean up the
duplicates by something like

keep if id1>id2

You can create those numeric IDs by something like

gen id = _n

if observations are unique, or by

egen id = group(country)

if they are not.

 ---                                    Stas Kolenikov
 --       Ph.D. student in Statistics at UNC-Chapel Hill
 - http://www.komkon.org/~tacik/  -- [email protected]

* This e-mail and all attachments to it are not intended to provide any
* reasonable point of view and was transmitted to you in error. It
* should be immediately deleted by all recipients unless they really
* enjoy communicating with the author :). Other restrictions apply.

*
*   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