|
575 | 575 | % Note, eliminating zero weights and unique() cannot be done yet as they need to be conditional on j
|
576 | 576 | % (otherwise lose the j dimension if I just apply them now)
|
577 | 577 |
|
578 |
| - |
579 | 578 | % Preallocate various things for the stats (as many will have jj as a dimension)
|
580 | 579 | % Stats to calculate and store in AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).
|
581 |
| - if simoptions.whichstats(1)==1 |
| 580 | + if simoptions_temp.whichstats(1)==1 |
582 | 581 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).Mean=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
583 | 582 | end
|
584 |
| - if simoptions.whichstats(2)==1 |
| 583 | + if simoptions_temp.whichstats(2)==1 |
585 | 584 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).Median=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
586 |
| - if simoptions.whichstats(1)==1 |
| 585 | + if simoptions_temp.whichstats(1)==1 |
587 | 586 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).RatioMeanToMedian=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
588 | 587 | end
|
589 | 588 | end
|
590 |
| - if simoptions.whichstats(3)==1 |
| 589 | + if simoptions_temp.whichstats(3)==1 |
591 | 590 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).Variance=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
592 | 591 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).StdDeviation=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
593 | 592 | end
|
594 |
| - if simoptions.whichstats(4)>=1 |
| 593 | + if simoptions_temp.whichstats(4)>=1 |
595 | 594 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).Gini=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
596 |
| - if simoptions.whichstats(4)<3 |
| 595 | + if simoptions_temp.whichstats(4)<3 |
597 | 596 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).LorenzCurve=nan(simoptions_temp.npoints,length(simoptions_temp.agegroupings),'gpuArray');
|
598 | 597 | end
|
599 | 598 | end
|
600 |
| - if simoptions.whichstats(5)==1 |
| 599 | + if simoptions_temp.whichstats(5)==1 |
601 | 600 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).Minimum=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
602 | 601 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).Maximum=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
603 | 602 | end
|
604 |
| - if simoptions.whichstats(6)>=1 |
| 603 | + if simoptions_temp.whichstats(6)>=1 |
605 | 604 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).QuantileCutoffs=nan(simoptions_temp.nquantiles+1,length(simoptions_temp.agegroupings),'gpuArray'); % Includes the min and max values
|
606 | 605 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).QuantileMeans=nan(simoptions_temp.nquantiles,length(simoptions_temp.agegroupings),'gpuArray');
|
607 | 606 | end
|
608 |
| - if simoptions.whichstats(7)==1 |
| 607 | + if simoptions_temp.whichstats(7)==1 |
609 | 608 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).MoreInequality.Top1share=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
610 | 609 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).MoreInequality.Top5share=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
611 | 610 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).MoreInequality.Top10share=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
|
617 | 616 | end
|
618 | 617 | if useCondlRest==1
|
619 | 618 | for rr=1:length(CondlRestnFnNames)
|
620 |
| - if simoptions.whichstats(1)==1 |
| 619 | + if simoptions_temp.whichstats(1)==1 |
621 | 620 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).Mean=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
622 | 621 | end
|
623 |
| - if simoptions.whichstats(2)==1 |
| 622 | + if simoptions_temp.whichstats(2)==1 |
624 | 623 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).Median=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
625 |
| - if simoptions.whichstats(1)==1 |
| 624 | + if simoptions_temp.whichstats(1)==1 |
626 | 625 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).RatioMeanToMedian=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
627 | 626 | end
|
628 | 627 | end
|
629 |
| - if simoptions.whichstats(3)==1 |
| 628 | + if simoptions_temp.whichstats(3)==1 |
630 | 629 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).Variance=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
631 | 630 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).StdDeviation=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
632 | 631 | end
|
633 |
| - if simoptions.whichstats(4)>=1 |
| 632 | + if simoptions_temp.whichstats(4)>=1 |
634 | 633 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).Gini=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
635 | 634 | if simoptions.whichstats(4)<3
|
636 | 635 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).LorenzCurve=nan(simoptions_temp.npoints,length(simoptions_temp.agegroupings),'gpuArray');
|
637 | 636 | end
|
638 | 637 | end
|
639 |
| - if simoptions.whichstats(5)==1 |
| 638 | + if simoptions_temp.whichstats(5)==1 |
640 | 639 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).Minimum=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
641 | 640 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).Maximum=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
642 | 641 | end
|
643 |
| - if simoptions.whichstats(6)>=1 |
| 642 | + if simoptions_temp.whichstats(6)>=1 |
644 | 643 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).QuantileCutoffs=nan(simoptions_temp.nquantiles+1,length(simoptions_temp.agegroupings),'gpuArray'); % Includes the min and max values
|
645 | 644 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).QuantileMeans=nan(simoptions_temp.nquantiles,length(simoptions_temp.agegroupings),'gpuArray');
|
646 | 645 | end
|
647 |
| - if simoptions.whichstats(7)==1 |
| 646 | + if simoptions_temp.whichstats(7)==1 |
648 | 647 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).MoreInequality.Top1share=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
649 | 648 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).MoreInequality.Top5share=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
650 | 649 | AgeConditionalStats.(CondlRestnFnNames{rr}).(FnsToEvalNames{ff}).(Names_i{ii}).MoreInequality.Top10share=nan(1,length(simoptions_temp.agegroupings),'gpuArray');
|
|
687 | 686 | SortedWeights_jj=SortedWeights_jj/sum(SortedWeights_jj(:)); % Normalize conditional on jj (is later renormalized ii weight before storing for groupstats)
|
688 | 687 |
|
689 | 688 | %% Use the full ValuesOnGrid_ii and StationaryDist_ii to calculate various statistics for the current PType-FnsToEvaluate (current ii and ff)
|
690 |
| - tempStats=StatsFromWeightedGrid(SortedValues_jj,SortedWeights_jj,simoptions.npoints,simoptions.nquantiles,simoptions.tolerance,1,simoptions.whichstats); % 1 is presorted |
| 689 | + tempStats=StatsFromWeightedGrid(SortedValues_jj,SortedWeights_jj,simoptions_temp.npoints,simoptions_temp.nquantiles,simoptions_temp.tolerance,1,simoptions_temp.whichstats); % 1 is presorted |
691 | 690 |
|
692 | 691 | % Now store these based on jj
|
693 |
| - if simoptions.whichstats(1)==1 |
| 692 | + if simoptions_temp.whichstats(1)==1 |
694 | 693 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).Mean(jj)=tempStats.Mean;
|
695 | 694 | end
|
696 |
| - if simoptions.whichstats(2)==1 |
| 695 | + if simoptions_temp.whichstats(2)==1 |
697 | 696 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).Median(jj)=tempStats.Median;
|
698 |
| - if simoptions.whichstats(1)==1 |
| 697 | + if simoptions_temp.whichstats(1)==1 |
699 | 698 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).RatioMeanToMedian(jj)=tempStats.RatioMeanToMedian;
|
700 | 699 | end
|
701 | 700 | end
|
702 |
| - if simoptions.whichstats(3)==1 |
| 701 | + if simoptions_temp.whichstats(3)==1 |
703 | 702 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).Variance(jj)=tempStats.Variance;
|
704 | 703 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).StdDeviation(jj)=tempStats.StdDeviation;
|
705 | 704 | end
|
706 |
| - if simoptions.whichstats(4)>=1 |
| 705 | + if simoptions_temp.whichstats(4)>=1 |
707 | 706 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).Gini(jj)=tempStats.Gini;
|
708 |
| - if simoptions.whichstats(4)<3 |
| 707 | + if simoptions_temp.whichstats(4)<3 |
709 | 708 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).LorenzCurve(:,jj)=tempStats.LorenzCurve;
|
710 | 709 | end
|
711 | 710 | end
|
712 |
| - if simoptions.whichstats(5)==1 |
| 711 | + if simoptions_temp.whichstats(5)==1 |
713 | 712 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).Minimum(jj)=tempStats.Minimum;
|
714 | 713 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).Maximum(jj)=tempStats.Maximum;
|
715 | 714 | end
|
716 |
| - if simoptions.whichstats(6)>=1 |
| 715 | + if simoptions_temp.whichstats(6)>=1 |
717 | 716 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).QuantileCutoffs(:,jj)=tempStats.QuantileCutoffs;
|
718 | 717 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).QuantileMeans(:,jj)=tempStats.QuantileMeans;
|
719 | 718 | end
|
720 |
| - if simoptions.whichstats(7)==1 |
| 719 | + if simoptions_temp.whichstats(7)==1 |
721 | 720 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).MoreInequality.Top1share(jj)=tempStats.MoreInequality.Top1share;
|
722 | 721 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).MoreInequality.Top5share(jj)=tempStats.MoreInequality.Top5share;
|
723 | 722 | AgeConditionalStats.(FnsToEvalNames{ff}).(Names_i{ii}).MoreInequality.Top10share(jj)=tempStats.MoreInequality.Top10share;
|
|
729 | 728 | end
|
730 | 729 |
|
731 | 730 | % For later, put the mean and std dev in a convenient place. These are instead done on jjageshifted (so they can be grouped across ptypes later)
|
732 |
| - if simoptions.whichstats(1)==1 |
| 731 | + if simoptions_temp.whichstats(1)==1 |
733 | 732 | MeanVec(ff,ii,jjageshifted)=tempStats.Mean;
|
734 | 733 | end
|
735 |
| - if simoptions.whichstats(3)==1 |
| 734 | + if simoptions_temp.whichstats(3)==1 |
736 | 735 | StdDevVec(ff,ii,jjageshifted)=tempStats.StdDeviation;
|
737 | 736 | end
|
738 | 737 | % Do the same with the minimum and maximum
|
739 |
| - if simoptions.whichstats(5)==1 |
| 738 | + if simoptions_temp.whichstats(5)==1 |
740 | 739 | minvaluevec(ff,ii,jjageshifted)=tempStats.Minimum;
|
741 | 740 | maxvaluevec(ff,ii,jjageshifted)=tempStats.Maximum;
|
742 | 741 | end
|
|
847 | 846 | end
|
848 | 847 | % Preallocate various things for the stats (as many will have jj as a dimension)
|
849 | 848 | % Stats to calculate and store in AgeConditionalStats.(FnsToEvalNames{ff})
|
| 849 | + % If we can put these together, it must be the case that whichstats is same for all permanent types |
| 850 | + if isstruct(simoptions.whichstats) |
| 851 | + simoptions.whichstats=simoptions.whichstats.(Names_i{1}); % just use the first one |
| 852 | + end |
850 | 853 | for ff=1:numFnsToEvaluate
|
851 | 854 | if simoptions.whichstats(1)==1
|
852 | 855 | AgeConditionalStats.(FnsToEvalNames{ff}).Mean=nan(1,N_j_max2,'gpuArray'); % Note: N_j_max2=length(simoptions.agegroupings) in basic setup, will be different when N_j or agejshifter varies by PType
|
|
0 commit comments