Hi all,
I am trying to create a new variable that indicates whether a switch between organizations the focal firm works with was a switch back to a firm they have already previously worked with. I have added some sample data below. The assignee is the focal firm and the lawfirm is the firm they are working with. I have already created a variable "switchlaw" indicating whether a new observation indicates a change from the previous one. Now I would like to create a new variable taking the value one whenever a switch (so switchlaw==1) represents a switch back to a firm that the assignee has already worked with. So, for example, the new variable should take the value "0" in row two (lawfirm 2 has not been worked with before) but the value "1" in row four (lawfirm two had already been worked with in row two. For the fourth to last row (assignee two lawfirm one) the variable should take the value 0, however, since assignee two hasn't worked with lawfirm one, only assignee one has.
I feel like a loop and using _N might be in order here but I couldn't quite figure it out by myself. Any help would be very much appreciated.
Thanks everybody
I am trying to create a new variable that indicates whether a switch between organizations the focal firm works with was a switch back to a firm they have already previously worked with. I have added some sample data below. The assignee is the focal firm and the lawfirm is the firm they are working with. I have already created a variable "switchlaw" indicating whether a new observation indicates a change from the previous one. Now I would like to create a new variable taking the value one whenever a switch (so switchlaw==1) represents a switch back to a firm that the assignee has already worked with. So, for example, the new variable should take the value "0" in row two (lawfirm 2 has not been worked with before) but the value "1" in row four (lawfirm two had already been worked with in row two. For the fourth to last row (assignee two lawfirm one) the variable should take the value 0, however, since assignee two hasn't worked with lawfirm one, only assignee one has.
I feel like a loop and using _N might be in order here but I couldn't quite figure it out by myself. Any help would be very much appreciated.
Thanks everybody
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(assignee lawfirm) float switchlaw 1 1 . 1 2 1 1 3 1 1 2 1 1 2 0 1 2 0 1 1 1 1 2 1 2 2 . 2 4 1 2 5 1 2 1 1 2 5 1 2 4 1 2 6 1 end
Comment