Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: ZIP to State or ZIP to FIPS?


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: ZIP to State or ZIP to FIPS?
Date   Sat, 17 Dec 2005 10:58:36 -0500

Stata doesn't have them as functions, but a simple merge will work. You can get a U.S. zip code to state fips dataset into Stata like this (you will likely need to re-combine the first two lines into one):

infix str5 zip 6-10 str2 st_fips 16-17 using www.oseda.missouri.edu/mscdc/sasfmats/Szipcods.sas

drop if real(zip)==.
sort zip
save zip2stfips

This data is from 1991 zip codes (and the file is actually a sas formats file), so you may want to use a more recent listing. The source file has several more fields (including counties and place names). You will find that zip codes are a poor geographic entity. They change over time and there are even a few zip codes that span more than one state. You may need to deal with that in this dataset if you want clean merges. For example, a semi-random approach would be:

bysort zip (state): keep if _n==1
save, replace

Once you have mapped the zips to fips, then you can:

use mydata
sort zip
merge zip using zip2stfips, nokeep
tab _merge

You may find some _merge==1 cases, indicating zip codes newer than the data source. However, if you just want state fips, you could fill in the missing values from the prior zip code in the file and most likely be 100% accurate:

bysort zip: replace st_fips=st_fips[_n-1] if st_fips==.

However, you might be better off using a datasource that relates zip code ranges to states. This approach would have the advantage of automatically placing new zip codes into the states of surrounding zip codes, which will tend to be correct.

Michael Blasnik
[email protected]


----- Original Message ----- From: "David Jaeger" <[email protected]>
To: <[email protected]>
Sent: Friday, December 16, 2005 10:05 PM
Subject: st: ZIP to State or ZIP to FIPS?



Anyone know if there is a State equivalent to ZIPSTATE() or ZIPFIPS()
functions in
SAS that will convert a zipcode to the state abbreviation or FIPS
code, respectively?

Thanks!
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index