-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
188 lines (188 loc) · 6.79 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
rm(list=ls())
Income<-100
fedrate<-.0396
staterate<-.12
fedincome<-income-(staterate*stateincome)
stateincome<-income-(fedrate*fedincome)
fedtax<-fedincome*fedtax
statetax<-stateincome*statetax
rm(list=ls())
income<-100
fedrate<-.0396
staterate<-.12
fedincome<-income-(staterate*stateincome)
stateincome<-income-(fedrate*fedincome)
fedtax<-fedincome*fedtax
statetax<-stateincome*statetax
rm(list=ls())
staterate<-.05
fedrate<-.396
agi<-100000
statewitholding<-agi*staterate
fedtax1<-(agi-statewitholding)*fedrate
statetax-<-(agi-fedtax1)*staterate
fedtax2<-(agi-statetax)*fedrate
effectiverate<-fedrate+staterate
rm(list=ls())
staterate<-.05
fedrate<-.396
agi<-100000
statewitholding<-agi*staterate
fedtax1<-(agi-statewitholding)*fedrate
statetax<-(agi-fedtax1)*staterate
fedtax2<-(agi-statetax)*fedrate
effectiverate<-fedrate+staterate
rm(list=ls())
staterate<-.05
fedrate<-.396
agi<-100000
statewitholding<-agi*staterate
fedtax1<-(agi-statewitholding)*fedrate
statetax<-(agi-fedtax1)*staterate
fedtax2<-(agi-statetax)*fedrate
effectiverate<-fedtax2+statetax/agi
rm(list=ls())
staterate<-.05
fedrate<-.396
agi<-100000
statewitholding<-agi*staterate
fedtax1<-(agi-statewitholding)*fedrate
statetax<-(agi-fedtax1)*staterate
fedtax2<-(agi-statetax)*fedrate
effectiverate<-(fedtax2+statetax)/agi
#This is a follow up to the marriage penalty calculator. This looks at the marginal rate penalty faced by
#second earners in a household.
setwd("C:/Users/kep/Documents/GitHub/Marriage-Pen")
#setwd("C:/Users/Kyle/Documents/GitHub/Marriage-Pen")
rm(list=ls())
#This spreadsheet has all the income data and will show all the calculations, step-by-step.
income<-read.csv("income.csv", header = TRUE, fill = TRUE, sep = ",")
statetax<-read.csv("statetaxdata.csv", header = TRUE, fill = TRUE, sep = ",")
fedtax<-read.csv("fedtax.csv", header = TRUE, fill = TRUE, sep = ",")
data<-read.csv("data.csv", header = TRUE, fill = TRUE, sep = ",")
#data<-read.csv("newdata400.csv", header = TRUE, fill = TRUE, sep = ",")
#Load Functions. One file is the basic tax functions, the burden functions are the
#calculations for the actual penalty/bonus
source("marginalfunctions.R")
taxburden1<-function(income1,children,married,hoh,stateincometax){
income<-income1
children<-children
if(children > 0){
hoh<-1
} else {
hoh<-0
}
taxableincome<-FedTaxableIncome(income,children, married, hoh, stateincometax)
incometax<-FedIncomeTax(taxableincome,married,hoh)
ctc<-FedCTC(income,children,married)
eitc<-FedEITC(income,children,married)
medicare<-MedSurtax(income,married)
amt<-AMT(income,married)
totaltax<-( max(incometax-(ctc+eitc),amt)+medicare)
return(max(totaltax,amt))
}
taxburden2<-function(income2,children,married,hoh,stateincometax){
income<-income2
children<-children
if(children > 0){
hoh<-1
} else {
hoh<-0
}
taxableincome<-FedTaxableIncome(income,children, married, hoh, stateincometax)
incometax<-FedIncomeTax(taxableincome,married,hoh)
ctc<-FedCTC(income,children,married)
eitc<-FedEITC(income,children,married)
medicare<-MedSurtax(income,married)
amt<-AMT(income,married)
totaltax<-( max(incometax-(ctc+eitc),amt) +medicare)
return(totaltax)
}
marriedtaxburden<-function(income,children,married,hoh,stateincometax){
income<-income
married<-1
children<-children
taxableincome<-FedTaxableIncome(income,children, married, hoh, stateincometax)
incometax<-FedIncomeTax(taxableincome,married,hoh)
ctc<-FedCTC(income,children,married)
eitc<-FedEITC(income,children,married)
medicare<-MedSurtax(income,married)
amt<-AMT(income,married)
totaltax<-( max(incometax-(ctc+eitc),amt) +medicare)
return(totaltax)
}
#####No Children; set up those parameters:
children<-0
hoh<-0
#Setup the output files for each earner
output_primary_nochildren<-data$income
output_secondary_nochildren<-data$income
x<-1
while(x <= length(data$multiplier)){
multiplier<-data$multiplier[x]
i<-1
penaltyprimary<-NULL
penaltysecondary<-NULL
while(i <= length(data$income)){
income<-data$income[i]
stateincometax<-0
married<-0
income1<-income*multiplier
income2<-income*(1-multiplier)
person1<-taxburden1(income1+1,children,married,hoh,stateincometax)-taxburden1(income1,children,married,hoh,stateincometax) #primary earner's marginal rate
person2<-taxburden2(income2+1,children,married,hoh,stateincometax)-taxburden2(income2,children,married,hoh,stateincometax) #secondary earner's marginal rate
couple<-marriedtaxburden(income+1,children,married,hoh,stateincometax)-marriedtaxburden(income,children,married,hoh,stateincometax) #the couple's marginal rate
penaltyprimary[i]<-couple-(person1)
penaltysecondary[i]<-couple-(person2)
i<-i+1
}
output_primary_nochildren<-cbind(output_primary_nochildren,penaltyprimary)
output_secondary_nochildren<-cbind(output_secondary_nochildren,penaltysecondary)
x<-x+1
}
toutput_secondary_nochildren<-t(output_secondary_nochildren)
write.table(toutput_secondary_nochildren,sep=",",file="testmarginalrates.txt")
#Heat Map
View(output_primary_nochildren)
install.packages("gplots")
install.packages("RColorBrewer")
if (!require("gplots")) {
install.packages("gplots", dependencies = TRUE)
library(gplots)
}
if (!require("RColorBrewer")) {
install.packages("RColorBrewer", dependencies = TRUE)
library(RColorBrewer)
}
my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 299)
my_palette <- colorRampPalette(c("red", "white", "blue"))(n = 299)
View(output_secondary_nochildren)
View(output_secondary_nochildren)
heatmap.2(output_secondary__nochildren,
cellnote = output_secondary__nochildren, # same data set for cell labels
main = "Second Earner Penalty", # heat map title
notecol="black", # change font color of cell labels to black
density.info="none", # turns off density plot inside color legend
trace="none", # turns off trace lines inside the heat map
margins =c(12,9), # widens margins around plot
col=my_palette, # use on color palette defined earlier
#breaks=col_breaks, # enable color transition at specified limits
dendrogram="row", # only draw a row dendrogram
Colv="NA") # turn off column clustering
View(output_secondary_nochildren)
heatmap.2(toutput_secondary__nochildren,
cellnote = toutput_secondary__nochildren, # same data set for cell labels
main = "Second Earner Penalty", # heat map title
notecol="black", # change font color of cell labels to black
density.info="none", # turns off density plot inside color legend
trace="none", # turns off trace lines inside the heat map
margins =c(12,9), # widens margins around plot
col=my_palette, # use on color palette defined earlier
#breaks=col_breaks, # enable color transition at specified limits
dendrogram="row", # only draw a row dendrogram
Colv="NA") # turn off column clustering
View(toutput_secondary_nochildren)
map_data<-toutput_secondary_nochildren[,2:ncol(toutput_secondary_nochildren)]
View(map_data)
map_data<-toutput_secondary_nochildren[2:nrow(toutput_secondary_nochildren),]
View(map_data)