-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNICUVolumeInstrument.do
198 lines (123 loc) · 4.67 KB
/
NICUVolumeInstrument.do
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
* NICU patients only volume instrument.
* See other version in VolumeInstrument.do
* This file measures the correlation between the two instruments.
* use "${birthdata}Birth2005.dta", clear
do "/Users/austinbean/Desktop/Birth2005-2012/FilePathGlobal.do"
capture quietly do "/Users/austinbean/Google Drive/Annual Surveys of Hospitals/TX Global Filepath Names.do"
foreach yr of numlist 2005(1)2012{
use "${birthdata}Birth`yr'.dta", clear
keep if b_bplace ==1
* Add Zip Code Choice Sets - closest 50 hospitals.
drop if b_mrzip < 70000 | b_mrzip > 79999
* TODO - this may not be necessary
drop if fid == .
rename b_mrzip PAT_ZIP
merge m:1 PAT_ZIP using "${birthdata}closest50hospitals.dta"
drop if _merge != 3
drop _merge
* Figure out which option chosen.
gen chosenind = .
forvalues i=1/50{
di "`i'"
replace chosenind = `i' if fidcn`i' == fid
}
* Add Outside Option
* Anyone who didn't choose one of the 50 closest.
gen fidcn51 = 0
gen faclatcn51 = 0
gen faclongcn51 = 0
gen zipfacdistancecn51 = 0
replace chosenind = 51 if chosenind == .
* Record distance to chosen facility
gen chdist = .
forvalues n = 1/51{
replace chdist = zipfacdistancecn`n' if chosenind == `n'
}
label variable chdist "distance to chosen hospital"
gen chdist2 = chdist^2
gen patid = _n
* Reshape
reshape long fidcn faclatcn faclongcn zipfacdistancecn, i(patid) j(hs)
* Record Choice
gen chosen = 0
bysort patid: replace chosen = 1 if fid == fidcn
* This records the choice as the OO
bysort patid: replace chosen = 1 if chosenind == 51 & fidcn == 0
drop faclatcn faclongcn
* Some checks - does anyone have two chosen facilities?
* And has everyone chosen a facility? (After these checks, everyone is correct.)
bysort patid: gen sm = sum(chosen)
bysort patid: egen ch1 = max(sm)
bysort patid fidcn: gen fidid = _n
drop if fidid > 1
drop sm ch1 fidid
* can also check this by doing tab chosen and comparing count of 1's to unique patid - will be equal.
gen zipfacdistancecn2 = zipfacdistancecn^2
keep patid fid fidcn PAT_ZIP chosen zipfacdistancecn zipfacdistancecn2 hs
* Add more info about these, using FID, I think.
rename fid fiddd
rename fidcn fid
gen year = `yr'
merge m:1 fid year using "${birthdata}AllHospInfo1990-2012.dta"
drop if _merge == 2
* remember: cannot drop if fid == 0!
drop if _merge ==1 & fid != 0
drop if (ObstetricCare == 0 & NeoIntensive == 0 & SoloIntermediate == 0) & fid != 0
rename fid fidcn
rename fiddd fid
* Fix variables in choice in Outside Option:
replace NeoIntensive = 0 if fidcn == 0
replace SoloIntermediate = 0 if fidcn == 0
replace ObstetricCare = 0 if fidcn == 0
replace ObstetricsLevel = 0 if fidcn == 0
replace ObstetricCare = 0 if fidcn == 0
* Fix dumb errors in Obstetrics Level
replace ObstetricsLevel = . if ObstetricsLevel == -9
* Estimating two choice models - first w/out facility FE's, second with.
label variable zipfacdistancecn "Distance to Chosen"
label variable zipfacdistancecn2 "Squared Distance to Chosen"
label variable NeoIntensive "Level 3"
label variable SoloIntermediate "Level 2"
label variable ObstetricsLevel "Obstetrics Level"
label variable chosen "Hosp. Chosen"
eststo cnicu_`yr': clogit chosen zipfacdistancecn zipfacdistancecn2 NeoIntensive SoloIntermediate i.ObstetricsLevel, group(patid)
unique patid
estadd local pN "`r(N)'"
*mat a1 = e(b)
estimates save "${birthdata}`yr' nicuchoices", replace
predict pr1
* Compute Shares and save
bysort fidcn: gen shr = sum(pr1)
bysort fidcn: egen exp_share = max(shr)
keep fidcn exp_share
duplicates drop fidcn, force
rename fidcn fid
* this next step does not matter.
gen mnthly_share = exp_share/12
gen yr = `yr'
save "${birthdata}`yr'_nicufidshares.dta", replace
}
esttab cnicu_2005 cnicu_2006 cnicu_2007 cnicu_2008 cnicu_2009 cnicu_2010 using "/Users/austinbean/Desktop/Birth2005-2012/nicuinstruments.tex", label replace mtitle("2005" "2006" "2007" "2008" "2009" "2010") style(tex) stats(pN) cells(b se) legend eqlabels(none) collabels(none)
use "${birthdata}2005_nicufidshares.dta", clear
foreach yr of numlist 2006(1)2012{
append using "${birthdata}`yr'_nicufidshares.dta"
}
rename yr ncdobyear
save "${birthdata}allyearnicufidshares.dta", replace
foreach yr of numlist 2005(1)2012{
use "${birthdata}Birth`yr'.dta", clear
di "`yr'"
count
}
/*
* Checking correlation across the two instruments:
use "${birthdata}allyearnicufidshares.dta", clear
rename exp_share ex2
rename mnthly_share mn2
merge 1:m fid ncdobyear using "${birthdata}allyearfidshares.dta"
corr ex2 exp_share
| ex2 exp_sh~e
-------------+------------------
ex2 | 1.0000
exp_share | 0.9376 1.0000
*/