Hi,
I am analyzing municipalities in Sweden and my data consists of 290 different municipalities. In my analysis, I will only study 59 of these municipalities and in which each municipality has a code representing which municipality it is. To work with the data but without dropping all the observations that I am not analyzing have I created a variable (mydata) that indicates if a municipality is going to be investigated or not. Where 1 indicates that it's in the analysis and 0 otherwise. So, my problem is that I want to recode all the 59 observations in replacing 0 for 1, but without writing 59 lines of code. I have tried to make a loop using foreach, but without any success, see suggestion further down. Would be grateful if anybody has some good ideas they want to share.


gen mydata =0
recode mydata (0=1) if municipality==114
recode mydata (0=1) if municipality==117
recode mydata (0=1) if municipality==120
recode mydata (0=1) if municipality==123
recode mydata (0=1) if municipality==126
recode mydata (0=1) if municipality==127
recode mydata (0=1) if municipality==136
recode mydata (0=1) if municipality==138
recode mydata (0=1) if municipality==139
.........

Suggestion
foreach mydata {
recode (0=1) if municipality== 114 117 120 123 126 127 136 138 139 160 163 180 181 182 183 184 186 188 191 319 380 381 382 428 461 480 483 484 562 580 581 586 680 682 683 780 1280 1283 1382 1384 1480 1481 1485 1488 1490 1880 1980 1981 2029 2080 2081 2085 2180 2282 2380 2582 2584

}

/David