-
Notifications
You must be signed in to change notification settings - Fork 0
/
BMW_model_tables.R
260 lines (204 loc) · 9.41 KB
/
BMW_model_tables.R
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
# Model BMW for R: balance-sheet and transactions-flow matrix
# from Wynne Godley and Marc Lavoie
# Monetary Economics
# Chapter 7
# Version: 8 November 2023
################################################################################
#Create BS and TFM tables
#Upload libraries
library(knitr)
#Choose a year
yr=50
#Choose a scenario (note: 1 = baseline)
scen=1
################################################################################
################################################################################
#Create row names for BS matrix
rownames<-c( "Deposits",
"Loans",
"Fixed capital",
"Balance (net worth)",
"Column total")
################################################################################
#Create households aggregates
H <-c( round(mh[scen,yr], digits = 2),
"",
"",
round(-mh[scen,yr], digits = 2),
round(mh[scen,yr]-mh[scen,yr], digits = 2)
)
#Create table of results
H_BS<-as.data.frame(H,row.names=rownames)
#Print firms column
kable(H_BS)
################################################################################
#Create firms aggregates
P <-c( "",
round(-l_d[scen,yr], digits = 2),
round(k[scen,yr], digits = 2),
0,
round(-l_d[scen,yr]+k[scen,yr], digits = 2)
)
#Create table of results
F_BS<-as.data.frame(P,row.names=rownames)
#Print firms column
kable(F_BS)
################################################################################
#Create banks aggregates
B <-c( round(-ms[scen,yr], digits = 2),
round(l_s[scen,yr], digits = 2),
"",
0,
round(ms[scen,yr]-l_s[scen,yr], digits = 2)
)
#Create table of results
B_BS<-as.data.frame(B,row.names=rownames)
#Print firms column
kable(B_BS)
################################################################################
#Create "row total" column
Tot <-c( round(mh[scen,yr]-ms[scen,yr], digits = 2),
round(-l_d[scen,yr]+l_s[scen,yr], digits = 2),
round(k[scen,yr], digits = 2),
round(-mh[scen,yr], digits = 2),
round(k[scen,yr]-mh[scen,yr], digits = 2)
)
#Create table of results
Tot_BS<-as.data.frame(Tot,row.names=rownames)
#Print firms column
kable(Tot_BS)
################################################################################
#Create BS matrix
BS_Matrix<-cbind(H_BS,F_BS,B_BS,Tot_BS)
kable(BS_Matrix) #Unload kableExtra to use this
################################################################################
################################################################################
#Create row names for TFM
rownames<-c( "Consumption",
"Investment",
"Production",
"Wages",
"Depreciation",
"Interests on loans",
"Interests on deposits",
"Change in loans",
"Change in deposits",
"Column total")
################################################################################
#Create households aggregates
H <-c( round(-c_d[scen,yr], digits = 2),
"",
"",
round(wb_d[scen,yr], digits = 2),
"",
"",
round(rm[scen,yr-1]*mh[scen,yr-1], digits = 2),
"",
round(-mh[scen,yr]+mh[scen,yr-1], digits = 2),
round(-c_d[scen,yr]+wb_d[scen,yr]+rm[scen,yr-1]*mh[scen,yr-1]-mh[scen,yr]+mh[scen,yr-1], digits = 2)
)
#Create table of results
H_TFM<-as.data.frame(H,row.names=rownames)
#Print firms column
kable(H_TFM)
################################################################################
#Create firms (current) aggregates
Fc <-c( round(c_s[scen,yr], digits = 2),
round(i_d[scen,yr], digits = 2),
paste("[",round(y[scen,yr], digits = 2),"]"),
round(-wb_s[scen,yr], digits = 2),
round(-da[scen,yr], digits = 2),
round(-rl[scen,yr-1]*l_d[scen,yr-1], digits = 2),
"",
"",
"",
round(c_s[scen,yr]+i_d[scen,yr]-wb_s[scen,yr]-da[scen,yr]-rl[scen,yr-1]*l_d[scen,yr-1], digits = 2)
)
#Create table of results
Fc_TFM<-as.data.frame(Fc,row.names=rownames)
#Print firms column
kable(Fc_TFM)
################################################################################
#Create firms (capital) aggregates
Fk <-c( "",
round(-i_d[scen,yr], digits = 2),
"",
"",
round(da[scen,yr], digits = 2),
"",
"",
round(l_d[scen,yr]-l_d[scen,yr-1], digits = 2),
"",
round(-i_d[scen,yr]+da[scen,yr]+l_d[scen,yr]-l_d[scen,yr-1], digits = 2)
)
#Create table of results
Fk_TFM<-as.data.frame(Fk,row.names=rownames)
#Print firms column
kable(Fk_TFM)
################################################################################
#Create banks aggregates
B <-c( "",
"",
"",
"",
"",
round(rl[scen,yr-1]*l_s[scen,yr-1], digits = 2),
round(-rm[scen,yr-1]*ms[scen,yr-1], digits = 2),
round(-l_s[scen,yr]+l_s[scen,yr-1], digits = 2),
round(ms[scen,yr]-ms[scen,yr-1], digits = 2),
round(rl[scen,yr-1]*l_s[scen,yr-1]-rm[scen,yr-1]*ms[scen,yr-1]+
-l_s[scen,yr]+l_s[scen,yr-1]+ms[scen,yr]-ms[scen,yr-1], digits = 2)
)
#Create table of results
B_TFM<-as.data.frame(B,row.names=rownames)
#Print firms column
kable(B_TFM)
################################################################################
#Create "row total" column
Tot <-c(round(c_d[scen,yr]-c_s[scen,yr], digits = 2),
round(i_d[scen,yr]-i_s[scen,yr], digits = 2),
"",
round(wb_d[scen,yr]-wb_s[scen,yr], digits = 2),
round(-da[scen,yr]+af[scen,yr], digits = 2),
round(-rl[scen,yr-1]*l_d[scen,yr-1]+rl[scen,yr-1]*l_s[scen,yr-1], digits = 2),
round(rm[scen,yr-1]*mh[scen,yr-1]-rm[scen,yr-1]*ms[scen,yr-1], digits = 2),
round((l_d[scen,yr]-l_d[scen,yr-1])-(l_s[scen,yr]-l_s[scen,yr-1]), digits = 2),
round(-(mh[scen,yr]-mh[scen,yr-1])-(ms[scen,yr]-ms[scen,yr-1]), digits = 2),
round(wb_d[scen,yr]-wb_s[scen,yr]-da[scen,yr]+af[scen,yr]+
-rl[scen,yr-1]*l_d[scen,yr-1]+rl[scen,yr-1]*l_s[scen,yr-1]+
rm[scen,yr-1]*mh[scen,yr-1]-rm[scen,yr-1]*ms[scen,yr-1]+
(l_d[scen,yr]-l_d[scen,yr-1])-(l_s[scen,yr]-l_s[scen,yr-1])+
-(mh[scen,yr]-mh[scen,yr-1])-(ms[scen,yr]-ms[scen,yr-1]), digits = 2)
)
#Create table of results
Tot_TFM<-as.data.frame(Tot,row.names=rownames)
#Print firms column
kable(Tot_TFM)
################################################################################
#Create TFM matrix
TFM_Matrix<-cbind(H_TFM,Fc_TFM,Fk_TFM,B_TFM,Tot_TFM)
kable(TFM_Matrix) #Unload kableExtra to use this
################################################################################
################################################################################
#Create html and latex tables
#Upload libraries
library(kableExtra)
#Create captions
caption1 <- paste("Table 1. Balance sheet of Model PC in period", yr, "under scenario", scen)
caption2 <- paste("Table 2. Transactions-flow matrix of Model PC in period ",yr, "under scenario", scen)
#Create html table for BS
BS_Matrix %>%
kbl(caption=caption1,
format= "html",
#format= "latex",
col.names = c("Households","Firms","Banks","Row total"),
align="r") %>%
kable_classic(full_width = F, html_font = "helvetica")
#Create html table for TFM
TFM_Matrix %>%
kbl(caption=caption2,
format= "html",
#format= "latex",
col.names = c("Households","Firms (current)","Firms (capital)","Banks","Row total"),
align="r") %>%
kable_classic(full_width = F, html_font = "helvetica")