Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
# statastates

statastates is a simple Stata module for adding U.S. state identifiers (abbreviation, FIPS code, and name) that may be missing from your dataset.
statastates is a simple Stata module for adding U.S. state identifiers (abbreviation, FIPS code, ICPSR code, and name) that may be missing from your dataset. My contribution to William Schpero's code was to add ICPSR functionality.

### Prerequisites

**Stata**: statastates should be compatible with Stata v12.1+. While it may be compatible with earlier versions, it has not been tested in those environments.

### Installation Options

**SSC Archive**: Run the code below via the Stata command line.

ssc install statastates, replace

**Github (for Stata v13.1+)**: Run the code below via the Stata command line.

net install statastates, from(https://raw.github.com/wschpero/statastates/master/) replace
net install statastates, from(https://raw.github.com/dmockus2/statastates/master/) replace

**Github (for Stata v12.1+)**: [Download](https://github.com/wschpero/statastates/archive/master.zip) the files above. Run the code below via the Stata command line, inserting the directory where you saved the files.
**Github (for Stata v12.1+)**: [Download](https://github.com/dmockus2/statastates/archive/master.zip) the files above. Run the code below via the Stata command line, inserting the directory where you saved the files.

net install statastates, from(<LOCAL PATH TO FILES>) replace

### Using statastates

statastates is pretty easy to use. Just run the command and include the relevant option, which is contingent on whether you would like to merge using the two-letter state abbreviation, FIPS code, or name.
statastates is pretty easy to use. Just run the command and include the relevant option, which is contingent on whether you would like to merge using the two-letter state abbreviation, FIPS code, name, or ICPSR code.

For example, if you have the state abbreviations in your dataset under the variable "state" and want to merge state FIPS codes and names using that variable, enter the following:

Expand All @@ -32,14 +28,18 @@ If you have the state FIPS codes in your dataset under the variable "state" and

statastates, fips(state)

Lastly, if you have the state names in your dataset under the variable "state" and want to merge state abbreviations and FIPS codes using that variable, enter the following:
If you have the state names in your dataset under the variable "state" and want to merge state abbreviations and FIPS codes using that variable, enter the following:

statastates, name(state)

Lastly, if you have the state ICPSR codes in your dataset under the variable "state" and want to merge state abbreviations and names using that variable, enter the following:

statastates, icpsr(state)

By default, statastates will generate a new variable, `_merge`, to mark merge results. If you do not want to create this variable (and simply keep matched observations and unmatched master observations), specify the option `nogenerate`.

statastates, name(state) nogenerate

### Bug Reports

Please [let me know](https://github.com/wschpero/statastates/issues) if you encounter any issues. Enjoy!
Please [let me know](https://github.com/dmockus2/statastates/issues) if you encounter any issues. Enjoy!
6 changes: 3 additions & 3 deletions stata.toc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ d statastates: Stata module for merging U.S. state identifiers
d
d Requires: Stata version 12.1+
d
d Distribution-Date: 122217
d Distribution-Date: 050918
d
d Authors: William L. Schpero
d Contact: william.schpero@yale.edu
d Authors: William L. Schpero (Original) and Domininkas Mockus
d Contact: dmockus2@illinois.edu
d
d
p statastates Stata module for merging U.S. state identifiers
47 changes: 38 additions & 9 deletions statastates.ado
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
/*
statastates: Stata module for merging U.S. state identifiers
Author: William L. Schpero
Contact: william.schpero@yale.edu
Date: 122217
Version: 1.3
Authors: Domininkas Mockus (heavily based on the code by William Schpero)
Contact: dmockus2@illinois.edu
Date: 04062019
Version: 3.0
*/

capture program drop statastates
program define statastates

version 12.1
syntax, [Abbreviation(string) Fips(string) Name(string) NOGENerate]
syntax, [Abbreviation(string) Fips(string) Name(string) ICPsr(string) MORTality(string) NOGENerate]

cap quietly findfile statastates.dta, path("`c(sysdir_personal)'statastates_data/")

if _rc==601 {
preserve
clear
quietly findfile statastates_data.ado
cap insheet using "`r(fn)'", tab

cap insheet using "`r(fn)'", tab
cap mkdir "`c(sysdir_personal)'"
cap mkdir "`c(sysdir_personal)'statastates_data"
cap save "`c(sysdir_personal)'statastates_data/statastates.dta"
cap save "`c(sysdir_personal)'statastates_data/statastates.dta", replace
restore
}

if "`nogenerate'" != "" {

if "`abbreviation'" != "" {
local abbrev "`abbreviation'"
local abbrev "`abbreviation'"
rename `abbrev' state_abbrev
replace state_abbrev=upper(state_abbrev)
merge m:1 state_abbrev using "`c(sysdir_personal)'statastates_data/statastates.dta", nogen keep(match master)
Expand All @@ -49,6 +50,20 @@ program define statastates
merge m:1 state_name using "`c(sysdir_personal)'statastates_data/statastates.dta", nogen keep(match master)
rename state_name `name'
}

else if "`icpsr'" != "" {
local icpsr "`icpsr'"
rename `icpsr' state_icpsr
merge m:1 state_icpsr using "`c(sysdir_personal)'statastates_data/statastates.dta", nogen keep(match master)
rename state_icpsr `icpsr'
}

else if "`mortality'" != "" {
local mortality "`mortality'"
rename `mortality' state_mort
merge m:1 state_mort using "`c(sysdir_personal)'statastates_data/statastates.dta", nogen keep(match master)
rename state_mort `mortality'
}

}

Expand All @@ -74,5 +89,19 @@ program define statastates
merge m:1 state_name using "`c(sysdir_personal)'statastates_data/statastates.dta"
rename state_name `name'
}

else if "`icpsr'" != "" {
local icpsr "`icpsr'"
rename `icpsr' state_icpsr
merge m:1 state_icpsr using "`c(sysdir_personal)'statastates_data/statastates.dta"
rename state_icpsr `icpsr'
}

else if "`mortality'" != "" {
local mortality "`mortality'"
rename `mortality' state_mort
merge m:1 state_mort using "`c(sysdir_personal)'statastates_data/statastates.dta"
rename state_mort `mortality'
}

end
6 changes: 3 additions & 3 deletions statastates.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ d statastates: Stata module for merging U.S. state identifiers
d
d Requires: Stata version 12.1+
d
d Distribution-Date: 122217
d Distribution-Date: 050918
d
d Authors: William L. Schpero
d Contact: william.schpero@yale.edu
d Authors: William L. Schpero (Original) and Domininkas Mockus
d Contact: dmockus2@illinois.edu
d
f statastates.ado
f statastates_data.ado
Expand Down
22 changes: 16 additions & 6 deletions statastates.sthlp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{smcl}
{* 22december2017}
{* 06apr2019}
{title: Title}

{p 4 8}{cmd:statastates} - Stata module for merging U.S. state identifiers

{title: Syntax}

{p 4 8}{cmd:statastates}, [{cmdab:a:bbreviation}({it:string}) {cmdab:f:ips}({it:string}) {cmdab:n:ame}({it:string})] {cmdab:nogen:erate}
{p 4 8}{cmd:statastates}, [{cmdab:a:bbreviation}({it:string}) {cmdab:f:ips}({it:string}) {cmdab:n:ame}({it:string}) {cmdab:icp:sr}({it:string})] {cmdab:nogen:erate}

{title: Description}

{p 4 8}{cmd:statastates} is a simple Stata module for adding U.S. state identifiers (abbreviation, FIPS code, and name) that may be missing from your dataset.
{p 4 8}{cmd:statastates} is a simple Stata module for adding U.S. state identifiers (abbreviation, FIPS code, ICPSR code, and name) that may be missing from your dataset.

{p 4 8}{cmd:statastates} is compatible with Stata v12.1+. While it may be compatible with earlier versions, it has not been tested in those environments.

Expand All @@ -24,6 +24,8 @@

{p 4 8}{cmdab:n:ame}({it:string}) Use this option if you would like to merge using the full state name and to specify the relevant variable name in your master dataset.

{p 4 8}{cmdab:icp:sr}({it:string}) Use this option if you would like to merge using the one or two-digit state ICPSR code and to specify the relevant variable name in your master dataset.

{p 4 8}{bf:Optional:}

{p 4 8}{cmdab:nogen:erate} Use this option if you do not want to mark merge results with the new variable {cmdab:_merge}. This option will also limit your dataset to matched observations and unmatched master observations.
Expand All @@ -40,18 +42,26 @@

{p 4 8}{cmd:statastates}, {cmdab:f:ips}({it:state})

{p 4 8}Lastly, if you have the state names in your dataset under the variable "state" and want to merge state abbreviations and FIPS codes using that variable, enter the following:
{p 4 8}If you have the state names in your dataset under the variable "state" and want to merge state abbreviations and FIPS codes using that variable, enter the following:

{p 4 8}{cmd:statastates}, {cmdab:n:ame}({it:state})

{p 4 8}If you have the state ICPSR codes in your dataset under the variable "state" and want to merge state abbreviations and names using that variable, enter the following:

{p 4 8}{cmd:statastates}, {cmdab:icp:sr}({it:state})

{p 4 8}Lastly, if you have the state codes from the CDC vital statistics in your dataset under the variable "state" and want to merge state abbreviations and names using that variable, enter the following:

{p 4 8}{cmd:statastates}, {cmdab:mort:ality}({it:state})

{p 4 8}By default, statastates will generate a new variable, {cmdab:_merge}, to mark merge results. If you do not want to create this variable, specify {cmdab:nogen:erate}. This will keep matched observations and unmatched master observations.

{p 4 8}{cmd:statastates}, {cmdab:n:ame}({it:state}) {cmdab:nogen:erate}

{title: Author}

{p 4 4}William L. Schpero
{p 4 4}Domininkas Mockus (heavily based on the code by William Schpero)

{title: Contact}

{p 4 4}{browse "mailto:william.schpero@yale.edu":william.schpero@yale.edu}{break}
{p 4 4}{browse "mailto:dmockus2@illinois.edu":dmockus2@illinois.edu}{break}
104 changes: 52 additions & 52 deletions statastates_data.ado
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
state_abbrev state_name state_fips
AK ALASKA 2
AL ALABAMA 1
AR ARKANSAS 5
AZ ARIZONA 4
CA CALIFORNIA 6
CO COLORADO 8
CT CONNECTICUT 9
DC DISTRICT OF COLUMBIA 11
DE DELAWARE 10
FL FLORIDA 12
GA GEORGIA 13
HI HAWAII 15
IA IOWA 19
ID IDAHO 16
IL ILLINOIS 17
IN INDIANA 18
KS KANSAS 20
KY KENTUCKY 21
LA LOUISIANA 22
MA MASSACHUSETTS 25
MD MARYLAND 24
ME MAINE 23
MI MICHIGAN 26
MN MINNESOTA 27
MO MISSOURI 29
MS MISSISSIPPI 28
MT MONTANA 30
NC NORTH CAROLINA 37
ND NORTH DAKOTA 38
NE NEBRASKA 31
NH NEW HAMPSHIRE 33
NJ NEW JERSEY 34
NM NEW MEXICO 35
NV NEVADA 32
NY NEW YORK 36
OH OHIO 39
OK OKLAHOMA 40
OR OREGON 41
PA PENNSYLVANIA 42
RI RHODE ISLAND 44
SC SOUTH CAROLINA 45
SD SOUTH DAKOTA 46
TN TENNESSEE 47
TX TEXAS 48
UT UTAH 49
VA VIRGINIA 51
VT VERMONT 50
WA WASHINGTON 53
WI WISCONSIN 55
WV WEST VIRGINIA 54
WY WYOMING 56
state_abbrev state_name state_fips state_icpsr state_mort
AL ALABAMA 1 41 1
AK ALASKA 2 81 2
AZ ARIZONA 4 61 3
AR ARKANSAS 5 42 4
CA CALIFORNIA 6 71 5
CO COLORADO 8 62 6
CT CONNECTICUT 9 1 7
DE DELAWARE 10 11 8
DC DISTRICT OF COLUMBIA 11 98 9
FL FLORIDA 12 43 10
GA GEORGIA 13 44 11
HI HAWAII 15 82 12
ID IDAHO 16 63 13
IL ILLINOIS 17 21 14
IN INDIANA 18 22 15
IA IOWA 19 31 16
KS KANSAS 20 32 17
KY KENTUCKY 21 51 18
LA LOUISIANA 22 45 19
ME MAINE 23 2 20
MD MARYLAND 24 52 21
MA MASSACHUSETTS 25 3 22
MI MICHIGAN 26 23 23
MN MINNESOTA 27 33 24
MS MISSISSIPPI 28 46 25
MO MISSOURI 29 34 26
MT MONTANA 30 64 27
NE NEBRASKA 31 35 28
NV NEVADA 32 65 29
NH NEW HAMPSHIRE 33 4 30
NJ NEW JERSEY 34 12 31
NM NEW MEXICO 35 66 32
NY NEW YORK 36 13 33
NC NORTH CAROLINA 37 47 34
ND NORTH DAKOTA 38 36 35
OH OHIO 39 24 36
OK OKLAHOMA 40 53 37
OR OREGON 41 72 38
PA PENNSYLVANIA 42 14 39
RI RHODE ISLAND 44 5 40
SC SOUTH CAROLINA 45 48 41
SD SOUTH DAKOTA 46 37 42
TN TENNESSEE 47 54 43
TX TEXAS 48 49 44
UT UTAH 49 67 45
VT VERMONT 50 6 46
VA VIRGINIA 51 40 47
WA WASHINGTON 53 73 48
WV WEST VIRGINIA 54 56 49
WI WISCONSIN 55 25 50
WY WYOMING 56 68 51