Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: Identify combinations without respect to the order of the elements


From   Oliver Jones <[email protected]>
To   [email protected]
Subject   st: Identify combinations without respect to the order of the elements
Date   Tue, 12 Jul 2011 14:41:47 +0200

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

--
Universität Bielefeld
Fakultät für Wirtschaftswissenschaften
Lehrstuhl für Ökonometrie und Statistik
- -
Bielefeld University
Faculty of Business Administration and Economics
Chair of Econometrics and Statistics
- -
Raum / room:  V9-110
Tel / phone:  +49 (0)521 106 4871
---
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index