# Conditional restrictions on agent distribution stats

**URL:** <https://discourse.vfitoolkit.com/t/conditional-restrictions-on-agent-distribution-stats/294>\
**Category:** Uncategorized\
**Created:** [July 20, 2024, 10:09pm UTC](https://discourse.vfitoolkit.com/t/conditional-restrictions-on-agent-distribution-stats/294 "2024-07-20T22:09:03Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)\
**Post date:** [July 22, 2024, 4:25am UTC](https://discourse.vfitoolkit.com/t/conditional-restrictions-on-agent-distribution-stats/294/4 "2024-07-22T04:25:07Z")

</div>

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.

---

_[View the full topic](https://discourse.vfitoolkit.com/t/conditional-restrictions-on-agent-distribution-stats/294)._
