Here is an example of how to do conditional restrictions in the Aiyagari (1994) model. The restriction in this example is rather contrived, but point is just to show how it is done.
Say we already have the function we want to evaluate,
FnsToEvaluate.Assets=@(aprime,a,z) a;
And we want to evaluate assets conditional on the shock z being greater than 1.
Then we just set up
simoptions.conditionalrestrictions.bigz=@(aprime,a,z) (z>1);
and then run AllStats
AllStats=EvalFnOnAgentDist_AllStats_Case1(StationaryDist, Policy, FnsToEvaluateIneq,Params, [],n_d, n_a, n_z, d_grid, a_grid,z_grid,simoptions);
Then the conditional mean is in
AllStats.bigz.Assets.Mean
and the conditional median is in
AllStats.bigz.Assets.Median
etc.
We can double check that this is doing the same thing by taking advantage of the fact that the conditional mean is easy to calculate in an alternative manner, specifically set up
FnsToEvaluate.test1=@(aprime,a,z) a*(z>1);
FnsToEvaluate.test2=@(aprime,a,z) (z>1);
Then run AllStats again, and calculate
AllStats.test1.Mean/AllStats.test2.Mean
and we can see that this gives exact same answer as when we used the simoptions.conditionalrestrictions approach. Obviously though this alternative only really works for conditional mean, and for things like the conditional median we need to take the simoptions.conditionalrestrictions approach.
Note, if you want to do something like, assets for people in lowest decile of income, you can run AllStats twice, the first time to get the cutoff for the income decile, and then use this to create a conditional restriction and call AllStats a second time.
Note, simoptions.conditionalrestrictions is currently only implemented in infinte-horizon models (not currently in finite-horizon models)
Just a note to myself, the code could be sped up by reusing Values across all the unconditional and then all the conditional restrictions, requires reorganizing the order of operations.