-
Notifications
You must be signed in to change notification settings - Fork 9
/
.Rhistory
512 lines (512 loc) · 26.2 KB
/
.Rhistory
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
## Load benfits parameters ----
load(paste0(current_directory,"/prd_parameters/benefit.parameters.rdata"))
## Load eligible tables of SMI,FPL / crosswalks ----
load(paste0(current_directory,"/prd_parameters/tables.rdata"))
## Load default parameters for the PRD----
load(paste0(current_directory,"/prd_parameters/parameters.defaults.rdata"))
# verify that everything is loaded in the console
## Call all the functions----
source(paste0(current_directory,"/libraries.R"), local=TRUE) # Load required packages
source(paste0(current_directory,"/functions/benefits_functions.R"), local=TRUE) # Benefits calculations
source(paste0(current_directory,"/functions/expense_functions.R"), local=TRUE) # Expenses calculations
source(paste0(current_directory,"/functions/BenefitsCalculator_functions.R"), local=TRUE) # Benefits Calculator functions
# SPECIFY PROJECT----
PROJECT<-"TEST"
## 1. Settings----
# Load inputs YAML file
inputs <- read_yaml(paste0(current_directory,"/projects/",PROJECT,".yml"))
# Global settings
k_ftorpt <- inputs$k_ftorpt
schoolagesummercare <- inputs$schoolagesummercare
headstart_ftorpt <- inputs$headstart_ftorpt
preK_ftorpt <- inputs$preK_ftorpt
contelig.headstart <- inputs$contelig.headstart
contelig.earlyheadstart <- inputs$contelig.earlyheadstart
contelig.ccdf <- inputs$contelig.ccdf
# Transfer programs switches
APPLY_CHILDCARE<-inputs$APPLY_CHILDCARE #Childcare block - Head Start and CCDF
APPLY_CCDF<-inputs$APPLY_CCDF
APPLY_HEADSTART<-inputs$APPLY_HEADSTART
APPLY_PREK<-inputs$APPLY_PREK
APPLY_LIHEAP<-inputs$APPLY_LIHEAP
APPLY_HEALTHCARE<-inputs$APPLY_HEALTHCARE
APPLY_MEDICAID_ADULT<-inputs$APPLY_MEDICAID_ADULT
APPLY_MEDICAID_CHILD<-inputs$APPLY_MEDICAID_CHILD
APPLY_ACA<-inputs$APPLY_ACA
APPLY_SECTION8<-inputs$APPLY_SECTION8
APPLY_RAP<-inputs$APPLY_RAP
APPLY_FRSP<-inputs$APPLY_FRSP
APPLY_SNAP<-inputs$APPLY_SNAP
APPLY_SLP<-inputs$APPLY_SLP
APPLY_WIC<-inputs$APPLY_WIC
APPLY_EITC<-inputs$APPLY_EITC
APPLY_TAXES<-inputs$APPLY_TAXES
APPLY_CTC<-inputs$APPLY_CTC
APPLY_CDCTC<-inputs$APPLY_CDCTC
APPLY_FATES<-inputs$APPLY_FATES
APPLY_TANF<-inputs$APPLY_TANF
APPLY_SSI<-inputs$APPLY_SSI
APPLY_SSDI<-inputs$APPLY_SSDI
## 2. Create data from inputs----
data<-function.createData(inputs)
## 3. Attach default expenses----
data<-BenefitsCalculator.DefaultExpenses(data)
## 4. Apply Benefits Calculator (block-by-block)----
# Apply other benefits block
data<-BenefitsCalculator.OtherBenefits(data, APPLY_TANF, APPLY_SSI, APPLY_SSDI) # OPTION TO END WITH APPLY_SSDI
# Apply child care block
data<-BenefitsCalculator.Childcare(data, APPLY_CHILDCARE, APPLY_HEADSTART, APPLY_PREK, APPLY_CCDF,APPLY_FATES) # OPTION TO END WITH APPLY_FATES
# Apply public health insurance block
data<-BenefitsCalculator.Healthcare(data, APPLY_HEALTHCARE, APPLY_MEDICAID_ADULT, APPLY_MEDICAID_CHILD, APPLY_ACA) # OPTION TO END WITH APPLY_ACA
# Apply food and housing block
data<-BenefitsCalculator.FoodandHousing(data, APPLY_SECTION8, APPLY_LIHEAP, APPLY_SNAP, APPLY_SLP, APPLY_WIC, APPLY_RAP, APPLY_FRSP) # OPTION TO END WITH APPLY_FRSP
# Apply taxes and tax credits block
data<-BenefitsCalculator.TaxesandTaxCredits(data, APPLY_EITC, APPLY_CTC, APPLY_CDCTC)
# Generate Additional Variables
data<-function.createVars(data)
## 5. Select variables of interest and save results----
data2<-data %>%
select(ruleYear, stateFIPS, stateName, stateAbbrev, countyortownName, famsize, numadults, numkids
, agePerson1, agePerson2, agePerson3, agePerson4, agePerson5, agePerson6, agePerson7, agePerson8, agePerson9, agePerson10, agePerson11, agePerson12,empl_healthcare
, income, assets.cash
, exp.childcare, exp.food, exp.rentormortgage, exp.healthcare, exp.utilities, exp.misc, exp.transportation
, netexp.childcare, netexp.food, netexp.rentormortgage, netexp.healthcare, netexp.utilities
, value.snap, value.schoolmeals, value.section8, value.liheap
, value.medicaid.adult, value.medicaid.child, value.aca, value.employerhealthcare
, value.CCDF, value.HeadStart, value.PreK
, value.cdctc.fed, value.cdctc.state, value.ctc.fed, value.ctc.state, value.eitc.fed, value.eitc.state
, value.eitc, value.ctc, value.cdctc, value.ssdi, value.ssi
, AfterTaxIncome, NetResources)
write.csv(data2, file = paste0(current_directory,"/output/results_",PROJECT, ".csv"), row.names = FALSE)
# Ellie & Elias Benefits Calculator----
# This program reads-in input data and runs Benefits Calculator
# PREAMBLE----
rm(list=ls())
## Setting your working directory----
current_directory<-getwd()
## Load expense parameters ----
load(paste0(current_directory,"/prd_parameters/expenses.rdata"))
## Load benfits parameters ----
load(paste0(current_directory,"/prd_parameters/benefit.parameters.rdata"))
## Load eligible tables of SMI,FPL / crosswalks ----
load(paste0(current_directory,"/prd_parameters/tables.rdata"))
## Load default parameters for the PRD----
load(paste0(current_directory,"/prd_parameters/parameters.defaults.rdata"))
# verify that everything is loaded in the console
## Call all the functions----
source(paste0(current_directory,"/libraries.R"), local=TRUE) # Load required packages
source(paste0(current_directory,"/functions/benefits_functions.R"), local=TRUE) # Benefits calculations
source(paste0(current_directory,"/functions/expense_functions.R"), local=TRUE) # Expenses calculations
source(paste0(current_directory,"/functions/BenefitsCalculator_functions.R"), local=TRUE) # Benefits Calculator functions
# SPECIFY PROJECT----
PROJECT<-"TEST"
## 1. Settings----
# Load inputs YAML file
inputs <- read_yaml(paste0(current_directory,"/projects/",PROJECT,".yml"))
# Global settings
k_ftorpt <- inputs$k_ftorpt
schoolagesummercare <- inputs$schoolagesummercare
headstart_ftorpt <- inputs$headstart_ftorpt
preK_ftorpt <- inputs$preK_ftorpt
contelig.headstart <- inputs$contelig.headstart
contelig.earlyheadstart <- inputs$contelig.earlyheadstart
contelig.ccdf <- inputs$contelig.ccdf
# Transfer programs switches
APPLY_CHILDCARE<-inputs$APPLY_CHILDCARE #Childcare block - Head Start and CCDF
APPLY_CCDF<-inputs$APPLY_CCDF
APPLY_HEADSTART<-inputs$APPLY_HEADSTART
APPLY_PREK<-inputs$APPLY_PREK
APPLY_LIHEAP<-inputs$APPLY_LIHEAP
APPLY_HEALTHCARE<-inputs$APPLY_HEALTHCARE
APPLY_MEDICAID_ADULT<-inputs$APPLY_MEDICAID_ADULT
APPLY_MEDICAID_CHILD<-inputs$APPLY_MEDICAID_CHILD
APPLY_ACA<-inputs$APPLY_ACA
APPLY_SECTION8<-inputs$APPLY_SECTION8
APPLY_RAP<-inputs$APPLY_RAP
APPLY_FRSP<-inputs$APPLY_FRSP
APPLY_SNAP<-inputs$APPLY_SNAP
APPLY_SLP<-inputs$APPLY_SLP
APPLY_WIC<-inputs$APPLY_WIC
APPLY_EITC<-inputs$APPLY_EITC
APPLY_TAXES<-inputs$APPLY_TAXES
APPLY_CTC<-inputs$APPLY_CTC
APPLY_CDCTC<-inputs$APPLY_CDCTC
APPLY_FATES<-inputs$APPLY_FATES
APPLY_TANF<-inputs$APPLY_TANF
APPLY_SSI<-inputs$APPLY_SSI
APPLY_SSDI<-inputs$APPLY_SSDI
## 2. Create data from inputs----
data<-function.createData(inputs)
## 3. Attach default expenses----
data<-BenefitsCalculator.DefaultExpenses(data)
## 4. Apply Benefits Calculator (block-by-block)----
# Apply other benefits block
data<-BenefitsCalculator.OtherBenefits(data, APPLY_TANF, APPLY_SSI, APPLY_SSDI) # OPTION TO END WITH APPLY_SSDI
# Apply child care block
data<-BenefitsCalculator.Childcare(data, APPLY_CHILDCARE, APPLY_HEADSTART, APPLY_PREK, APPLY_CCDF,APPLY_FATES) # OPTION TO END WITH APPLY_FATES
# Apply public health insurance block
data<-BenefitsCalculator.Healthcare(data, APPLY_HEALTHCARE, APPLY_MEDICAID_ADULT, APPLY_MEDICAID_CHILD, APPLY_ACA) # OPTION TO END WITH APPLY_ACA
# Apply food and housing block
data<-BenefitsCalculator.FoodandHousing(data, APPLY_SECTION8, APPLY_LIHEAP, APPLY_SNAP, APPLY_SLP, APPLY_WIC, APPLY_RAP, APPLY_FRSP) # OPTION TO END WITH APPLY_FRSP
# Apply taxes and tax credits block
data<-BenefitsCalculator.TaxesandTaxCredits(data, APPLY_EITC, APPLY_CTC, APPLY_CDCTC)
# Generate Additional Variables
data<-function.createVars(data)
## 5. Select variables of interest and save results----
data2<-data %>%
select(ruleYear, stateFIPS, stateName, stateAbbrev, countyortownName, famsize, numadults, numkids
, agePerson1, agePerson2, agePerson3, agePerson4, agePerson5, agePerson6, agePerson7, agePerson8, agePerson9, agePerson10, agePerson11, agePerson12,empl_healthcare
, income, assets.cash
, exp.childcare, exp.food, exp.rentormortgage, exp.healthcare, exp.utilities, exp.misc, exp.transportation
, netexp.childcare, netexp.food, netexp.rentormortgage, netexp.healthcare, netexp.utilities
, value.snap, value.schoolmeals, value.section8, value.liheap
, value.medicaid.adult, value.medicaid.child, value.aca, value.employerhealthcare
, value.CCDF, value.HeadStart, value.PreK
, value.cdctc.fed, value.cdctc.state, value.ctc.fed, value.ctc.state, value.eitc.fed, value.eitc.state
, value.eitc, value.ctc, value.cdctc, value.ssdi, value.ssi
, AfterTaxIncome, NetResources)
write.csv(data2, file = paste0(current_directory,"/output/results_",PROJECT, ".csv"), row.names = FALSE)
source("~/Documents/GitHub/policy-rules-database/tests/run_tests.R")
load("/Users/danielalejandrotasconbuchelly/Documents/GitHub/policy-rules-database/prd_parameters/expenses.rdata")
current_directory<-getwd()
## Load expense parameters ----
load(paste0(current_directory,"/prd_parameters/expenses.rdata"))
source("~/Documents/GitHub/policy-rules-database/tests/run_tests.R")
here()
library(testthat)
library(here)
# get directory for this project (in this case, it's where .git is)
proj_dir <- here::here()
#proj_dir <-"/Users/danielalejandrotasconbuchelly/Documents/GitHub/policy-rules-database"
#proj_dir <-"/Users/danielalejandrotasconbuchelly/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs"
setwd(proj_dir)
# Step 1 - create a test data frame
rm(list=ls())
## Setting your working directory----
#current_directory <- setwd("C:/Users/f1dat01/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs")
#current_directory<- setwd("/Users/danielalejandrotasconbuchelly/Documents/GitHub/policy-rules-database")
#current_directory<-setwd("/Users/danielalejandrotasconbuchelly/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs")
current_directory<-getwd()
## Load expense parameters ----
load(paste0(current_directory,"/prd_parameters/expenses.rdata"))
## Load benefits parameters ----
load(paste0(current_directory,"/prd_parameters/benefit.parameters.rdata"))
## Load eligible tables of SMI,FPL / crosswalks ----
load(paste0(current_directory,"/prd_parameters/tables.rdata"))
## Load default parameters for the PRD----
load(paste0(current_directory,"/prd_parameters/parameters.defaults.rdata"))
# verify that everything is loaded in the console
## Call all the functions----
source(paste0(current_directory,"/libraries.R"), local=TRUE) # Load required packages
source(paste0(current_directory,"/functions/benefits_functions.R"), local=TRUE) # Benefits calculations
source(paste0(current_directory,"/functions/expense_functions.R"), local=TRUE) # Expenses calculations
source(paste0(current_directory,"/functions/BenefitsCalculator_functions.R"), local=TRUE) # Benefits Calculator functions
# SPECIFY PROJECT----
PROJECT<-"Unit_test"
#PROJECT<-"TEST_SNAP"
## 1. Settings----
# Load inputs YAML file
inputs <- read_yaml(paste0(current_directory,"/projects/",PROJECT,".yml"))
# Global settings
k_ftorpt <- inputs$k_ftorpt
schoolagesummercare <- inputs$schoolagesummercare
headstart_ftorpt <- inputs$headstart_ftorpt
preK_ftorpt <- inputs$preK_ftorpt
contelig.headstart <- inputs$contelig.headstart
contelig.earlyheadstart <- inputs$contelig.earlyheadstart
contelig.ccdf <- inputs$contelig.ccdf
USEALICE <- inputs$USEALICE
# Transfer programs switches
APPLY_CHILDCARE<-inputs$APPLY_CHILDCARE #Childcare block - Head Start and CCDF
APPLY_CCDF<-inputs$APPLY_CCDF
APPLY_HEADSTART<-inputs$APPLY_HEADSTART
APPLY_PREK<-inputs$APPLY_PREK
APPLY_LIHEAP<-FALSE #doesn't work if true
APPLY_HEALTHCARE<-inputs$APPLY_HEALTHCARE
APPLY_MEDICAID_ADULT<-inputs$APPLY_MEDICAID_ADULT
APPLY_MEDICAID_CHILD<-inputs$APPLY_MEDICAID_CHILD
APPLY_ACA<-inputs$APPLY_ACA
APPLY_SECTION8<-inputs$APPLY_SECTION8
APPLY_RAP<-inputs$APPLY_RAP
APPLY_FRSP<-inputs$APPLY_FRSP
APPLY_SNAP<-inputs$APPLY_SNAP
APPLY_SLP<-inputs$APPLY_SLP
APPLY_WIC<-inputs$APPLY_WIC
APPLY_EITC<-inputs$APPLY_EITC
APPLY_TAXES<-inputs$APPLY_TAXES
APPLY_CTC<-inputs$APPLY_CTC
APPLY_CDCTC<-inputs$APPLY_CDCTC
APPLY_FATES<-inputs$APPLY_FATES
APPLY_TANF<-inputs$APPLY_TANF
APPLY_SSI<-inputs$APPLY_SSI
APPLY_SSDI<-inputs$APPLY_SSDI
## 2. Create data from inputs----
data<-function.createData(inputs)
## 3. Attach default expenses----
if (USEALICE == FALSE){
data<-BenefitsCalculator.DefaultExpenses(data)
}
if (USEALICE == TRUE){
data<-BenefitsCalculator.ALICEExpenses(data)
}
# testing first function
load("./unit_test/BenefitsCalculator.OtherBenefits_unittest.rdata")
test_that("OtherBenefits",{
expect_equal(BenefitsCalculator.OtherBenefits(data, APPLY_TANF, APPLY_SSDI, APPLY_SSI), data_unittest)
})
data=BenefitsCalculator.OtherBenefits(data, APPLY_TANF, APPLY_SSDI, APPLY_SSI)
load("./unit_test/BenefitsCalculator.Childcare_unittest.rdata")
test_that("Childcare",{
expect_equal(BenefitsCalculator.Childcare(data, APPLY_CHILDCARE, APPLY_HEADSTART, APPLY_PREK, APPLY_CCDF,APPLY_FATES), data_unittest)
})
data=BenefitsCalculator.Childcare(data, APPLY_CHILDCARE, APPLY_HEADSTART, APPLY_PREK, APPLY_CCDF,APPLY_FATES)
load("./unit_test/BenefitsCalculator.Healthcare_unittest.rdata")
test_that("Healthcare",{
expect_equal(BenefitsCalculator.Healthcare(data, APPLY_HEALTHCARE, APPLY_MEDICAID_ADULT, APPLY_MEDICAID_CHILD, APPLY_ACA), data_unittest)
})
data=BenefitsCalculator.Healthcare(data, APPLY_HEALTHCARE, APPLY_MEDICAID_ADULT, APPLY_MEDICAID_CHILD, APPLY_ACA)
load("./unit_test/BenefitsCalculator.FoodandHousing_unittest.rdata")
test_that("FoodandHousing",{
expect_equal(BenefitsCalculator.FoodandHousing(data, APPLY_SECTION8, APPLY_LIHEAP, APPLY_SNAP, APPLY_SLP, APPLY_WIC, APPLY_RAP, APPLY_FRSP), data_unittest)
})
data=BenefitsCalculator.FoodandHousing(data, APPLY_SECTION8, APPLY_LIHEAP, APPLY_SNAP, APPLY_SLP, APPLY_WIC, APPLY_RAP, APPLY_FRSP)
load("./unit_test/BenefitsCalculator.TaxesandTaxCredits_unittest.rdata")
test_that("TaxesandTax",{
expect_equal(BenefitsCalculator.TaxesandTaxCredits(data, APPLY_EITC, APPLY_CTC, APPLY_CDCTC, APPLY_TAXES), data_unittest)
})
data=BenefitsCalculator.TaxesandTaxCredits(data, APPLY_EITC, APPLY_CTC, APPLY_CDCTC, APPLY_TAXES)
load("./unit_test/function.createVars_unittest.rdata")
test_that("createVars",{
expect_equal(function.createVars(data), data_unittest)
})
# Ellie & Elias Benefits Calculator----
# This program reads-in input data and runs Benefits Calculator
# PREAMBLE----
rm(list=ls())
## Setting your working directory----
current_directory<-getwd()
## Load expense parameters ----
load(paste0(current_directory,"/prd_parameters/expenses.rdata"))
## Load benfits parameters ----
load(paste0(current_directory,"/prd_parameters/benefit.parameters.rdata"))
## Load eligible tables of SMI,FPL / crosswalks ----
load(paste0(current_directory,"/prd_parameters/tables.rdata"))
## Load default parameters for the PRD----
load(paste0(current_directory,"/prd_parameters/parameters.defaults.rdata"))
# verify that everything is loaded in the console
## Call all the functions----
source(paste0(current_directory,"/libraries.R"), local=TRUE) # Load required packages
source(paste0(current_directory,"/functions/benefits_functions.R"), local=TRUE) # Benefits calculations
source(paste0(current_directory,"/functions/expense_functions.R"), local=TRUE) # Expenses calculations
source(paste0(current_directory,"/functions/BenefitsCalculator_functions.R"), local=TRUE) # Benefits Calculator functions
# SPECIFY PROJECT----
#PROJECT<-"TEST"
PROJECT<-"Unit_test"
## 1. Settings----
# Load inputs YAML file
inputs <- read_yaml(paste0(current_directory,"/projects/",PROJECT,".yml"))
# Global settings
k_ftorpt <- inputs$k_ftorpt
schoolagesummercare <- inputs$schoolagesummercare
headstart_ftorpt <- inputs$headstart_ftorpt
preK_ftorpt <- inputs$preK_ftorpt
contelig.headstart <- inputs$contelig.headstart
contelig.earlyheadstart <- inputs$contelig.earlyheadstart
contelig.ccdf <- inputs$contelig.ccdf
# Transfer programs switches
APPLY_CHILDCARE<-inputs$APPLY_CHILDCARE #Childcare block - Head Start and CCDF
APPLY_CCDF<-inputs$APPLY_CCDF
APPLY_HEADSTART<-inputs$APPLY_HEADSTART
APPLY_PREK<-inputs$APPLY_PREK
APPLY_LIHEAP<-inputs$APPLY_LIHEAP
APPLY_HEALTHCARE<-inputs$APPLY_HEALTHCARE
APPLY_MEDICAID_ADULT<-inputs$APPLY_MEDICAID_ADULT
APPLY_MEDICAID_CHILD<-inputs$APPLY_MEDICAID_CHILD
APPLY_ACA<-inputs$APPLY_ACA
APPLY_SECTION8<-inputs$APPLY_SECTION8
APPLY_RAP<-inputs$APPLY_RAP
APPLY_FRSP<-inputs$APPLY_FRSP
APPLY_SNAP<-inputs$APPLY_SNAP
APPLY_SLP<-inputs$APPLY_SLP
APPLY_WIC<-inputs$APPLY_WIC
APPLY_EITC<-inputs$APPLY_EITC
APPLY_TAXES<-inputs$APPLY_TAXES
APPLY_CTC<-inputs$APPLY_CTC
APPLY_CDCTC<-inputs$APPLY_CDCTC
APPLY_FATES<-inputs$APPLY_FATES
APPLY_TANF<-inputs$APPLY_TANF
APPLY_SSI<-inputs$APPLY_SSI
APPLY_SSDI<-inputs$APPLY_SSDI
## 2. Create data from inputs----
data<-function.createData(inputs)
## 3. Attach default expenses----
data<-BenefitsCalculator.DefaultExpenses(data)
## 4. Apply Benefits Calculator (block-by-block)----
# Apply other benefits block
data<-BenefitsCalculator.OtherBenefits(data, APPLY_TANF, APPLY_SSI, APPLY_SSDI) # OPTION TO END WITH APPLY_SSDI
# Apply child care block
data<-BenefitsCalculator.Childcare(data, APPLY_CHILDCARE, APPLY_HEADSTART, APPLY_PREK, APPLY_CCDF,APPLY_FATES) # OPTION TO END WITH APPLY_FATES
# Apply public health insurance block
data<-BenefitsCalculator.Healthcare(data, APPLY_HEALTHCARE, APPLY_MEDICAID_ADULT, APPLY_MEDICAID_CHILD, APPLY_ACA) # OPTION TO END WITH APPLY_ACA
# Apply food and housing block
data<-BenefitsCalculator.FoodandHousing(data, APPLY_SECTION8, APPLY_LIHEAP, APPLY_SNAP, APPLY_SLP, APPLY_WIC, APPLY_RAP, APPLY_FRSP) # OPTION TO END WITH APPLY_FRSP
# Apply taxes and tax credits block
data<-BenefitsCalculator.TaxesandTaxCredits(data, APPLY_EITC, APPLY_CTC, APPLY_CDCTC)
# Generate Additional Variables
data<-function.createVars(data)
## 5. Select variables of interest and save results----
data2<-data %>%
select(ruleYear, stateFIPS, stateName, stateAbbrev, countyortownName, famsize, numadults, numkids
, agePerson1, agePerson2, agePerson3, agePerson4, agePerson5, agePerson6, agePerson7, agePerson8, agePerson9, agePerson10, agePerson11, agePerson12,empl_healthcare
, income, assets.cash
, exp.childcare, exp.food, exp.rentormortgage, exp.healthcare, exp.utilities, exp.misc, exp.transportation
, netexp.childcare, netexp.food, netexp.rentormortgage, netexp.healthcare, netexp.utilities
, value.snap, value.schoolmeals, value.section8, value.liheap
, value.medicaid.adult, value.medicaid.child, value.aca, value.employerhealthcare
, value.CCDF, value.HeadStart, value.PreK
, value.cdctc.fed, value.cdctc.state, value.ctc.fed, value.ctc.state, value.eitc.fed, value.eitc.state
, value.eitc, value.ctc, value.cdctc, value.ssdi, value.ssi
, AfterTaxIncome, NetResources)
write.csv(data2, file = paste0(current_directory,"/output/results_",PROJECT, ".csv"), row.names = FALSE)
# Ellie & Elias Benefits Calculator----
# This program reads-in input data and runs Benefits Calculator
# PREAMBLE----
rm(list=ls())
## Setting your working directory----
#current_directory <- setwd("C:/Users/f1acs02/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs")
#current_directory <- setwd("C:/Users/f1dat01/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs")
#current_directory <- setwd("C:/Users/edgar/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs")
#current_directory<-setwd("/Users/danielalejandrotasconbuchelly/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs")
current_directory<-getwd()
## Load expense parameters ----
load(paste0(current_directory,"/prd_parameters/expenses.rdata"))
## Load benefits parameters ----
load(paste0(current_directory,"/prd_parameters/benefit.parameters.rdata"))
## Load eligible tables of SMI,FPL / crosswalks ----
load(paste0(current_directory,"/prd_parameters/tables.rdata"))
## Load default parameters for the PRD----
load(paste0(current_directory,"/prd_parameters/parameters.defaults.rdata"))
# verify that everything is loaded in the console
## Call all the functions----
source(paste0(current_directory,"/libraries.R"), local=TRUE) # Load required packages
source(paste0(current_directory,"/functions/benefits_functions.R"), local=TRUE) # Benefits calculations
source(paste0(current_directory,"/functions/expense_functions.R"), local=TRUE) # Expenses calculations
source(paste0(current_directory,"/functions/BenefitsCalculator_functions.R"), local=TRUE) # Benefits Calculator functions
# SPECIFY PROJECT----
PROJECT<-"Unit_test"
#PROJECT<-"TEST"
## 1. Settings----
# Load inputs YAML file
inputs <- read_yaml(paste0(current_directory,"/projects/",PROJECT,".yml"))
# Global settings
k_ftorpt <- inputs$k_ftorpt
schoolagesummercare <- inputs$schoolagesummercare
headstart_ftorpt <- inputs$headstart_ftorpt
preK_ftorpt <- inputs$preK_ftorpt
contelig.headstart <- inputs$contelig.headstart
contelig.earlyheadstart <- inputs$contelig.earlyheadstart
contelig.ccdf <- inputs$contelig.ccdf
USEALICE <- inputs$USEALICE
# Transfer programs switches
APPLY_CHILDCARE<-inputs$APPLY_CHILDCARE #Childcare block - Head Start and CCDF
APPLY_CCDF<-inputs$APPLY_CCDF
APPLY_HEADSTART<-inputs$APPLY_HEADSTART
APPLY_PREK<-inputs$APPLY_PREK
APPLY_LIHEAP<-FALSE #doesn't work if true
APPLY_HEALTHCARE<-inputs$APPLY_HEALTHCARE
APPLY_MEDICAID_ADULT<-inputs$APPLY_MEDICAID_ADULT
APPLY_MEDICAID_CHILD<-inputs$APPLY_MEDICAID_CHILD
APPLY_ACA<-inputs$APPLY_ACA
APPLY_SECTION8<-inputs$APPLY_SECTION8
APPLY_RAP<-inputs$APPLY_RAP
APPLY_FRSP<-inputs$APPLY_FRSP
APPLY_SNAP<-inputs$APPLY_SNAP
APPLY_SLP<-inputs$APPLY_SLP
APPLY_WIC<-inputs$APPLY_WIC
APPLY_EITC<-inputs$APPLY_EITC
APPLY_TAXES<-inputs$APPLY_TAXES
APPLY_CTC<-inputs$APPLY_CTC
APPLY_CDCTC<-inputs$APPLY_CDCTC
APPLY_FATES<-inputs$APPLY_FATES
APPLY_TANF<-inputs$APPLY_TANF
APPLY_SSI<-inputs$APPLY_SSI
APPLY_SSDI<-inputs$APPLY_SSDI
## 2. Create data from inputs----
data<-function.createData(inputs)
## 3. Attach default expenses----
if (USEALICE == FALSE){
data<-BenefitsCalculator.DefaultExpenses(data)
}
if (USEALICE == TRUE){
data<-BenefitsCalculator.ALICEExpenses(data)
}
## 4. Apply Benefits Calculator (block-by-block)----
# Apply other benefits block
data<-BenefitsCalculator.OtherBenefits(data, APPLY_TANF, APPLY_SSI, APPLY_SSDI) # OPTION TO END WITH APPLY_SSDI
data_unittest<-data
save (data_unittest,file="./unit_test/BenefitsCalculator.OtherBenefits_unittest.rdata")
rm(data_unittest)
# Apply child care block
data<-BenefitsCalculator.Childcare(data, APPLY_CHILDCARE, APPLY_HEADSTART, APPLY_PREK, APPLY_CCDF,APPLY_FATES) # OPTION TO END WITH APPLY_FATES
data_unittest<-data
save (data_unittest,file="./unit_test/BenefitsCalculator.Childcare_unittest.rdata")
rm(data_unittest)
# Apply public health insurance block
data<-BenefitsCalculator.Healthcare(data, APPLY_HEALTHCARE, APPLY_MEDICAID_ADULT, APPLY_MEDICAID_CHILD, APPLY_ACA) # OPTION TO END WITH APPLY_ACA
data_unittest<-data
save (data_unittest,file="./unit_test/BenefitsCalculator.Healthcare_unittest.rdata")
rm(data_unittest)
# Apply food and housing block
data<-BenefitsCalculator.FoodandHousing(data, APPLY_SECTION8, APPLY_LIHEAP, APPLY_SNAP, APPLY_SLP, APPLY_WIC, APPLY_RAP, APPLY_FRSP) # OPTION TO END WITH APPLY_FRSP
data_unittest<-data
save (data_unittest,file="./unit_test/BenefitsCalculator.FoodandHousing_unittest.rdata")
rm(data_unittest)
# Apply taxes and tax credits block
data<-BenefitsCalculator.TaxesandTaxCredits(data, APPLY_EITC, APPLY_CTC, APPLY_CDCTC, APPLY_TAXES)
data_unittest<-data
save (data_unittest,file="./unit_test/BenefitsCalculator.TaxesandTaxCredits_unittest.rdata")
rm(data_unittest)
# Generate Additional Variables
data<-function.createVars(data)
data_unittest<-data
save (data_unittest,file="./unit_test/function.createVars_unittest.rdata")
rm(data_unittest)
## 5. Select variables of interest and save results----
data2<-data %>%
select(ruleYear, stateFIPS, stateName, stateAbbrev, countyortownName, famsize, numadults, numkids
, agePerson1, agePerson2, agePerson3, agePerson4, agePerson5, agePerson6, agePerson7, agePerson8, agePerson9, agePerson10, agePerson11, agePerson12,empl_healthcare
, income, assets.cash
, exp.childcare, exp.food, exp.rentormortgage, exp.healthcare, exp.utilities, exp.misc, exp.transportation
, netexp.childcare, netexp.food, netexp.rentormortgage, netexp.healthcare, netexp.utilities
, tax.income.fed, tax.income.state, tax.FICA
, value.snap, value.wic, value.schoolmeals, value.section8, value.liheap
, value.medicaid.adult, value.medicaid.child, value.aca, value.employerhealthcare
, value.CCDF, value.HeadStart, value.PreK
, value.cdctc.fed, value.cdctc.state, value.ctc.fed, value.ctc.state, value.eitc.fed, value.eitc.state
, value.eitc, value.ctc, value.cdctc, value.ssdi, value.ssi
, AfterTaxIncome, NetResources)
write.csv(data2, file = paste0(current_directory,"/output/results_",PROJECT, ".csv"), row.names = FALSE)
data<-BenefitsCalculator.FoodandHousing(data, APPLY_SECTION8, APPLY_LIHEAP, APPLY_SNAP, APPLY_SLP, APPLY_WIC, APPLY_RAP, APPLY_FRSP) # OPTION TO END WITH APPLY_FRSP
proj_dir <-"/Users/danielalejandrotasconbuchelly/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs"
setwd(proj_dir)
set_here()
source("~/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs/tests/run_tests.R")
source("~/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs/tests/run_tests.R")
source("~/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs/tests/run_tests.R")
library(testthat)
library(here)
# get directory for this project (in this case, it's where .git is)
proj_dir <- here::here()
#proj_dir <-"/Users/danielalejandrotasconbuchelly/Documents/GitHub/policy-rules-database"
#proj_dir <-"/Users/danielalejandrotasconbuchelly/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs"
setwd(proj_dir)
# Step 1 - create a test data frame
rm(list=ls())
## Setting your working directory----
#current_directory <- setwd("C:/Users/f1dat01/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs")
#current_directory<- setwd("/Users/danielalejandrotasconbuchelly/Documents/GitHub/policy-rules-database")
#current_directory<-setwd("/Users/danielalejandrotasconbuchelly/Dropbox (ATL FRB)/WorkForceDevProj/Documentation/Benefits & Expenses Database/programs")
current_directory<-getwd()
## Load expense parameters ----
load(paste0(current_directory,"/prd_parameters/expenses.rdata"))
current_directory