*! Version 1.0 20221107

Title

countyfips -- Stata program for merging U.S. county identifiers

Syntax

countyfips [, options] nogenerate

Description

countyfips is a simple Stata crosswalk program for adding various county-level
identifiers (name, FIPS, Census codes) that may be missing from your dataset.
The purpose of this program is to facilitate merging datasets that do not share
a common identifier.

countyfips is compatible with Stata version 12.1+. It may be compatible
with previous versions, but it has not been tested in those environments.

Options

One of the following arguments is required.

name(string) Use this option to merge using county name string. (string)
specifies the variable name in the master dataset. statefips or statecode is required
for this option.

statefips(string) Use this option to merge using the two-digit state FIPS code.
(string) specifies the variable name in the master dataset. countyfips is required
for this option.

countyfips(string) Use this option to merge using the three-digit county FIPS code.
(string) specifies the variable name in the master dataset. statefips is required
for this option.

fips(string) Use this option to merge using the five-digit county-level FIPS code.
(string) specifies the variable name in the master dataset.

statecode(string) Use this option to merge using the two-digit state-level Census code.
(string) specifies the variable name in the master dataset. countycode is required
for this option.

countycode(string) Use this option to merge using the three-digit county-level Census code.
(string) specifies the variable name in the master dataset. statecode is required
for this option.

Optional

nogenerate Use this option if you do not want to mark merge results with
the new variable, _merge. This option will also limit your dataset to matched
observations and unmatched master observations.

Examples

countyfips offers three methods of merging using either county names,
five-digit county FIPS codes, or the combination of two-digit state FIPS and three-digit
county FIPS codes.

Merging with name, where county is the name of variable containing county name as a string requires either statefips or statecode to be specified

. countyfips, name(county) statefips(stfips)

or

. countyfips, name(county) statecode(stcode)

Merging with fips, where countyfips is the name of the variable containing the 5-digit FIPS code

. countyfips, fips(countyfips)

Merging with statefips and countyfips, where stfips and cofips are the names of the variables containing the 2-digit state FIPS and 3-digit county FIPS codes

. countyfips, statefips(stfips) countyfips(cofips)

Merging with statecode and countycode, where stcode and cocode are the names of the variables containing the U.S. Census Bureau Census of Governments state and county codes

. countyfips, statecode(stcode) countcode(cocode)

By default, countyfips will generate a new variable, _merge, to indicate
the merged results. If you do not want to create this variable, specify nogenerate.
This will keep matched observations and unmatched master observations.

. countyfips, fips(county) nogenerate

Data Examples:

Merging with 5-digit FIPS codes

webuse texas_ue.dta

countyfips, fips(fips)

Merging with 2-digit state FIPS and 3-digit county FIPS codes

webuse homicide1990.dta

countyfips, countyfips(cfips) statefips(sfips)

Common Issues

The first time you run countyfips it creates a data file that lives in your personal ado directory
(by default, Windows: "c:\ado\"; macOS: "~/Documents/Stata/ado"). In versions of OSX 10.7 and newer,
this folder may be protected, lacking sufficient read-write permissions for countyfips to
create the necessary file. If you are receiving an error, please check your permissions.
See here for more information.

Limitations

Using countyfips with the name option requires specific
formatting of the name variable. County names must not include
"county" after the name. County names beginning with "Saint" such as
Saint Louis must be abbreviated to "St" (no period). County names with
apostrophes are included ("PRINCE GEORGE'S" County, MD)

FIPS codes are available for U.S counties, county equivalents, and territories.
Census codes are only available for counties or county equivalents (such as independent cities).

FIPS codes for Virginia independent cities as well as merged county and
independent cities (as is the practice for some areas in BEA data) are
included. Using countyfips with the name option will require extremely
particular formatting. Additionally, only the statefips option will work
when merging with name.

countyfips uses the more recent FIPS code for Miami-Dade county
(12086) rather than the FIPS code for Dade county (12025). The Census state
(10) and county (13) codes remain unchanged.

Author

Christopher B. Goodman, School of Public and Global Affairs,
Northern Illinois University

cgoodman@niu.edu

Also see

statastates (if installed)