在Stata中查找社交网络组件 [英] Find social network components in Stata

查看:99
本文介绍了在Stata中查找社交网络组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[我从另一篇帖子中复制了以下示例的一部分,并根据我的特定需求进行了更改]

[I copied part of the below example from a separate post and changed it to suit my specific needs]

pos_1    pos_2
  2        4
  2        5
  1        2
  3        9
  4        2
  9        3

以上内容读取为person_2已连接到person_4,...,person_4已连接到person_2,并且person_9已连接到person_3.

The above is read as person_2 is connected to person_4,...,person_4 is connected to person_2, and person_9 is connected to person_3.

我想创建第三个分类的变量,组件,该组件让我知道观察到的链接是否是该网络内连接的组件(子网)的一部分.在这种情况下,网络中有两个连接的组件:

I want to create a third categorical [edited] variable, component, that lets me know if the observed link is part of a connected component (subnetwork) within this network. In this case, there are two connected components in the network:

pos_1    pos_2    component
  2        4        1
  2        5        1
  1        2        1
  3        9        2
  4        2        1
  9        3        2

组件1中的所有节点都相互连接,但没有连接到组件2中的节点,反之亦然.有没有办法在Stata中生成此组件变量?我知道有其他程序可以执行此操作,但是如果我可以将其集成到Stata中,我的代码将更加无缝.

All nodes in component 1 are connected to each other, but not to the nodes in component 2 and vice versa. Is there a way to generate this component variable in Stata? I know there are alternative programs to do this in, but my code would be more seamless if I can integrate it into Stata.

推荐答案

如果您将数据reshape转换为长格式,则可以使用group_id(来自SSC)获得所需的内容:

If you reshape the data to long form, you can use group_id (from SSC) to get what you want:

clear
input pos_1    pos_2
  2        4
  2        5
  1        2
  3        9
  4        2
  9        3
end

gen id = _n
reshape long pos_, i(id) j(n)

clonevar comp = id
list, sepby(comp)

group_id comp, match(pos)

reshape wide pos_, i(id) j(n)

egen component = group(comp)
list

这篇关于在Stata中查找社交网络组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆