Added a welfare benefit, now need to find potential abuser

I added a welfare benefit to my model, and it seems to be working well. In general, adversely shocked agents sometimes need a little help to survive when they are at the end of their rope, and their modest asks are easily satisfied. In my first tests, the aggregate benefit costs less than 5% (not 2%, alas! And with other changes, no longer 25%) of the pension scheme. When they need it, the help agents need tends to range of 10% of a year’s wages.

However, while solving the GE, there is one iteration where one(?) agent makes a claim that’s 5x-10x larger than normal. I want to track them down. They question is how to do so most efficiently.

I have the receipts:

AgeConditionalStats=LifeCycleProfiles_FHorz_Case1(StationaryDist.household,Policy.household,CFnsToEvaluate,Parameters,[],n_d.household,n_a.household,n_z.household,N_j.household,d_grid.household,a_grid.household,z_grid.household,PType_Options(simoptions,Names_i,ii));
[max_benefit,max_benefit_J]=max(AgeConditionalStats.BenefitNeeded.Maximum);

So I know the total I’m looking for (max_benefit) and the age of the suspect (max_benefit_J). But what would be the cheapest and easiest way to find the index in the matrix (or the parameter values) that yielded such a large BenefitNeeded?

I’m all for giving people what they need, but if there’s a bug in my code, I want to fix it!

If you set heteroagentoptions.verbose=2 it shows the parameter before (rather than at the end of) each iteration. Once you see the parameter values you can just run the ValueFnIter, StationaryDist and AllStats or AgeConditionalStats or ValuesOnGrid to see where it happens.

[You might not need =2, =1 will do the trick if the GE is not erroring when this happens]

What I found is that somehow the StationaryDist sometimes had non-zero weight at the edge case where labor=0 and agej=7. I modified the benefits program to not give benefits to agents whose labor offer was zero, and this seems to have fixed my problem.

Somehow my ReturnFn was favoring zero labor participation in certain benefits case. Once I disallowed labor=0 as a benefit condition, the max benefit dropped from more than 2.5 to less than 0.5, which in this case is a reasonable result.