Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
Nick Cox <njcoxstata@gmail.com> |

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 21:39:35 +0100 |

See Stata Tip 71 in Stata Journal 8(4) 2008. Nick

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 previousrows" {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/

**References**:**st: Identify combinations without respect to the order of the elements***From:*Oliver Jones <ojones@wiwi.uni-bielefeld.de>

- Prev by Date:
**st: Errors arise when dataset is modified in Bootstrapping** - Next by Date:
**Re: st: increase digits after decimal point in p value** - Previous by thread:
**st: Identify combinations without respect to the order of the elements** - Next by thread:
**re: st: Identify combinations without respect to the order of the elements** - Index(es):