Skip to content

Commit 5163a4d

Browse files
author
Chris Goodman
committed
intitial commit
1 parent 82af86c commit 5163a4d

8 files changed

+2193
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

Diff for: LICENSE renamed to LICENSE.md

File renamed without changes.

Diff for: README.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# msacrosswalk
2+
`msacrosswalk` is a simple Stata crosswalk program for adding 2017 vintage CBSA/CSA codes, CBSA/CSA names, metropolitan/micropolitan, and central/outlying indicators that may be missing from your dataset.
3+
4+
## Prerequisites
5+
6+
**Stata:** `msacrosswalk` is compatible with Stata version 12.1+. It may be compatible with previous versions, but it has not been tested in those environments.
7+
8+
## Installation
9+
10+
**Github (for Stata v13.1+):** Run the following via the Stata command line.
11+
```Stata
12+
net install msacrosswalk, from(https://raw.github.com/cbgoodman/msacrosswalk/master/) replace
13+
```
14+
15+
**Github (for Stata v12.1+):** Download the [zipped file](https://github.com/cbgoodman/msacrosswalk/archive/master.zip) of this repository. Unzip on your local computer. Run the following code via the Stata command line replacing <local source> with the location of the unzipped repository on your computer.
16+
```Stata
17+
net install msacrosswalk, from(<local source>) replace
18+
```
19+
20+
## Using msacrosswalk
21+
`msacrosswalk` offers three methods of merging using either five-digit county FIPS codes, the combination of two-digit state FIPS and three-digit county FIPS codes, or the combination of two-digit state Census codes and three-digit county Census codes.
22+
23+
Merging with `fips`
24+
```Stata
25+
. msacrosswalk, fips(county)
26+
```
27+
28+
Merging with `statefips` and `countyfips`
29+
```Stata
30+
. msacrosswalk, statefips(stfips) countyfips(cofips)
31+
```
32+
33+
Merging with `statecode` and `countycode`
34+
```Stata
35+
. msacrosswalk, statecode(stcode) countycode(cocode)
36+
```
37+
38+
By default, `msacrosswalk` will generate a new variable, `_merge`, to indicate the merged results. If you do not want to create this variable, specify `nogenerate`.
39+
This will keep matched observations and unmatched master observations.
40+
```Stata
41+
. msacrosswalk, fips(county) nogenerate
42+
```
43+
44+
## Limitations
45+
* 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).
46+
* `msacrosswalk` 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.
47+
48+
## Next steps
49+
* Add other recent CBSA/CSA definitions
50+
* Add historical delineation files
51+
52+
## Bugs
53+
Please report any bugs [here](https://github.com/cbgoodman/msacrosswalk/issues).

Diff for: msacrosswalk.ado

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
msacrosswalk: Stata program for merging U.S. MSA/CBSA identifiers
3+
Author: Christopher B. Goodman
4+
5+
Date: NA
6+
Version: 0.9.0
7+
*/
8+
9+
capture program drop msacrosswalk
10+
program define msacrosswalk
11+
12+
version 12.1
13+
syntax, [Statefips(string) Countyfips(string) Fips(string) Statecode(string) Countycode(string) NOGENerate]
14+
15+
cap quietly findfile msacrosswalk.dta, path("`c(sysdir_personal)'msacrosswalk_data/")
16+
17+
if _rc==601 {
18+
preserve
19+
clear
20+
quietly findfile msacrosswalk_data.ado
21+
cap insheet using "`r(fn)'", tab
22+
label var fips "5-digit FIPS Code"
23+
label var state_fips "State FIPS Code"
24+
label var county_fips "County FIPS Code"
25+
label var state_code "State Census Code"
26+
label var county_code "County Census Code"
27+
label var cbsa_code "CBSA Code"
28+
label var cbsa_name "CBSA Name"
29+
label var csa_code "CSA Code"
30+
label var csa_name "CSA Name"
31+
label var type "1=Metropolitan, 2=Micropolitan"
32+
label var cen "1=Central, 2=Outlying"
33+
label define metro 1 "Metropolitan Statistical Area" 2 "Micropolitan Statistical Area"
34+
label define central 1 "Central" 2 "Outlying"
35+
label values type metro
36+
label values cen central
37+
cap mkdir "`c(sysdir_personal)'"
38+
cap mkdir "`c(sysdir_personal)'msacrosswalk_data"
39+
cap save "`c(sysdir_personal)'msacrosswalk_data/msacrosswalk.dta"
40+
restore
41+
}
42+
43+
if "`nogenerate'" != "" {
44+
45+
if "`statefips'" != "" & "`countyfips'" != "" {
46+
local statefips "`statefips'"
47+
local countyfips "`countyfips'"
48+
rename `countyfips' county_fips
49+
rename `statefips' state_fips
50+
merge m:1 state_fips county_fips using "`c(sysdir_personal)'msacrosswalk_data/msacrosswalk.dta", nogen keep(match master)
51+
drop fips state_code county_code
52+
rename state_fips `statefips'
53+
rename county_fips `countyfips'
54+
}
55+
56+
else if "`fips'" != "" {
57+
local fips "`fips'"
58+
rename `fips' fips
59+
merge m:1 fips using "`c(sysdir_personal)'msacrosswalk_data/msacrosswalk.dta", nogen keep(match master)
60+
drop state_code county_code state_fips county_fips
61+
rename fips `fips'
62+
}
63+
64+
else if "`statecode'" != "" & "`countycode'" != "" {
65+
preserve
66+
clear
67+
cap quietly use "`c(sysdir_personal)'msacrosswalk_data/msacrosswalk.dta"
68+
quietly drop if county_code==.
69+
tempfile msacrosswalk_datatemp
70+
cap save `msacrosswalk_datatemp'
71+
restore
72+
local statecode "`statecode'"
73+
local countycode "`countycode'"
74+
rename `statecode' state_code
75+
rename `countycode' county_code
76+
merge m:1 state_code county_code using `msacrosswalk_datatemp', nogen keep(match master)
77+
drop state_fips county_fips fips
78+
rename state_code `statecode'
79+
rename county_code `countycode'
80+
}
81+
82+
}
83+
84+
else if "`statefips'" != "" & "`countyfips'" != "" {
85+
local statefips "`statefips'"
86+
local countyfips "`countyfips'"
87+
rename `countyfips' county_fips
88+
rename `statefips' state_fips
89+
merge m:1 state_fips county_fips using "`c(sysdir_personal)'msacrosswalk_data/msacrosswalk.dta"
90+
drop fips state_code county_code
91+
rename state_fips `statefips'
92+
rename county_fips `countyfips'
93+
}
94+
95+
else if "`fips'" != "" {
96+
local fips "`fips'"
97+
rename `fips' fips
98+
merge m:1 fips using "`c(sysdir_personal)'msacrosswalk_data/msacrosswalk.dta"
99+
drop state_code county_code state_fips county_fips
100+
rename fips `fips'
101+
}
102+
103+
else if "`statecode'" != "" & "`countycode'" != "" {
104+
preserve
105+
clear
106+
cap quietly use "`c(sysdir_personal)'msacrosswalk_data/msacrosswalk.dta"
107+
quietly drop if county_code==.
108+
tempfile msacrosswalk_datatemp
109+
cap save `msacrosswalk_datatemp'
110+
restore
111+
local statecode "`statecode'"
112+
local countycode "`countycode'"
113+
rename `statecode' state_code
114+
rename `countycode' county_code
115+
merge m:1 state_code county_code using `msacrosswalk_datatemp'
116+
drop state_fips county_fips fips
117+
rename state_code `statecode'
118+
rename county_code `countycode'
119+
}
120+
121+
end

Diff for: msacrosswalk.pkg

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
v 3
2+
d msacrosswalk. Stata program for merging U.S. MSA/CBSA identifiers
3+
d {bf:Christopher B. Goodman, School of Public Administration, University of Nebraska at Omaha}
4+
d
5+
d After installation, see help {bf:msacrosswalk}.
6+
d
7+
d Distribution-Date: 07132018
8+
d
9+
d Support: email [email protected]
10+
d
11+
f msacrosswalk.ado
12+
f msacrosswalk.sthlp
13+
f msacrosswalk_data.ado

Diff for: msacrosswalk.sthlp

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{smcl}
2+
{* *! Version 0.9.0 07132018}
3+
{title:Title}
4+
5+
{p 4 8}{cmd:msacrosswalk} {hline 2} Stata program for merging U.S. MSA/CBSA identifiers
6+
7+
{title:Syntax}
8+
9+
{p 8 16 2}
10+
{opt msacrosswalk} [{cmd:,} {it:options}] {opt nogen:erate}
11+
12+
{title:Description}
13+
14+
{pstd}
15+
{cmd:msacrosswalk} is a simple Stata crosswalk program for adding CBSA/CSA codes, CBSA/CSA names, metropolitan/micropolitan, and central/outlying indicators that may be missing from your dataset.
16+
17+
{pstd}
18+
{cmd:msacrosswalk} is compatible with Stata version 12.1+. It may be compatible
19+
with previous versions, but it has not been tested in those environments.
20+
21+
{title:Options}
22+
23+
One of the following {cmd:arguments} is required.
24+
25+
{phang}
26+
{opt s:tatefips(string)} Use this option to merge using the two-digit state FIPS code.
27+
(string) specifies the variable name in the master dataset. {cmd:countyfips} is required
28+
for this option.
29+
30+
{phang}
31+
{opt c:ountyfips(string)} Use this option to merge using the three-digit county FIPS code.
32+
(string) specifies the variable name in the master dataset. {cmd:statefips} is required
33+
for this option.
34+
35+
{phang}
36+
{opt f:ips(string)} Use this option to merge using the five-digit county-level FIPS code.
37+
(string) specifies the variable name in the master dataset.
38+
39+
{phang}
40+
{opt s:tatecode(string)} Use this option to merge using the two-digit state-level Census code.
41+
(string) specifies the variable name in the master dataset. {cmd:countycode} is required
42+
for this option.
43+
44+
{phang}
45+
{opt c:ountycode(string)} Use this option to merge using the three-digit county-level Census code.
46+
(string) specifies the variable name in the master dataset. {cmd:statecode} is required
47+
for this option.
48+
49+
Optional
50+
51+
{phang}
52+
{opt nogen:erate} Use this option if you do not want to mark merge results with
53+
the new variable, {cmd:_merge}. This option will also limit your dataset to matched
54+
observations and unmatched master observations.
55+
56+
{title:Examples}
57+
58+
{pstd}{cmd:msacrosswalk} offers two methods of merging using either five-digit county
59+
FIPS codes or the combination of two-digit state FIPS and three-digit
60+
county FIPS codes.{p_end}
61+
62+
{pstd}Merging with {cmd:fips}{p_end}
63+
{phang2}{cmd:. msacrosswalk, fips(}{it:county}{cmd:)}{p_end}
64+
65+
{pstd}Merging with {cmd:statefips} and {cmd:countyfips}{p_end}
66+
{phang2}{cmd:. msacrosswalk, statefips(}{it:stfips}{cmd:) countyfips(}{it:cofips}{cmd:)}{p_end}
67+
68+
{pstd}Merging with {cmd:statecode} and {cmd:countycode}{p_end}
69+
{phang2}{cmd:. msacrosswalk, statecode(}{it:stcode}{cmd:) countcode(}{it:cocode}{cmd:)}{p_end}
70+
71+
{pstd}By default, {cmd:countyfips} will generate a new variable, {cmd:_merge}, to indicate
72+
the merged results. If you do not want to create this variable, specify {cmd:nogenerate}.
73+
This will keep matched observations and unmatched master observations.{p_end}
74+
75+
{phang2}{cmd:. msacrosswalk, fips(}{it:county}{cmd:) nogenerate}{p_end}
76+
77+
{title:Limitations}
78+
{pstd}FIPS codes are available for U.S counties, county equivalents, and territories.
79+
Census codes are only available for counties or county equivalents (such as independent cities).{p_end}
80+
81+
{pstd}{cmd:msacrosswalk} uses the more recent FIPS code for Miami-Dade county
82+
(12086) rather than the FIPS code for Dade county (12025). The Census state
83+
(10) and county (13) codes remain unchanged.
84+
85+
{title:Author}
86+
87+
{pstd}Christopher B. Goodman, School of Public Administration,
88+
University of Nebraska at Omaha {p_end}
89+
{pstd}{browse "mailto:[email protected]":[email protected]}{break} {p_end}
90+
91+
{title:Also see}
92+
93+
{pstd} {help statastates} {help countyfips} (if installed)

0 commit comments

Comments
 (0)