I am working with a dataset in R(county_data) and I have on a consumption column for every county in every state of the US. I tried to merge it with a dataset with fips code(I believe it comes with tidycensus package) but I noticed that there are multiple fips code for a single county. Why is that?
I was expecting to see just a single FIPS code so I could merge it with my county data and plot it. I tried merging the county_data to the fips_data, and not the same consumption has been duplicated for the multiple versions of same county that are present in the fips dataset.
If there is a substantive change to a county (like a name change, or a notable boundary change) Census will change the FIPS code. tidycensus includes all version of that over time so that users can request counties by name across the different years.
I don't typically recommend using
fips_codesfor that purpose, it's an internal dataset that we use to translate county names to FIPS codes for users.If you want counties with FIPS codes for a given year, fetch that data with the tigris package (e.g.
counties(year = 2022)) and pull out the FIPS code (typically calledGEOID) and the name.It's tough to say without your specific example, but I would also be very careful if you are merging on county names which it sounds like you are doing given different spellings (e.g. Saint Louis vs. St. Louis).