Skip to content

Commit

Permalink
finalized R code
Browse files Browse the repository at this point in the history
  • Loading branch information
sbischl committed Dec 11, 2020
1 parent dcbea0e commit 986ee2e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 254 deletions.
13 changes: 7 additions & 6 deletions assumptions.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Changeable Assumptions
#----------------------------------------------------------------------------------------------------------------------#

# Economic Assumptions:
# Basic Assumptions:
discount_rate <- 0.03
retirement_age <- 64 # This is more or less set in stone by the IAB data. We cannot go higher only lower.
retirement_age <- 64 # This is more or less set in stone by the IAB data. We cannot go higher than 64 only lower.
wage_growth_rate <- 0.005

# Tax System Assumptions:
Expand All @@ -22,7 +22,7 @@ global_income_fraction_of_long_term_care_contribution <- 0 # The fraction of une
global_welfare_benefit_monthly <- 700
value_added_tax <- 0.19

# Behaviroal reponses to taxation
# Behavioural responses to taxation
cost_of_raising_public_funds <- 0.3 # Relevant for the more traditional benefit cost ratio
# Elasticity of Taxable Income
overwrite_eti <- FALSE # If set to true the ETI specified below is used for all tax reforms
Expand All @@ -31,7 +31,7 @@ global_eti <- 0.3 # Irrelevant unless overwrite_eti == TRUE
# Preferences
global_relative_risk_aversion <- 2

# Value of statistical Life and Injuries:
# Value of statistical life and injuries:
use_single_statistical_life_value <- TRUE # If set to true only one statistical life value has to be specified. All of the
# other values for injuries and the differentiation between resource cost and risk value are derived from the value set
# in value_of_statistical_life
Expand Down Expand Up @@ -90,15 +90,16 @@ excluded_from_deflating <- c("taxReform2005",
order_of_categories <- c("Top Tax Reform",
"Education",
"Job Training",
"Start up Subsidy",
"Start-Up Subsidy",
"Subsidized Employment",
"Other Labor Market Policies",
"Unemployment Insurance",
"Parental Leave Reform",
"Climate Policy",
"Health Program",
"Other") #This determines the order in which the reforms categories are displayed in the graphs
# and tables.
# and tables. If a new category is added (or a existing is renamed this has to be updated). Otherwise the program crashes
# when trying to calculate category averages.

# Exclude Programs from category average:
excluded_from_category_average <- c("bicycleHelmet", "coronavirusLockdownR1")
Expand Down
10 changes: 7 additions & 3 deletions functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ getPointEstimates <- function(programs) {
mvpf_results <- data.frame(program = programs)
for (i in 1:length(programs)) {
message(paste("Running", programs[i], "once to get the point estimate."))
# Call program "i" and store the return values
return_values <- do.call(programs[i], list())

# Deflate unless deflating is explicitely disabled.
if (!programs[i] %in% excluded_from_deflating) {
return_values <- deflateReturnValues(return_values, results_prices)
}
Expand All @@ -86,13 +88,15 @@ getPointEstimates <- function(programs) {
mvpf_results[names(return_values), ] <- unlist(return_values)
next
}
# Store the return values in the results data.frame
mvpf_results[i, names(return_values)] <- unlist(return_values)
# Calculate the MVPF and also store it in the results data.frame
mvpf_results[i, "mvpf"] <- calculateMVPF(mvpf_results[i, "willingness_to_pay"], mvpf_results[i, "government_net_costs"])
}
return(mvpf_results)
}

# Run Programs without priting messages
# Run Programs without printing messages
quietelyRunPrograms <- function(programs, bootstrap = FALSE) {
results <- suppressMessages(getPointEstimates(programs))
if (bootstrap) {
Expand Down Expand Up @@ -712,7 +716,7 @@ getCategoryPlotData <- function(plot_data, bootstrap_results, include_additional
return(1 - bootstrap_results$government_net_costs / bootstrap_results$program_cost)
})

# Calculate numerator and denominator as before expcet that the result now is a vector with number of bootstrap replications rows:
# Calculate numerator and denominator as before except that the result now is a vector with 'number of bootstrap replications' rows:
numerator_bootstrap <- 1 / ncol(willingness_to_pay_per_euro) * rowSums(willingness_to_pay_per_euro)
denominator_bootstrap <- 1 / ncol(willingness_to_pay_per_euro) * (-rowSums(fiscal_externality_per_euro) + ncol(fiscal_externality_per_euro))

Expand Down Expand Up @@ -1063,7 +1067,7 @@ getTaxSystemEffects <- function(gross_income,
# Higher pension contributions result in higher pension payments but due to demographics the return is probably quite low.

# adapted from:
# 'Identifying Laffer Bounds: A Sufficient-Statistics Approach with an Application to Germany' by Sachs and Lorenz (2015) Appendix A
# 'Identifying Laffer Bounds: A Sufficient-Statistics Approach with an Application to Germany' by Lorenz and Sachs (2015) Appendix A
# and their supplementary excel file

# Calculations are for a single household without children
Expand Down
17 changes: 7 additions & 10 deletions main.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#----------------------------------------------------------------------------------------------------------------------#
# Unified Welfare Analysis for Germany using MVPFs (Marginal Value of Public Funds)
# Unified Welfare Analysis for Germany using the MVPF (Marginal Value of Public Funds)
#----------------------------------------------------------------------------------------------------------------------#

# Clear the environment:
Expand Down Expand Up @@ -37,7 +37,7 @@ if (length(not_installed_packages) > 0) {
break
}
else if (confirmation == "n") {
stop("Need to have required packages installed. Exiting...")
stop("Need to have the required packages installed. Exiting...")
}
}
}
Expand Down Expand Up @@ -129,7 +129,7 @@ plotResults(plot_data = plot_data,
# Figure that plots the Net Costs of all policies against the year they were implemented (with text lables)
plotResults(plot_data = plot_data,
y_axis = "government_net_costs_per_program_cost",
y_label = "Net Costs per Euro Progammatic Expenditure",
y_label = "Net Costs per Euro Programmatic Expenditure",
x_axis = "year", x_label = "Year",
save = "cost_against_year.pdf",
lower_cutoff = 0,
Expand All @@ -140,7 +140,7 @@ plotResults(plot_data = plot_data,
# Figure that plots the WTP of all policies against the year they were implemented (with text lables)
plotResults(plot_data = plot_data,
y_axis = "willingness_to_pay_per_program_cost",
y_label = "Willingness to Pay per Euro Progammatic Expenditure",
y_label = "Willingness to Pay per Euro Programmatic Expenditure",
x_axis = "year", x_label = "Year",
save = "wtp_against_year.pdf",
lower_cutoff = 0,
Expand Down Expand Up @@ -236,7 +236,7 @@ robustnessCheck(programs,
global_flat_tax <<- 0.5
}
},
headlines = c("τ = 0.1", "Only Income Tax", "Taxes and Transfers (Baseline)", "τ = 0.5"),
headlines = c("τ = 0.1", "Only Income Tax", "German Tax and Transfer System (Baseline)", "τ = 0.5"),
overwrite_bootstrap_replications = 100,
save = "robustness_check_tax_rate.pdf")

Expand All @@ -255,7 +255,7 @@ robustnessCheck(programs,
yearly_return_to_schooling <<- 0.11
}
else if (specification == 4) {
# Baseline
# nothing baseline
}
},
headlines = c("RTS = 5%", "RTS = 8%", " RTS = 11%", "IAB Data (Baseline)"),
Expand All @@ -270,7 +270,4 @@ cat("Robustness checks completed in ", difftime(Sys.time(), start_time, units='m
#exportPlotCSV(programs, assumption_list = getListOfAllMetaAssumptions(), bootstrap = FALSE, meta_assumptions = TRUE)

# Export Tables:
exportLatexTables(plot_data)

# Copy Files:
FolderCopy()
exportLatexTables(plot_data)
3 changes: 3 additions & 0 deletions web/csv/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
the files generated by
exportPlotCSV(programs, assumption_list = getListOfAllMetaAssumptions(), bootstrap = FALSE, meta_assumptions = TRUE)
need to be placed here.
235 changes: 0 additions & 235 deletions web/variables.json

This file was deleted.

0 comments on commit 986ee2e

Please sign in to comment.