-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathstatastates.ado
78 lines (65 loc) · 2.06 KB
/
statastates.ado
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
statastates: Stata module for merging U.S. state identifiers
Author: William L. Schpero
Contact: [email protected]
Date: 122217
Version: 1.3
*/
capture program drop statastates
program define statastates
version 12.1
syntax, [Abbreviation(string) Fips(string) Name(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 mkdir "`c(sysdir_personal)'"
cap mkdir "`c(sysdir_personal)'statastates_data"
cap save "`c(sysdir_personal)'statastates_data/statastates.dta"
restore
}
if "`nogenerate'" != "" {
if "`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)
rename state_abbrev `abbrev'
}
else if "`fips'" != "" {
local fips "`fips'"
rename `fips' state_fips
merge m:1 state_fips using "`c(sysdir_personal)'statastates_data/statastates.dta", nogen keep(match master)
rename state_fips `fips'
}
else if "`name'" != "" {
local name "`name'"
rename `name' state_name
replace state_name=upper(state_name)
merge m:1 state_name using "`c(sysdir_personal)'statastates_data/statastates.dta", nogen keep(match master)
rename state_name `name'
}
}
else if "`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"
rename state_abbrev `abbrev'
}
else if "`fips'" != "" {
local fips "`fips'"
rename `fips' state_fips
merge m:1 state_fips using "`c(sysdir_personal)'statastates_data/statastates.dta"
rename state_fips `fips'
}
else if "`name'" != "" {
local name "`name'"
rename `name' state_name
replace state_name=upper(state_name)
merge m:1 state_name using "`c(sysdir_personal)'statastates_data/statastates.dta"
rename state_name `name'
}
end