Hi!
I'm currently working with data of this form
I have c1 and c2 which are county IDs. zone is a variable which identifies the commuting zone that counties in c1 are in. In this case, counties 1 and 2 are in the same commuting zone (100), while county 3 is in commuting zone 200. I'd like to create the out_zone variable which is a dummy = 0 if the two counties are in the same commuting zone and = 1 if they are not in the same commuting zone. For example, here, out_zone is 0 when the rows contain combinations of counties 1 and 2 but out_zone = 1 when rows contain combinations of county 3 and the other two.
In order to create the out_zone variable, my initial thought was to have a for loop creating macros by the zone variable (adding all c1s into a macro if they have the same zone number). Then I could generate out_zone , specifying 0 if c1 and c2 are in the same macro. However, I'm not quite sure how to do this and it seems to me that there should be a simpler way.
Any help would be greatly appreciated!
I'm currently working with data of this form
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(c1 c2 zone out_zone) 1 1 100 0 1 2 100 0 1 3 100 1 2 1 100 0 2 2 100 0 2 3 100 1 3 1 200 1 3 2 200 1 3 3 200 1 end
In order to create the out_zone variable, my initial thought was to have a for loop creating macros by the zone variable (adding all c1s into a macro if they have the same zone number). Then I could generate out_zone , specifying 0 if c1 and c2 are in the same macro. However, I'm not quite sure how to do this and it seems to me that there should be a simpler way.
Any help would be greatly appreciated!
Comment