Conditional statistics

If I want to compute the average of a variable, for example assets, for working age people, I can write

FnsToEval.assets  = @(aprime,a,z) a; 
simoptions.conditionalrestrictions.working = @(aprime,a,z,agej,Jr) (agej<=Jr-1);

But say I have a more complicated setup where for some variables I want to compute the average conditional on z (z=0,1) and on working age (i.e. j<=Jr-1) but for other variables I want to compute simply the average conditional on health. Then I have to define multiple conditional restrictions, like

simoptions.conditionalrestrictions.z1 = @(aprime,a,z) (z==1);
simoptions.conditionalrestrictions.z2 = @(aprime,a,z) (z==2);
simoptions.conditionalrestrictions.working_z1 = @(aprime,a,z,agej,Jr) (agej<=Jr-1 && z==1);
simoptions.conditionalrestrictions.working_z2 = @(aprime,a,z,agej,Jr) (agej<=Jr-1 && z==2);

Is there a simpler method of doing this with the toolkit? Problem is that adding conditional restrictions slows down the computation quite a bit.

This is the only current approach to doing this.

The reason it is slower is likely because it is calculating the conditional restriction for everything in FnsToEval. I guess I could set up an option where you can tell it only do the conditional restriction for certain FnsToEval. You can kind of do this manually though just creating multiple FnsToEval and multiple simoptions, e.g.,
FnsToEval1.assets = @(aprime,a,z) a;
FnsToEval1.shock = @(aprime,a,z) z;
FnsToEval2.shock = @(aprime,a,z) z;
simoptions1.conditionalrestrictions.z1 = @(aprime,a,z) (z==1);
simoptions1.conditionalrestrictions.z2 = @(aprime,a,z) (z==2); simoptions2.conditionalrestrictions.working_z1 = @(aprime,a,z,agej,Jr) (agej<=Jr-1 && z==1);
simoptions2.conditionalrestrictions.working_z2 = @(aprime,a,z,agej,Jr) (agej<=Jr-1 && z==2);
AllStats1=EvalFnOnAgentDist_AllStats_FHorz_Case1(StationaryDist,Policy, FnsToEvaluate1,Parameters,FnsToEvaluateParamNames,n_d,n_a,n_z,N_j,d_grid,a_grid,z_grid,simoptions1)
AllStats2=EvalFnOnAgentDist_AllStats_FHorz_Case1(StationaryDist,Policy, FnsToEval2,Parameters,FnsToEvaluateParamNames,n_d,n_a,n_z,N_j,d_grid,a_grid,z_grid,simoptions2)
Notice that conditional on z I calculate ‘assets’ and ‘shock’, while conditional on working I only calculate assets. This will however only be faster if you have lots of FnsToEval but use some of the conditional restrictions for just a very small number of FnsToEval, because it is going to calculate the unconditional moments twice.

I will think about setting a way to declare simoptions where you can tell it only do the conditional restriction for certain FnsToEval. But my next two weeks of coding are already fully allocated.

1 Like