Stata. How to compare the values ​​in a 1: m relationship?

I have two datasets. First:

countyGroup income other_data_ 1 20990 … 2 25622 … 3 24289 … 4 27391 … 5 23326 … 6 19261 … 7 15197 … 8 11132 … 

Second:

 countyGroup state county other_data 1 IL 123 … 1 IL 123 … 2 MI 365 … 1 IL 123 … 3 AK 65 … 4 IL 546 … 5 MI 689 … 6 AK 32 … 

The countyGroup variable uniquely identifies both state and county . The second dataset contains countyGroup , state and county . The first data set contains only countyGroup . I need to create two variables ( state and county ) in the first data set.

I tried matching values ​​with merge :

 use dataset1 merge 1:m countyGroup using dataset2, keepusing(state state cntyfp) update replace 

The result that I get is duplicate rows ... I tried 1:1 , it did not work ... I can always drop duplicate rows, but I wanted to merge them correctly from the very beginning.

+1
source share
1 answer

We need to know about duplicate lines (the term Stata is β€œobservations”). If they are the same for all variables, there is no additional information, and it is the cleanest and easiest to use duplicates drop to get rid of them before merge .

duplicates is a generic duplicate management tool.

If there is other information about other variables, tell us more about what it is and about your goals here.

(LATER) With your datasets that you posted

  merge 1:m countyGroup using dataset2 

seems to be working fine.

+3
source

Source: https://habr.com/ru/post/1485261/


All Articles