Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 72772

Count how many times an individual lies in the same cluster as another one

$
0
0
Hi all, I have a database that comprises cities divided into clusters for each year. In other words, I applied a community detection algorithm for different databases containing cities in different years base on modularity.
The final database looks like this:

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input int v1 str21 city byte cluster float year
0 "city1"  0  2000. 
1 "city2"  2. 2000
2 "city3" 1.  2000
3 "city4" 0  2000
4 "city5" 2  2000
0 "city1" 2  2001
1 "city2" 1 2001
2 "city3" 0 2001
3 "city4" 0 2001
4 "city5" 0 2001
0 "city1" 1 2002
1 "city2" 2 2002
2 "city3" 0  2002
3 "city4" 0 2002
4 "city5" 1 2002
end
Now what would like to do is counting how many times a city ends up in the same cluster as another city each year.
So in the mock example above I should end up with a 5 times 5 matrix where rows and columns are cities where each entry represent the number of times that city I and j are in the same cluster (independently of which cluster) in all years.

Thank you

Viewing all articles
Browse latest Browse all 72772

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>