Consider a textbook Aiyagari model and suppose I’d like to compute median wealth. I can do the following:
First, I define a function that gives me “wealth”, and I call it “A”:
FnsToEvaluate.A = @(aprime,a,eps,theta) a;
Then, after computing the Stationary Distribution, I call the function:
AllStats=EvalFnOnAgentDist_AllStats_Case1(StationaryDist,Policy,FnsToEvaluate,...
Params,[],n_d,n_a,n_z,d_grid,a_grid,z_grid,simoptions);
Median wealth is then given by
AllStats.A.Median
So far so good. But suppose that I have a slightly more complicated model, say Aiyagari with an occupational choice (entrepreneur vs worker) and I would like to compute the median wealth conditional on being a worker and separately conditional on being an entrepreneur.
I used the following but it does not work (it always gives zero as a result)
% Assets owned by entrepreneurs
FnsToEvaluate.A_entre = @(aprime,a,eps,theta,r,w,vi,delta,lambda,gamma) a*f_Entre(aprime,a,eps,theta,r,w,vi,delta,lambda,gamma);
% Assets owned by workers
FnsToEvaluate.A_work = @(aprime,a,eps,theta,r,w,vi,delta,lambda,gamma) a*(1-f_Entre(aprime,a,eps,theta,r,w,vi,delta,lambda,gamma));
Note that in this case, f_Entre
is a function that returns 1 if entre, 0 if worker.
I think I understand what is going on: in the case above I set wealth equal to zero whenever the individual is NOT an entrepreneur. Since there are only 5-10% entre in the economy, then most wealth levels are set to 0 and therefore the median is also 0.
What I would like to do is to set the distribution, not the wealth values, equal to 0 if the guy is NOT an entre, and then renormalize. I did this manually and it works well but it would be great to do this automatically with the toolkit, if possible.
I had a look at the toolkit function EvalFnOnAgentDist_AllStats_Case1 and I was wondering if the part on “conditional restrictions”, around line 140, might help.
My manual code:
a_vec = repmat(a_grid,[1,n_z(1),n_z(2)]);
a_vec = a_vec(:);
StationaryDist_Entre = (pol_e==1).*StationaryDist;
StationaryDist_Entre = StationaryDist_Entre/sum(StationaryDist_Entre,"all");
StationaryDist_Work = (pol_e==0).*StationaryDist;
StationaryDist_Work = StationaryDist_Work/sum(StationaryDist_Work,"all");
A_entre_Median = quantili(a_vec(:),StationaryDist_Entre(:),0.50);
A_work_Median = quantili(a_vec(:),StationaryDist_Work(:),0.50);
and the function quantili (not included here but available on request) does the standard task of computing percentiles.