I have a two datasets both of which have a variable denoting state/county fips codes. I need to "I think" either merge or append data from a second dataset to my main data. I've attached a snippet of the main dataset below.
----------------------- copy starting from the next line -----------------------
The second dataset has two variables I need Risk Rating and Risk Score to be added to this data matching on the STCOFIPS to FIPS variable from the master. See the snippet below.
I believe the correct code would be something like
to rename the master dataset variable to the same name, then use
to bring in the two variables I need into the master.
Is this correct or should I be appending the data instead? I've read the help file but I always get confused with merge vs. append.
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str28 countyname int year str3 stateabbr long fips double empgfunds "Acadia" 2014 "LA" 22001 32365 "Acadia" 2015 "LA" 22001 29198 "Acadia" 2016 "LA" 22001 29098 "Acadia" 2017 "LA" 22001 29720.94 "Acadia" 2018 "LA" 22001 29651.59 "Acadia" 2019 "LA" 22001 29521.63 "Acadia" 2020 "LA" 22001 29821.68 "Accomack" 2014 "VA" 51001 7500 "Accomack" 2015 "VA" 51001 7500 "Accomack" 2016 "VA" 51001 7500 "Accomack" 2017 "VA" 51001 7500 "Accomack" 2018 "VA" 51001 7500 "Accomack" 2019 "VA" 51001 7500 "Accomack" 2020 "VA" 51001 7500 "Ada" 2014 "ID" 16001 259958.99 "Ada" 2015 "ID" 16001 252399.45 "Ada" 2016 "ID" 16001 260049.12 "Ada" 2017 "ID" 16001 257601 "Ada" 2018 "ID" 16001 259547.5 "Ada" 2019 "ID" 16001 269664 "Ada" 2020 "ID" 16001 299311.41 "Adams" 2014 "CO" 8001 135147 "Adams" 2015 "CO" 8001 100000 "Adams" 2016 "CO" 8001 0 "Adams" 2017 "CO" 8001 77000 "Adams" 2018 "CO" 8001 77000 "Adams" 2019 "CO" 8001 77000 "Adams" 2020 "CO" 8001 77000 "Adams" 2014 "ID" 16003 4221.1 "Adams" 2015 "ID" 16003 5726.52 "Adams" 2016 "ID" 16003 0 "Adams" 2017 "ID" 16003 1529.9 "Adams" 2018 "ID" 16003 9510 "Adams" 2019 "ID" 16003 9955 "Adams" 2020 "ID" 16003 11058.76 "Adams" 2014 "IL" 17001 28571.31 "Adams" 2015 "IL" 17001 27869.37 "Adams" 2016 "IL" 17001 34440.22 "Adams" 2017 "IL" 17001 32741.75 "Adams" 2018 "IL" 17001 34476.22 "Adams" 2019 "IL" 17001 36777.78 "Adams" 2020 "IL" 17001 33503.01 "Adams" 2014 "IN" 18001 8485.29 "Adams" 2015 "IN" 18001 0 "Adams" 2016 "IN" 18001 27760 "Adams" 2017 "IN" 18001 6968.57 "Adams" 2018 "IN" 18001 91923.98000000001 "Adams" 2019 "IN" 18001 35264.06 "Adams" 2020 "IN" 18001 30000 "Adams" 2014 "MS" 28001 31055 end
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str21 COUNTY double RISK_SCORE str19 RISK_RATNG str4 STATEABBRV "Johnson" 9.281418624 "Relatively Low" "KY" "Kenton" 10.44905673 "Relatively Low" "KY" "Knott" 10.06839548 "Relatively Low" "KY" "Knox" 11.85824507 "Relatively Low" "KY" "Larue" 4.610899676 "Very Low" "KY" "Laurel" 12.2632724 "Relatively Low" "KY" "Lawrence" 6.767260626 "Very Low" "KY" "Lee" 4.937158257 "Very Low" "KY" "Leslie" 7.782817821 "Very Low" "KY" "Letcher" 9.271908629 "Relatively Low" "KY" "Lewis" 8.90908052 "Relatively Low" "KY" "Lincoln" 7.242164057 "Very Low" "KY" "Livingston" 9.999168796 "Relatively Low" "KY" "Lyon" 6.622276403 "Very Low" "KY" "McCracken" 19.12364162 "Relatively Moderate" "KY" "McCreary" 6.122567653 "Very Low" "KY" "McLean" 7.142575815 "Very Low" "KY" "Madison" 10.82923089 "Relatively Low" "KY" "Logan" 9.500956351 "Relatively Low" "KY" "Magoffin" 7.70513816 "Very Low" "KY" "Marion" 6.039854946 "Very Low" "KY" "Marshall" 11.23343249 "Relatively Low" "KY" "Martin" 6.381700555 "Very Low" "KY" "Mason" 7.529803222 "Very Low" "KY" "Meade" 6.093386636 "Very Low" "KY" "Menifee" 8.299519073 "Relatively Low" "KY" "Mercer" 7.722162526 "Very Low" "KY" "Metcalfe" 5.590253834 "Very Low" "KY" "Monroe" 6.881790428 "Very Low" "KY" "Montgomery" 6.86183341 "Very Low" "KY" "Morgan" 5.66691992 "Very Low" "KY" "Muhlenberg" 9.414436873 "Relatively Low" "KY" "Nelson" 8.085131815 "Very Low" "KY" "Nicholas" 5.891145218 "Very Low" "KY" "Ohio" 9.307983344 "Relatively Low" "KY" "Oldham" 2.109627275 "Very Low" "KY" "Owen" 6.836766087 "Very Low" "KY" "Owsley" 7.583154061 "Very Low" "KY" "Pendleton" 7.446827729 "Very Low" "KY" "Perry" 10.10004836 "Relatively Low" "KY" "Pike" 12.62172927 "Relatively Low" "KY" "Powell" 9.581312986 "Relatively Low" "KY" "Pulaski" 12.00379862 "Relatively Low" "KY" "Robertson" 4.197439657 "Very Low" "KY" "Rockcastle" 7.058219568 "Very Low" "KY" "Rowan" 8.083623212 "Very Low" "KY" "Russell" 8.555008101 "Relatively Low" "KY" "Scott" 5.94170199 "Very Low" "KY" "Shelby" 9.22171892 "Relatively Low" "KY" "Simpson" 8.437796527 "Relatively Low" "KY" end
I believe the correct code would be something like
Code:
rename fips STCOFIPS
Code:
merge 1:1 STCOPFIPS RISK_SCORE RISK_RATING using NRI_TABLE_COUNTY.csv
Is this correct or should I be appending the data instead? I've read the help file but I always get confused with merge vs. append.
Comment