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.
How to store formatted number in a noteStataMP 15.1 on macOS Sierra I'd like to display the number of observations in a note with formatti…
Question about graph bar command and how to include a second y-axis for a second variableDear Stata forum, I have a question about the graph bar command. So far, I have been using the foll…
Compare elements of locals and return distingushing elementsDear all, I have the following three locals: Code: local house "1 2 3 4" local garden "1 2 3" loc…
XTQREG: how to add statistics to regression (e.g. pseudo R2) and how to determine the quantile?Hi, how do I include these extra statistics in xtqreg: - I want to add a measure of fit (such as the…
Create a dataset from the current datasetHello Can someone help me create a dataset from my current dataset? I have the following dataset: …
Subscribe to:
Post Comments (Atom)
0 Response to Recode many different observations in one variable.
Post a Comment