Dear colleagues,
I am trying to group observations based on their (possibly indirect) connections . For example, imagine workers may have worked at different branches and the following is their working history (not time sensitive).
Code:
clear
input personid branchid
1 1
2 1
1 2
3 2
3 3
4 3
5 4
6 4
end
The goal is to generate a new variable (group) that yields the following.
personid branchid group
1 1 1
2 1 1
1 2 1
3 2 1
3 3 1
4 3 1
5 4 2
6 4 2
The logic is that personal 1 is directly connected to person 2 (they both worked at branch office 1) and also to person 3 (they both worked at branch office 2), and indirectly connected to person 4 (because 3 and 4 both worked at branch office 3), hence persons 1-4 shall all belong to the same group. Similarly for person 5 and 6 as another group. Any comments on how to code and generate the group would be greatly appreciated!
Thanks.
Hua
Related Posts with Group observations with indirect tie.
How to save covariance matrix of the estimated fixed effects after reghdfeHi everybody! I have a longitudinal dataset (individuals x years, individuals live in different are…
Unique String Values Across Variables and Duplicate Observations for an ID VariableHi! I'm trying to count the unique number of string values for variable mainx, and x1-9. My dataset …
estout column output helpHello, I'm using the estout command like this: Code: sysuse auto glm foreign price, fam(bin) l…
Identifying consecutive observations that meet a determined valueHello Statalisters, I am starting in the world of Stata and I would appreciate suggestions on how t…
Having trouble counting unqiue dates by ID variable (_n and _N); Other options?Hello, I am having an issue getting my data coded properly. I have a dataset of patients with encou…
Subscribe to:
Post Comments (Atom)
0 Response to Group observations with indirect tie.
Post a Comment