Hello I am trying to write a dofile that allows me to be the most specific with my results using looping code, but have struggled to think of anything that works so far.
My dataset has 406 observations and I am running Stata 14.1 for windows. I have an id variable that is specific to the first two digits, and you'll notice that 111, 112, 113, 114, and 115 add up to 3008, and that 1131, 1132, 1133, 1141, 1142, 1151, and 1152 add up to 3005. Therefore I want to keep the three digit id observations for the 11 level of specification because the three digit level accounts for the greatest amount (3,008 at the three digit level compared to 3005 at the four digit level and 3006 at the two digit level.
Does anyone have any idea what my code should be to generate a check variable and then keep only the specific id observations that account for the greatest amount for each unique first number?
My dataset looks something like this:
id amt length firstnum
11 3006 2 11
21 5725 2 21
22 23919 2 22
111 0 3 11
112 0 3 11
113 1603 3 11
114 136 3 11
115 1269 3 11
211 951 3 21
212 2596 3 21
213 2177 3 21
221 23919 3 22
1131 51 4 11
1132 68 4 11
1133 1483 4 11
1141 42 4 11
1142 94 4 11
1151 558 4 11
1152 623 4 11
1153 86 4 11
2111 951 4 21
2121 15 4 21
2122 1343 4 21
2123 1237 4 21
2131 2177 4 21
2211 21263 4 22
2212 2387 4 22
2213 273 4 22
My dataset has 406 observations and I am running Stata 14.1 for windows. I have an id variable that is specific to the first two digits, and you'll notice that 111, 112, 113, 114, and 115 add up to 3008, and that 1131, 1132, 1133, 1141, 1142, 1151, and 1152 add up to 3005. Therefore I want to keep the three digit id observations for the 11 level of specification because the three digit level accounts for the greatest amount (3,008 at the three digit level compared to 3005 at the four digit level and 3006 at the two digit level.
Does anyone have any idea what my code should be to generate a check variable and then keep only the specific id observations that account for the greatest amount for each unique first number?
My dataset looks something like this:
id amt length firstnum
11 3006 2 11
21 5725 2 21
22 23919 2 22
111 0 3 11
112 0 3 11
113 1603 3 11
114 136 3 11
115 1269 3 11
211 951 3 21
212 2596 3 21
213 2177 3 21
221 23919 3 22
1131 51 4 11
1132 68 4 11
1133 1483 4 11
1141 42 4 11
1142 94 4 11
1151 558 4 11
1152 623 4 11
1153 86 4 11
2111 951 4 21
2121 15 4 21
2122 1343 4 21
2123 1237 4 21
2131 2177 4 21
2211 21263 4 22
2212 2387 4 22
2213 273 4 22
Comment