Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Airey, David C" <david.airey@vanderbilt.edu> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | re: st: Identify combinations without respect to the order of the elements |
Date | Tue, 12 Jul 2011 10:59:19 -0500 |
. oops, I gave the wrong subject header... > I wonder if this message would help? > > <http://www.stata.com/statalist/archive/2011-06/msg01320.html> > > You might find others in the archives. > > -Dave > >> Hello everyone, >> >> I have a dataset with the number of people moving from one >> city to another city (or stay where they live). We have records >> for 342 cities. The data set looks like this: >> (just showing the structure with the three cities A, B and C) >> >> from | to | n >> .............. >> A | A | 29 >> A | B | 1 >> A | C | 3 >> B | A | 8 >> B | B | 90 >> B | C | 0 >> C | A | 80 >> C | B | 70 >> C | C | 800 >> >> Is there an easy way to generate an identifier variable that >> identifies pairs of cities? >> In pseudo code it should be something like: >> >> gen identifier = . >> local counter = 0 >> forval i = 1/_N { >> if "reverse city-combination in the current row i exists in previous rows" { >> local ident_value = value of the identifier in that previous row >> replace identifier = `ident_value' >> } >> else { >> local counter = `counter' + 1 >> replace identifier = counter >> } >> } >> >> The result should look like this: >> >> from | to | n | identifier >> ......................... >> A | A | 29 | 1 >> A | B | 1 | 2 >> A | C | 3 | 3 >> B | A | 8 | 2 >> B | B | 90 | 4 >> B | C | 0 | 5 >> C | A | 80 | 3 >> C | B | 70 | 5 >> C | C | 800 | 6 >> >> >> Best >> Oliver * * 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/