I am trying to expand a dataset that looks like this:
Dataset A
contract_id | region_id | county_n |
1 | 1 | 5 |
2 | 1 | 5 |
3 | 2 | 4 |
4 | 2 | 4 |
5 | 3 | 3 |
6 | 3 | 3 |
Dataset B
region_id | county_id |
1 | 11 |
1 | 12 |
1 | 13 |
1 | 14 |
1 | 15 |
2 | 22 |
2 | 23 |
2 | 24 |
2 | 25 |
2 | 26 |
3 | 35 |
3 | 36 |
3 | 37 |
3 | 38 |
3 | 39 |
Code:
levelsof county_n, local(levels) foreach n of local levels { expand `n' if county_n == `n' merge m:1 region_id using data_B,replace update drop if _merge==2 drop _merge }
Any advice would be appreciated!
0 Response to Expanding Dataset
Post a Comment