我有一个问题,我正在编写代码来计算模拟经济。但是,在运行模型时,编码包含四个错误。
该模型正在JuliaBox 1.0.3中运行
using Distributions
using DataFrames
# n = numero de familias
# t = numero de periodos para la simulacion
function inequality2(; n =5000 , t =15000 )
# Simulador de la economía e indices de desigualdad %%
# Parametros de Economia
gamma = 2; # Aversión al riesgo
delta = 0.057; # Depreciación de activos
betta = 0.99; # Factor de descuento
alfa = 0.47; # Elasticidad producto del capital en la producción
miz = 1; # Productividad en estado estacionario
roz = 0.75; # Ajuste de productividad
sigmaz = 0.013; # Volatilidad de la productividad
phi = 0.05; # Penalización de los hogares (activos)
rok = 0.7; # Parámetro inicial del movimiento de capital
mie = 1; # Empleo en estado estacionatio
roe = 0.7; # Ajuste del empleo
sigmae1 = 0.05; # Volatilidad del empleo de los hogares capitalistas
sigmae2 = 0.1; # Volatilidad del empelo de los hogares trabajadores
roez = 0.3; # Ciclicidad del empleo para los hogares trabajadores
lambda = 0.8; # Participación de los capitalistas en la economía
tau = 0; # Tasa de impuestos sobre la renta
ass = 31.7838916986589918973; # Desviación estandar de los activos
kss = lambda*ass; # Desviación estandar del capital
vtheta1 =0.1; # parametro 1 de la ecuación de movimiento de capital
vtheta2 =0.2; # parametro 2 de la ecuación de movimiento de capital
vtheta3 =0.3; # parametro 3 de la ecuación de movimiento de capital
vtheta4 =0.4; # parametro 4 de la ecuación de movimiento de capital
vtheta5 =0.5; # parametro 5 de la ecuación de movimiento de capital
n_lambda = trunc(Int, lambda ∗ n)
eshocks1= rand(Normal(0.0,sigmae1), n_lambda ,t); # choque sobre capitalistas
eshocks2= rand(Normal(0.0,sigmae2), n-n_lambda , t); # choque sobre capitalistas
zshocks1= rand(Normal(0.0, sigmaz), 1, t); # choque sobre capitalistas
# Variables:
a = ones(t,n);
c = ones(t,n);
y = ones(t,n);
k = ones(t);
w = ones(t);
r = ones(t);
z = ones(t);
l = ones(t);
e = ones(t,n);
# Valores iniciales de las variables:
a[1:2,1:n_lambda] = ass ;
a[1:t,(n_lambda+1):n]=0;
k[1:2] = lambda∗ass;
c[1:n_lambda,1] = (assˆalfa)∗(1-tau∗ alfa) - delta∗ass;
# Loop de Simulacion
for i = 2:(t-1)
k[i] = lambda∗mean(a[i,1:n_lambda]);
z[i] = (1-roz) + roz∗z[i-1]+zshocks[i];
l[i] = 1 + (1-lambda)∗roez*(z[i]-1)/(1-roe);
w[i] = (1-alfa)*z[i]∗((k[i])^(alfa))*l[i]^(-alfa);
r[i] = alfa∗z[i]*((k[i])^(alfa-1))*l[i]^(1-alfa);
for j = 1:n_lambda
e[i,j] = (1-roe) + roe∗e[i-1,j]+eshocks1[j,i];
a[i+1,j] = (vtheta1) + (vtheta2)*a[i,j]+ (vtheta3)*e[i,j] + (vtheta4)∗z[i] + (vtheta5)∗k[i];
c[i,j] = (1-tau)∗r[i]∗a[i,j] + w[i]∗e[i,j]+(1-delta )∗a[i,j] - a[i+1,j];
y[i,j] = (1-tau)∗r[i]∗a[i,j] + w[i]∗e[i,j];
end
for m = 1:(n - n_lambda)
e[i,m+n_lambda] = (1-roe ) + roe∗e[i-1,m+n_lambda]+ roez∗(z[i]-1) + eshocks2[m,i];
c[i,m+n_lambda] = w[i]∗e[i,m+n_lambda]+ tau∗r[i]∗k[i]/(1-lambda);
y[i,m+n_lambda] = c[i,m+n_lambda];
end
end
# Preparando las variables para el calculo del indice de Gini
asort = ones(t,n);
csort = ones(t,n);
ysort = ones(t,n);
for i = 1:(t-1)
asort[i,:]=sort(a[i,:]);
csort[i,:]=sort(c[i,:]);
ysort[i,:]=sort(y[i,:]);
end
# Calculo del Gini de la Riqueza
giniA = ones(t);
for i = 1:(t-1)
sum1 = 0.0;
sum2 = 0.0;
for j = 1:n
sum1 = (n+1-j)∗asort[i,j] + sum1;
sum2 = asort[i,j] + sum2;
end
giniA[i] = (n+1-2∗(sum1/sum2))/n;
end
# Calculo del Gini de Consumo
giniC = ones(t);
for i = 1:(t-1)
sum1 = 0;
sum2 = 0;
for j = 1:n
sum1 = (n+1-j)∗csort[i,j] + sum1;
sum2 = csort[i,j] + sum2;
end
giniC[i] = (n+1-2∗(sum1/sum2))/n;
end
# Calculo del Gini de la Renta
giniY = ones(t);
for i = 1:(t-1)
sum1 = 0;
sum2 = 0;
for j = 1:n
sum1 = (n+1-j)∗ysort[i,j] + sum1;
sum2 = ysort[i,j] + sum2;
end
giniY[i] = (n+1-2∗(sum1/sum2))/n;
end
# Calculo de la Curva de Lorenz ( lor )
sum = 0;
lor = ones(n);
atrim = asort[t-1,1:n];
atrim[1:350]=0;
for i = 1:n
sum = atrim[i] + sum;
end
cum = 0;
ind = 1:n;
for i = 1:n
cum = atrim[i]+cum;
lor[i] = cum/sum;
end
# Calculo del Coeficiente de Theil
theilY = ones(t);
for i = 1:(t-1)
ybar = mean(y[i,:]);
sum1 = 0;
for j = 1:n
sum1 = (y[i,j]/ybar)∗log(y[i,j]/ybar)+sum1;
end
theilY[i] = sum1/n;
end
# Calculo de Razoes de Porcentajes de Renda
ratio1 = ones(t);
r_n = trunc(Int, 0.9 ∗ n)
for i = 1:(t-1)
ratio1[i] = ysort[i,r_n]/ysort[i,n - r_n];
end
ratio2 = ones(t);
half_n = trunc(Int, 0.5 ∗ n)
for i = 1:(t-1)
ratio2[i] = ysort[i,r_n]/ ysort[i,half_n];
end
ratio3=ones(t);
for i = 1:(t-1)
ratio3[i] = ysort[i,half_n]/ ysort[i,n - r_n];
end
# Calculo de la Decomposicion del Coeficiente de Theil
theilC = ones(t);
ytotalC = ones(t);
for i = 1:(t-1)
ybarC = mean(y[i,1:n_lambda]);
sum1 = 0;
sum2 = 0;
for j = 1:n_lambda
sum1 = (y[i,j]/ybarC)∗log(y[i,j]/ybarC)+sum1;
sum2 = y[i,j] + sum2;
end
ytotalC[i] = sum2;
theilC[i] = sum1/(lambda∗n);
end
theilW = ones(t);
ytotalW = ones(t);
for i = 1:(t-1)
ybarW = mean(y[i,(1+n_lambda):n]);
sum1 = 0;
sum2 = 0;
for j = 1:(n - n_lambda)
sum1 = (y[i,j+n_lambda]/ybarW)∗log(y[i,j+n_lambda]/ybarW)+sum1;
sum2 = y[i,j+n_lambda]+sum2;
end
ytotalW[i] = sum2;
theilW[i] = sum1/((1-lambda)∗n);
end
ytotal = ones(t);
for i = 1:(t-1)
sum1 = 0;
for j = 1:n
sum1 = y[i,j] + sum1;
end
ytotal[i]=sum1;
end
shareC = ones(t);
shareW = ones(t);
meanC = ones(t);
meanW = ones(t);
meantotal = ones(t);
theilCW = ones(t);
for i = 1:(t-1)
shareC[i] = ytotalC[i]/ytotal[i];
shareW[i] = ytotalW[i]/ytotal[i];
meanC[i] = mean(y[i,1:n_lambda]);
meanW[i] = mean(y[i,(1+n_lambda):n]);
meantotal[i] = mean(y[i,:]);
theilCW[i] = shareC[i]∗theilC[i] + shareW[i]∗ theilW[i] + shareC[i]∗log(meanC[i]/ meantotal[i]) + shareW[i]∗log(meanW[i]/ meantotal[i]);
end
tab = DataFrame()
tab[ :periodos] = 15000
tab[ :familias] = 5000
tab[ :gamma] = gamma
tab[ :delta] = delta
tab[ :betta] = betta
tab[ :alfa] = alfa
tab[ :miz] = miz
tab[ :roz] = roz
tab[ :sigmaz] = sigmaz
tab[ :phi] = phi
tab[ :rok] = rok
tab[ :mie] = mie
tab[ :roe] = roe
tab[ :sigmae1] = sigmae1
tab[ :sigmae2] = sigmae2
tab[ :roez] = roez
tab[ :sigmae1] = sigmae1
tab[ :sigmae2] = sigmae2
tab[ :roez] = roez
tab[ :lambda] = lambda
tab[ :tau] = tau
tab[ :ass] = ass
tab[ :kss] = kss
tab[ :GiniY] = mean(giniY) # valor medio
tab[ :GiniC] = mean(giniC) # valor medio
tab[ :GiniA] = mean(giniA) # valor medio
tab[ :TheilY] = mean(theilY) # valor medio
tab[ :TheilC] = mean(theilC) # valor medio
tab[ :TheilW] = mean(theilW) # valor medio
tab[ :TheilCW] = mean(theilCW) # valor medio
tab[ :Ratio1] = mean(ratio1) # valor medio
tab[ :Ratio2] = mean(ratio2) # valor medio
tab[ :Ratio3] = mean(ratio3) # valor medio
tab[ :ShareC] = mean(shareC) # valor medio
tab[ :ShareW] = mean(shareW) # valor medio
tab[ :MeanC] = mean(meanC) # valor medio
tab[ :MeanW] = mean(meanW) # valor medio
tab[ :MeanTotal] = mean(meantotal) # valor medio
return tab
end
@time tab = inequality2(n =5000,t =15000);
writetable(”experimento.csv”,tab ,separator=’ ; ’)
运行模型时发生以下错误:
UndefVarError: ∗ not defined
Stacktrace:
[1] #inequality2#13(::Int64, ::Int64, ::Function) at ./In[11]:40
[2] (::getfield(Main, Symbol("#kw##inequality2")))(::NamedTuple{(:n, :t),Tuple{Int64,Int64}}, ::typeof(inequality2)) at ./none:0
[3] top-level scope at util.jl:156
[4] top-level scope at In[11]:297