/
SIM_micro
145 lines (110 loc) · 4.44 KB
/
SIM_micro
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
#SIM with microfunded consumption, R version
#This code replicates model SIM but using individual consumption functions.
#Created by Marco Veronese Passarella, 4 October 2018
#Clear
rm(list=ls(all=TRUE))
#PERIODS (i= 1 to 65)
nPeriods=65
#NUMBER OF CONSUMERS (AGENTS)
Ni=10
#PARAMETERS
alpha0=0.6
beta0=0.4
theta=0.2
#MACROECONOMIC VARIABLES
#Income
y=matrix(data=0,nrow=1,ncol=nPeriods)
#Income
y_star=matrix(data=0,nrow=1,ncol=nPeriods)
#Consumption
c=matrix(data=0,nrow=1,ncol=nPeriods)
#Government expenditures
g=matrix(data=0,nrow=1,ncol=nPeriods)
#Taxes
t=matrix(data=0,nrow=1,ncol=nPeriods)
#Disposable income
yd=matrix(data=0,nrow=1,ncol=nPeriods)
#Cash demand
h_h=matrix(data=0,nrow=1,ncol=nPeriods)
#Cash supply
h_s=matrix(data=0,nrow=1,ncol=nPeriods)
#Labour
n=matrix(data=0,nrow=1,ncol=nPeriods)
#Wages
w=matrix(data=1,nrow=1,ncol=nPeriods)
#wealth
h=matrix(data=0,nrow=1,ncol=nPeriods)
#MICROECONOMIC VARIABLES
#Individual consumption of household i
c_i <- matrix(data=0,nrow=1,ncol=Ni)
#STATISTICS
#Average consumption across agents
mec <- matrix(data=0,nrow=1,ncol=nPeriods)
#Standard deviation of consumption across agents
sdc <- matrix(data=0,nrow=1,ncol=nPeriods)
#Define time
for (i in 2:nPeriods){
for (iterations in 1:20){
if (i>=15){
g[,i]=20 #Government expenditures passed from 0 to 20 after 15 periods
}
########################################################################################
#MICROFOUNDATIONS
#Individual consumption (same YD and H but different propensities to consume)
for (a in 1:Ni){
set.seed(a)
alpha = alpha0*(1+runif(1, min = -0.2, max = 0.2))
beta = beta0*(1+runif(1, min = -0.2, max = 0.2))
c_i[,a] = alpha*yd[,i]/Ni + beta*h_h[,i-1]/Ni }
#Note: different saving should entail different wealth!
#Aggregate consumption
c[,i] = sum(c_i)
#Mean consumption (across agents)
mec[,i] = mean(c_i)
#Standard deviation (across agents)
sdc[,i] = sd(c_i)
########################################################################################
#Determination of output
y[,i]= c[,i] + g[,i]
#Steady state solution
y_star[,i] = g[,i]/theta
#Determination of employment
n[,i] = y[,i]/w[,i]
#Tax payments
t[,i] = theta*w[,i]*n[,i]
#Disposable income derived from accounting identity
yd[,i] = w[,i]*n[,i] - t[,i]
#Increase in cash money, as a result of government deficit
h_s[,i] = h_s[,i-1] + g[,i] - t[,i]
#Increase in cash held by households
h_h[,i] = h_h[,i-1] + yd[,i] - c[,i]
}
}
#Figure 3.1
plot(y_star[,2:65],type="l",col="4",lwd=2,lty=1,font.main=1,cex.main=0.75,main="Figure 3.1: Impact of Y and Y* of a permanent increase in G",ylab = '',xlab = '',ylim=range(0,130))
lines(y[,2:65],type="l",lwd=2,lty=1,col="3")
par(xpd=TRUE)
legend(-2,-32,c("Steady state solution Y*","Income Y"), bty = 1, cex = 0.8, lty=c(1,1), lwd=c(2,2), col = c(4,3), box.lwd=0)
#Figure 3.2
plot(yd[,2:65],type="l",col="2",lwd=2,lty=1,font.main=1,cex.main=0.75,main="Figure 3.2: YD and C starting from scratch",ylab = '',xlab = '',ylim=range(0,90))
lines(c[,2:65],type="l",lwd=2,lty=1,col="3")
#abline(h=80,col=1,lty=1,lwd=1)
segments(x0=-3, # Value from x (initial)
x1=66, # Value to x (final)
y0=80, # Value from y (initial)
y1=80, # Value to y (final)
col=1,lty=2,lwd=1)
par(xpd=TRUE)
legend(-2,-22,c("Income YD","Consumption C"), bty = 1, cex = 0.8, lty=c(1,1), lwd=c(2,2), col = c(2,3), box.lwd=0)
#Figure 3.3
plot(h_h[,2:65],type="l",lwd=2,lty=1,col="4",font.main=1,cex.main=0.75,main="Figure 3.3: Wealth level and wealth change, starting from scratch",ylab = '',xlab = '')
par(new="TRUE")
plot(diff(h_h[,2:65]),type="l",lwd=2,lty=1,col="2",xlab = '',ylab = '',xaxt='n',yaxt='n')
axis(side=4)
par(xpd=TRUE)
legend(-2,-4,c("Wealth level H (money stock)","Household saving (the change in H)"), bty = 1, cex = 0.8, lty=c(1,1), lwd=c(2,2), col = c(4,2), box.lwd=0)
#Additional figure: individual consumption
plot(mec[,2:65],type="l",lwd=2,lty=1,col="1",font.main=1,cex.main=0.75,main="Figure M: Individual consumption",ylab = '',xlab = '',ylim=range(0,10))
lines(mec[,2:65]+2*sdc[,2:65],type="l",lwd=2,lty=2,col="2")
lines(mec[,2:65]-2*sdc[,2:65],type="l",lwd=2,lty=2,col="2")
legend("bottomright",c("Individual average","+/- 2 s.d."), bty = "n", cex = 0.8, lty=c(1,2), lwd=c(2,2), col = c(1,2), box.lwd=0)