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
Related Posts with Recode many different observations in one variable.
Using rangestat when there are gaps in the date identifierHi, I am trying to use rangestat to perform rolling regressions over a data panel. My data correspo…
How to create new variables using observations from other variable but observations contain spaces?I tried to use the following command to create new variables using observations from a variable "ind…
Creating dummy variable and assigning a unique individual to one of many possible groupHi everyone, I want to create two random dataset with 45,000 students. Students can be enrolled fro…
Moving vertical axis in graph hbarHi, I'm trying to plot a variable called "teleworking rate" by region. So my data looks like: tw_r…
Repeated measures ANOVA for two dependent variables separated by time *I have a dependent variable that is measured in the past and present, and these two are coded as two…
Subscribe to:
Post Comments (Atom)
0 Response to Recode many different observations in one variable.
Post a Comment