Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: AW: Creating a Group Pair ID (where the generating variables order shouldn't matter)


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: AW: Creating a Group Pair ID (where the generating variables order shouldn't matter)
Date   Fri, 23 Jul 2010 11:27:22 +0200

<> 

Essentially, the technique advocated in NJC`s tip boils down to a simple
trick:


*************
clear*
inp str20 c1id str20 c2id
"US" "Canada"
"US" "Mexico"
"Canada" "US"
"US" "France"
"France" "England"
"France" "US"
end

gen first = cond(c1id < c2id, c1id, c2id)
gen second = cond(c2id < c1id, c1id, c2id)

egen newid = group(first second)

drop first second
sort newid

l, sepby(newid) noo
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss
Gesendet: Freitag, 23. Juli 2010 11:21
An: statalist@hsphsun2.harvard.edu
Betreff: st: AW: Creating a Group Pair ID (where the generating variables
order shouldn't matter)


<> 

Try NJC`s http://www.stata-journal.com/article.html?article=dm0043



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von J Taylor
Gesendet: Freitag, 23. Juli 2010 11:00
An: statalist@hsphsun2.harvard.edu
Betreff: st: Creating a Group Pair ID (where the generating variables order
shouldn't matter)

I am trying to create an ID corresponding to numbers from two lists.
For example, if the two lists were of countries, one would have

clear
input str20 c1id str20 c2id
"US" "Canada"
"US" "Mexico"
"Canada" "US"
"US" "France"
"France" "England"
"France" "US"
end
egen newid = group(c1id c2id)

I would like newid to create an ID pair for each country pair.  My
first instinct was to use the egen group command.  However, the
problem is that egen group takes into account which id comes first.
For example, (c1id,c2id)=(United States,Canada) and (c1id,c2id)=(
Canada ,United States) have different IDs.  I would like them to be
able to have the same ID.  That is, I would like to create newid as a
group pair ID, reflecting which two countries are in the pair, and
where the order doesn't matter.

Any thoughts on how to do this?

Thanks,
JT
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index