Repository navigation
Expand file tree
/
Copy pathsettings.R
More file actions
232 lines (142 loc) · 8.23 KB
/
Copy pathsettings.R
File metadata and controls
232 lines (142 loc) · 8.23 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# DO NOT MODIFY THIS SCRIPT DURING MULTITHREADING
# year: march cps-asec, one year ahead of acs
# myear: marketplace hiu income inflation past dataset year
# efya: values of the cps "peinusyr" variable indicating an immigrant entered the country five years ago or less
# etya: values of the cps "peinusyr" variable indicating an immigrant entered the country ten years ago or less
# pcap: 100-400% FPL aca hiu premium as a percent of hiu income caps
# pyear: year of marketplace premium data
# redesign: TRUE if (research cps-asec 2017) OR (bridge cps-asec 2018) OR cps-asec 2019+ otherwise FALSE
# production cps-asec 2025 and acs 2024 ; 2026 premium caps (separated from ARPA) ; 2026 premiums
year <- 2025 ; myear <- year ; efya <- 27:28 ; etya <- 24:28 ; pcap <- c( 2.1 , 2.1 , 3.14 , 4.19 , 6.6 , 8.44 , 9.96 , 9.96 ) ; pyear <- 2026 ; redesign <- TRUE
# production cps-asec 2025 and acs 2024 ; 2026 premium caps (separated from ARPA) ; 2025 premiums NOT 2026
# year <- 2025 ; myear <- year - 1 ; efya <- 27:28 ; etya <- 24:28 ; pcap <- c( 2.1 , 2.1 , 3.14 , 4.19 , 6.6 , 8.44 , 9.96 , 9.96 ) ; pyear <- 2025 ; redesign <- TRUE
# production cps-asec 2024 and acs 2023 ; 2025 premium caps because ARPA ; 2026 premiums
# year <- 2024 ; myear <- year + 1 ; efya <- 27:28 ; etya <- 24:28 ; pcap <- c( 1.82 , 1.82 , 2.73 , 3.64 , 5.73 , 7.33 , 8.65 , 8.65 ) ; pyear <- 2026 ; redesign <- TRUE
# production cps-asec 2024 and acs 2023 ; 2025 premium caps because ARPA ; 2025 premiums
# year <- 2024 ; myear <- year ; efya <- 27:28 ; etya <- 24:28 ; pcap <- c( 1.82 , 1.82 , 2.73 , 3.64 , 5.73 , 7.33 , 8.65 , 8.65 ) ; pyear <- 2025 ; redesign <- TRUE
# cps-asec 2014 and acs 2013 ; 2014 premium caps ; 2026 premiums
# year <- 2014 ; myear <- year + 11 ; efya <- 22:23 ; etya <- 21:19 ; pcap <- c( 2 , 2 , 3 , 4 , 6.3 , 8.05 , 9.5 , 9.5 ) ; pyear <- 2026 ; redesign <- FALSE
# cps-asec 2014 and acs 2013 ; 2014 premium caps ; 2025 premiums
# year <- 2014 ; myear <- year + 10 ; efya <- 22:23 ; etya <- 21:19 ; pcap <- c( 2 , 2 , 3 , 4 , 6.3 , 8.05 , 9.5 , 9.5 ) ; pyear <- 2025 ; redesign <- FALSE
# Source for required contribution (pcap)
# The required premium contribution is inflated based on the adjustment ratio calculated using projections of gross domestic product per capita from the National Health Expenditure Account.
# https://www.cms.gov/research-statistics-data-and-systems/statistics-trends-and-reports/nationalhealthexpenddata/nationalhealthaccountsprojected.html
library(survey)
library(mitools)
library(snow)
library(sqldf)
library(arrow)
options( timeout = 999 )
options( survey.replicates.mse = TRUE )
no.na <- function( z , value = FALSE ){ z[ is.na( z ) ] <- value ; z }
ec <- function( x , y ) paste( rep( x , each = length( y ) ) , y , sep = '' )
MIcombine_zero <- function( z ){ z <- lapply( z , function( y ){ y[ is.na( y ) ] <- 0 ; y } ) ; MIcombine( z ) }
fp <- function( w ) data.frame( results = coef( w ) , se = sqrt( diag( vcov( w ) ) ) )
squ <- function( z ){ z[ no.na( ( z[ 2 ] / z[ 1 ] > 0.3 ) | ( z[ 2 ] == 0 ) ) , ] <- NA ; z }
# rename & merge
rnam <-
function( z , y , n ){
names( y ) <- gsub( 'hiu' , n , names( y ) )
merge( z , y )
}
set.seed( year )
code_folder <- "S:/Users/AnthonyD/Current Population Survey/repository/"
cps_output_folder <- "R:/Current Population Survey/2025 generated/"
acs_output_folder <- "R:/American Community Survey/2024 generated/"
cps_rds_fn <- paste0( "R:/Current Population Survey/rds/" , year , " cps asec.rds" )
premium_fn <- paste0( "S:/Users/AnthonyD/Current Population Survey/repository/slcsp lcbp " , pyear , ".csv" )
mcdc_fn <- paste0( code_folder , "MCDC zcta to county.csv" )
census_fn <- paste0( code_folder , "census counts.csv" )
irs_ceilings_fn <- paste0( code_folder , "irs ceilings.csv" )
hhs_thresholds_fn <- paste0( code_folder , "hhs thresholds.csv" )
# load fpl categories
medicaid_fpl <- read.csv( paste0( code_folder , "medicaid fpl.csv" ) )
chip_fpl <- read.csv( paste0( code_folder , "chip fpl.csv" ) )
# determine character columns plus `gestfips`
ccols <- unique( c( which( sapply( medicaid_fpl , class ) == 'character' ) , which( names( medicaid_fpl ) == 'gestfips' ) ) )
# add prefixes in front of all of the eligibility columns
names( medicaid_fpl )[ -ccols ] <- paste0( 'caidelig_' , names( medicaid_fpl )[ -ccols ] )
names( chip_fpl )[ -1 ] <- paste0( 'chipelig_' , names( chip_fpl )[ -1 ] )
stopifnot( nrow( medicaid_fpl ) == 52 )
stopifnot( nrow( chip_fpl ) == 52 )
aca_age_factors_fn <- paste0( code_folder , "aca age factors 2018.csv" )
# marketplace inflation factor calculation
if( year > pyear ) stop( "marketplace inflation factor should be <= 1" ) else {
# for non-projections, use annual statistics from https://fred.stlouisfed.org/series/ECIWAG
# for projection years,
# marketplace inflation factors (miif) come from the 10-year economic projections
# https://www.cbo.gov/about/products/budget-economic-data#4 for example
# "calendar year" tab excel rows #23 and #24 of
# https://www.cbo.gov/system/files/2025-09/51135-2025-09-Economic-Projections.xlsx
eciwag <-
structure(
list(
year = 2007:2026,
eciwag = c(105.5, 108.6, 110.4,
112.1, 114, 116, 118.2, 120.6, 123.3, 126.3, 129.5, 133.4, 137.4,
141.4, 147.1, 154.8 , 161.925 , 168.3, 174.2 , 180.1 ),
percent_change = c(NA, 1.02962, 1.01588, 1.01609, 1.01628, 1.01821, 1.01896,
1.0203, 1.02238, 1.02372, 1.02554, 1.03031, 1.02961, 1.0293,
1.04014, 1.05253, 1.04603 , 1.03937 , 1.03501 , 1.03416 ),
projection = c(FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE , FALSE , FALSE , FALSE , TRUE , TRUE )
) ,
class = "data.frame",
row.names = c(NA, -20L)
)
miif <- prod( eciwag[ eciwag[ , 'year' ] %in% seq( year , pyear ) , 'percent_change' ] )
}
# https://www.irs.gov/pub/irs-prior/p501--2025.pdf
irs_ceilings <- read.csv( irs_ceilings_fn )
stopifnot( all.equal( names( irs_ceilings ) , c("year", "senior", "blind", "projection", "unearned_nonfiler_ceiling", "earned_nonfiler_ceiling", "gross_qr_ceiling", "single_nonfiler_ceiling", "joint_nonfiler_ceiling", "hoh_nonfiler_ceiling") ) )
# https://aspe.hhs.gov/topics/poverty-economic-mobility/poverty-guidelines
hhs_poverty <- read.csv( hhs_thresholds_fn )
stopifnot( all.equal( names( hhs_poverty ) , c("year", "cont", "cont_incr", "ak", "ak_incr", "hi", "hi_incr") ) )
# premium caps prior to 2021 ARPA stimulus #
# hard-code all premium caps
premium_caps <-
data.frame(
pov = c( 0 , 1.32 , 1.33 , 1.5 , 2 , 2.5 , 3 , 4 ) ,
cap = pcap
)
# calculate premium caps for all fpl values between 0 and 400
pc <- data.frame( pov = ( 0:400 ) / 100 )
pc <- merge( pc , premium_caps , all.x = T )
for ( i in 2:nrow( premium_caps ) ){
low_row <- rownames( pc[ pc[ , 'pov' ] == premium_caps[ i - 1 , 'pov' ] , ] )
hi_row <- rownames( pc[ pc[ , 'pov' ] == premium_caps[ i , 'pov' ] , ] )
pct_btw <-
( premium_caps[ i , 'cap' ] - premium_caps[ i - 1 , 'cap' ] ) /
( ( premium_caps[ i , 'pov' ] - premium_caps[ i - 1 , 'pov' ] ) * 100 )
pc[ low_row:hi_row , 'cap' ] <-
seq(
premium_caps[ i - 1 , 'cap' ] ,
premium_caps[ i , 'cap' ] ,
by = pct_btw
)
}
# tax filing units at exactly 400% fpl are NOT subsidy-eligible
pc <- subset( pc , pov < 4 )
# end of premium cap calculations
# premium caps new for 2021 ARPA stimulus #
arpa_cap <-
data.frame(
pov = c( 0 , 1.5 , 2 , 2.5 , 3 , 4 ) ,
arpa_cap = c( 0 , 0 , 2 , 4 , 6 , 8.5 )
)
arpa_pc <- data.frame( pov = ( 0:400 ) / 100 )
arpa_pc <- merge( arpa_pc , arpa_cap , all.x = T )
for ( i in 2:nrow( arpa_cap ) ){
low_row <- rownames( arpa_pc[ arpa_pc[ , 'pov' ] == arpa_cap[ i - 1 , 'pov' ] , ] )
hi_row <- rownames( arpa_pc[ arpa_pc[ , 'pov' ] == arpa_cap[ i , 'pov' ] , ] )
pct_btw <-
( arpa_cap[ i , 'arpa_cap' ] - arpa_cap[ i - 1 , 'arpa_cap' ] ) /
( ( arpa_cap[ i , 'pov' ] - arpa_cap[ i - 1 , 'pov' ] ) * 100 )
arpa_pc[ low_row:hi_row , 'arpa_cap' ] <-
seq(
arpa_cap[ i - 1 , 'arpa_cap' ] ,
arpa_cap[ i , 'arpa_cap' ] ,
by = pct_btw
)
}