I have this data on the start and end month of Giver-Receiver relationship.
Giver Receiver Start End
A B 201807 201808
A B 202001 202003
B C 201902 201903
B D 202002 202004
I want to create a file on the duration of longer "chain" relationships.
The chain from A to B to D has an overlapped time from 202003 to 202112.
But chain from A to B to C does not have any overlapped time, so it won't create any line in the output.
The desired output file is either
ID1 ID2 ID3 Start End
A B D 202002 202003
or
ID1 ID2 ID3 Month
A B D 202002
A B D 202003
Either one form is fine. Both are hard.
I actually want to create any 4-firm or 5-firm or any length of longer chains, but creating 3-firm chain is already hard enough, so I would like begin with creating 3-firm chain.
This seems to be a hard problem on Stata or on any language.
One idea I tried to pursue was to create a data like this (I don't know how to):
Giver Receiver Month
A B 201807
A B 201808
A B 202001
A B 202002
A B 202003
B C 201902
B C 201903
B D 202002
B D 202003
B D 202004
and from this I construct my goal, but again I can't figure out how to do this, either. Just an idea.
What command or trick will likely to help me?
Giver Receiver Start End
A B 201807 201808
A B 202001 202003
B C 201902 201903
B D 202002 202004
I want to create a file on the duration of longer "chain" relationships.
The chain from A to B to D has an overlapped time from 202003 to 202112.
But chain from A to B to C does not have any overlapped time, so it won't create any line in the output.
The desired output file is either
ID1 ID2 ID3 Start End
A B D 202002 202003
or
ID1 ID2 ID3 Month
A B D 202002
A B D 202003
Either one form is fine. Both are hard.
I actually want to create any 4-firm or 5-firm or any length of longer chains, but creating 3-firm chain is already hard enough, so I would like begin with creating 3-firm chain.
This seems to be a hard problem on Stata or on any language.
One idea I tried to pursue was to create a data like this (I don't know how to):
Giver Receiver Month
A B 201807
A B 201808
A B 202001
A B 202002
A B 202003
B C 201902
B C 201903
B D 202002
B D 202003
B D 202004
and from this I construct my goal, but again I can't figure out how to do this, either. Just an idea.
What command or trick will likely to help me?
Code:
gen Giver="" gen Receiver="" gen Start="" gen End="" set obs 4 replace Giver="A" if _n==1 | _n==2 replace Receiver="B" if _n==1 | _n==2 replace Giver="A" if _n==3 | _n==4 replace Receiver="C" if _n==3 replace Receiver="D" if _n==4 replace Start="201807" if _n==1 replace Start="202001" if _n==2 replace Start="201902" if _n==3 replace Start="202002" if _n==4 replace End="201808" if _n==1 replace End="202003" if _n==2 replace End="201903" if _n==3 replace End="202004" if _n==4
Comment