I need to convert my master data to county level. For that in my master data I have statefip and city name. In my using data I have city , statefip , county_fip and county name.
The issue arises, since plenty of city in different states have multiple county code/county name as I'm showing a part of duplicates ( from my using data ) data with same city and state but different county name /couty_fip code.
This is how my master data looks like :
dataex id city statefip if city=="Georgetown" & statefip=="PA"
----------------------- copy starting from the next line -----------------------
This is how my using data looks like
dataex city statefip county_fips county_name if city== "Georgetown" & statefip=="PA"
----------------------- copy starting from the next line -----------------------
When I'm using m:1
Whenever I'm using 1:m the following error message shows up
What direction should I go to given this particular problem ?
The issue arises, since plenty of city in different states have multiple county code/county name as I'm showing a part of duplicates ( from my using data ) data with same city and state but different county name /couty_fip code.
Code:
list city state_id county_name, sepby(city state_id) noobs +---------------------------------------+ | city state_id county_name | |---------------------------------------| | Midway FL Gadsden | | Midway FL Santa Rosa | | Midway FL Seminole | |---------------------------------------| | Woodbury NY Nassau | | Woodbury NY Orange | |---------------------------------------| | Oakwood OH Cuyahoga | | Oakwood OH Montgomery | | Oakwood OH Paulding | |---------------------------------------| | Franklin PA Cambria | | Franklin PA Venango | |---------------------------------------| | Georgetown PA Beaver | | Georgetown PA Lancaster | | Georgetown PA Luzerne | |---------------------------------------|
dataex id city statefip if city=="Georgetown" & statefip=="PA"
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str14 id str43 city str3 statefip "11311793" "Georgetown" "PA" "12054868" "Georgetown" "PA" "13761470" "Georgetown" "PA" "63145796" "Georgetown" "PA" "63058645" "Georgetown" "PA" "11415903" "Georgetown" "PA" "62891646" "Georgetown" "PA" "10933939" "Georgetown" "PA" "17385483" "Georgetown" "PA" "10925795" "Georgetown" "PA" end
dataex city statefip county_fips county_name if city== "Georgetown" & statefip=="PA"
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str35 city str2 statefip long county_fips str21 county_name "Georgetown" "PA" 42007 "Beaver" "Georgetown" "PA" 42071 "Lancaster" "Georgetown" "PA" 42079 "Luzerne" end
When I'm using m:1
Code:
merge m:1 city statefip using "using.dta", keep(master match) nogen variables city statefip do not uniquely identify observations in the using data r(459); end of do-file r(459);
Code:
merge 1:m city statefip using "using.dta", keep(master match) nogen variables city statefip do not uniquely identify observations in the master data r(459); end of do-file r(459);
Comment