function AgeConditionalStats=LifeCycleProfiles_FHorz_Case1_PType(StationaryDist, Policy, FnsToEvaluate, Parameters,n_d,n_a,n_z,N_j,Names_i,d_grid, a_grid, z_grid, simoptions)
% Allows for different permanent (fixed) types of agent.
% See ValueFnIter_PType for general idea.
%
% simoptions.verbose=1 will give feedback
% simoptions.verboseparams=1 will give further feedback on the param values of each permanent type
%
% Rest of this description describes how those inputs not already used for
% ValueFnIter_PType or StationaryDist_PType should be set up.
%
% jequaloneDist can either be same for all permanent types, or must be passed as a structure.
% AgeWeightParamNames is either same for all permanent types, or must be passed as a structure.
%
% The stationary distribution be a structure and will contain both the
% weights/distribution across the permenant types, as well as a pdf for the
% stationary distribution of each specific permanent type.
%
% How exactly to handle these differences between permanent (fixed) types
% is to some extent left to the user. You can, for example, input
% parameters that differ by permanent type as a vector with different rows f
% for each type, or as a structure with different fields for each type.
%
% Any input that does not depend on the permanent type is just passed in
% exactly the same form as normal.
% Names_i can either be a cell containing the 'names' of the different
% permanent types, or if there are no structures used (just parameters that
% depend on permanent type and inputted as vectors or matrices as appropriate; note that this cannot be done for
% vfoptions, simoptions, etc as it then becomes impossible to tell that the vector/matrix is because of PType and not something else)
% then Names_i can just be the number of permanent types (but does not have to be, can still be names).
if iscell(Names_i)
N_i=length(Names_i);
else
N_i=Names_i; % It is the number of PTypes (which have not been given names)
Names_i={'ptype001'};
for ii=2:N_i
if ii<10
Names_i{ii}=['ptype00',num2str(ii)];
elseif ii<100
Names_i{ii}=['ptype0',num2str(ii)];
elseif ii<1000
Names_i{ii}=['ptype',num2str(ii)];
end
end
end
computeForThesei=ones(N_i,1); % Used to omit the infinite horizon PTypes from computations (a message is printed to say they are being ignored)
% Set default of grouping all the PTypes together when reporting statistics
if ~exist('simoptions','var')
simoptions.groupptypesforstats=0;
simoptions.ptypestorecpu=0; % GPU memory is limited, so switch solutions to the cpu. Off by default.
simoptions.verbose=0;
simoptions.verboseparams=0;
simoptions.nquantiles=20; % by default gives ventiles
if isstruct(N_j)
for ii=1:N_i
if isfinite(N_j.(Names_i{ii}))
simoptions.agegroupings.(Names_i{ii})=1:1:N_j.(Names_i{ii});
else % Infinite horizon
computeForThesei(ii)=0;
end
end
else
simoptions.agegroupings=1:1:N_j; % by default does each period seperately, can be used to say, calculate gini for age bins
end
simoptions.npoints=100; % number of points for lorenz curve (note this lorenz curve is also used to calculate the gini coefficient
simoptions.tolerance=10^(-12); % Numerical tolerance used when calculating min and max values.
simoptions.agejshifter=0; % Use when different PTypes have different initial ages (will be a structure when actually used)
else
if ~isfield(simoptions,'groupptypesforstats')
simoptions.groupptypesforstats=0;
end
if ~isfield(simoptions,'ptypestorecpu')
simoptions.ptypestorecpu=0; % GPU memory is limited, so switch solutions to the cpu. Off by default.
end
if ~isfield(simoptions,'verboseparams')
simoptions.verboseparams=100;
end
if ~isfield(simoptions,'verbose')
simoptions.verbose=100;
end
if isfield(simoptions,'nquantiles')==0
simoptions.nquantiles=20; % by default gives ventiles
end
if isfield(simoptions,'agegroupings')==0
if isstruct(N_j)
for ii=1:N_i
if isfinite(N_j.(Names_i{ii}))
simoptions.agegroupings.(Names_i{ii})=1:1:N_j.(Names_i{ii});
else % Infinite horizon
computeForThesei(ii)=0;
end
end
else
simoptions.agegroupings=1:1:N_j; % by default does each period seperately, can be used to say, calculate gini for age bins
end
end
if isfield(simoptions,'npoints')==0
simoptions.npoints=100; % number of points for lorenz curve (note this lorenz curve is also used to calculate the gini coefficient
elseif simoptions.npoints==0
error('simoptions.npoints must be a positive (non-zero) integer')
end
if isfield(simoptions,'tolerance')==0
simoptions.tolerance=10^(-12); % Numerical tolerance used when calculating min and max values.
end
if isfield(simoptions,'agejshifter')==0
simoptions.agejshifter=0; % Use when different PTypes have different initial ages (will be a structure when actually used)
end
end
if isstruct(simoptions.agegroupings)
ngroups=length(simoptions.agegroupings.(Names_i{ii}));
else
ngroups=length(simoptions.agegroupings);
end
maxngroups=max(ngroups(isfinite(ngroups)));
if isstruct(simoptions.agejshifter) % if using agejshifter
tempagejshifter=simoptions.agejshifter;
simoptions=rmfield(simoptions,'agejshifter');
simoptions.agejshifter=zeros(N_i,1);
for ii=1:N_i
simoptions.agejshifter(ii)=tempagejshifter.(Names_i{ii});
end
simoptions.agejshifter=simoptions.agejshifter-min(simoptions.agejshifter); % put them all relative to the minimum
elseif length(simoptions.agejshifter)==1 % not using agejshifter
simoptions.agejshifter=zeros(N_i,1);
else % have inputed as a vector
simoptions.agejshifter=simoptions.agejshifter-min(simoptions.agejshifter); % put them all relative to the minimum
end
% You cannot use agejshifter together with any age grouping other than just every period
if max(simoptions.agejshifter)>0 && defaultagegroupings==0
error('You cannot use agejshifter together with any age grouping other than the default (each period seperately)')
end
if isstruct(simoptions.experienceasset)
error('Have not yet implemented handling when some agents use experience asset and others do not')
elseif simoptions.experienceasset==1
% Just rejig the decision variables and send off as a Case2
n_d=[n_d,n_a(1:end-1)]; % Note: the decisions are all standard decisions, plus all the next period endogenous states except for the experience asset
d_grid=[d_grid;a_grid(1:sum(n_a(1:end-1)))];
AgeConditionalStats=LifeCycleProfiles_FHorz_Case2_PType(StationaryDist,Policy,FnsToEvaluate,Parameters,n_d,n_a,n_z,N_j,Names_i,d_grid,a_grid,z_grid,simoptions);
return
end
% Set default of grouping all the PTypes together when reporting statistics
% AllStats reports both
% simoptions.groupptypesforstats=0;
% and
% simoptions.groupptypesforstats=1;
%% Drop anything that is infinite horizon and print out a message to say so
if any(computeForThesei==0)
N_i=sum(computeForThesei);
Names_i2=Names_i;
Names_i=cell(N_i,1);
ii=0;
for ii2=1:length(computeForThesei)
if computeForThesei(ii2)==1
ii=ii+1;
Names_i{ii}=Names_i2{ii2};
else % tell the user about it
fprintf(['LifeCycleProfiles_FHorz_Case1_PType: Ignoring the ', num2str(ii2), '-th PType, ',Names_i2{ii2}, ' because it is infinite horizon \n']);
end
end
% Eliminate any no longer relevant functions from FnsToEvaluate (those which are only used for infinite horizon)
FnsToEvalNames=fieldnames(FnsToEvaluate);
FnsToEvaluate2=FnsToEvaluate;
clear FnsToEvaluate
for ff=1:length(fieldnames(FnsToEvaluate2))
i
没有合适的资源?快使用搜索试试~ 我知道了~
VFIToolkit-matlab.zip
共625个文件
m:615个
directory:6个
md:2个
0 下载量 62 浏览量
2023-08-17
14:48:37
上传
评论
收藏 1.44MB ZIP 举报
温馨提示
使用价值函数迭代的宏观经济模型 Matlab 工具包
资源推荐
资源详情
资源评论
收起资源包目录
VFIToolkit-matlab.zip (625个子文件)
.directory 121B
.directory 121B
.directory 121B
.directory 121B
.directory 121B
.directory 120B
LICENSE 34KB
LICENSE 1KB
LifeCycleProfiles_FHorz_Case1_PType.m 119KB
cmaes_vfitoolkit.m 119KB
CreateReturnFnMatrix_Case1_Disc_Par2e.m 101KB
CreateReturnFnMatrix_Case1_ExpAsset_Disc_Par2e.m 90KB
LifeCycleProfiles_FHorz_Case2_PType.m 85KB
EvalFnOnAgentDist_Grid_Case1e.m 74KB
CreateReturnFnMatrix_Case2_Disc_Par2e.m 70KB
ValueFnIter_Case2_FHorz_QuasiHyperbolic_raw.m 57KB
ValueFnIter_Case2_FHorz_AgeDepGrids_Dynasty_Par2_raw.m 49KB
EvalFnOnAgentDist_Grid_Case1_SDP.m 47KB
CreateReturnFnMatrix_Case1_Disc_Par2_SDP.m 46KB
TransitionPath_Case1_EntryExit_shooting.m 40KB
EstimateModel.m 39KB
ValueFnIter_Case2_FHorz_AgeDepGrids_Par2_raw.m 39KB
TransitionPath_Case1_EntryExit_no_d_shooting.m 38KB
TransitionPath_Case1_EntryExit_subfn.m 37KB
TransitionPath_Case1_FHorz_PType.m 36KB
LifeCycleProfiles_FHorz_Case1.m 34KB
ValueFnIter_Case2_FHorz_nphi_Dynasty_Par2_raw.m 34KB
CreateReturnFnMatrix_Case1_Disc_Par2_LowMem2.m 34KB
CreatePhiaprimeMatrix_Case2_Disc_Par2.m 34KB
TransitionPath_Case1_EntryExit_no_d_subfn.m 33KB
ValueFnIter_Case1.m 33KB
ValueFnIter_Case3_FHorz_EpsteinZin_raw.m 33KB
ValueFnIter_Case2_FHorz_Dynasty_Par2_raw.m 33KB
ValueFnIter_Case2_FHorz_Par2_raw.m 31KB
ValueFnIter_Case3_FHorz_EpsteinZin_e_raw.m 30KB
TransitionPath_Case1_FHorz.m 30KB
ValueFnIter_Case1_FHorz.m 29KB
HeteroAgentStationaryEqm_Case1_FHorz_PType.m 28KB
SimPanelIndexes_FHorz_Case1.m 28KB
ValueFnIter_Case1_FHorz_QuasiHyperbolic_e_raw.m 27KB
ValueFnIter_Case1_FHorz_QuasiHyperbolic_nod_e_raw.m 26KB
HeteroAgentStationaryEqm_Case1_PType.m 26KB
EvalFnOnAgentDist_Inequality_FHorz_Case1_PType.m 26KB
ValueFnIter_Case1_EndoType_TPath_SingleStep_Refine2_raw.m 25KB
StationaryDist_FHorz_Case2_3_Iteration_e_raw.m 25KB
ValueFnIter_Case1_EndoType_Refine2.m 25KB
EvalFnOnAgentDist_AggVars_Case1.m 25KB
getIMFData.m 25KB
TransitionPath_Case1_EntryExit_no_d.m 25KB
ValueFnIter_Case1_FHorz_QuasiHyperbolic_raw.m 24KB
LifeCycleProfiles_FHorz_Case2_AgeDepGrids.m 24KB
TransitionPath_Case2.m 24KB
EstimateModel_DistanceFn.m 24KB
getHDRData.m 24KB
HeteroAgentStationaryEqm_PType.m 24KB
ValueFnIter_Case1_FHorz_EpsteinZin_e_raw.m 24KB
EvalFnOnAgentDist_AllStats_FHorz_Case1_PType.m 24KB
EvalFnOnAgentDist_Quantiles_FHorz_Case1_PType.m 23KB
TransitionPath_Case1_FHorz_e_shooting.m 23KB
ValueFnIter_Case1_FHorz_QuasiHyperbolic_nod_raw.m 23KB
ValueFnIter_Case1_FHorz_EpsteinZin_nod_e_raw.m 23KB
ValueFnIter_Case1_FHorz_SemiExo_e_raw.m 23KB
EvalFnOnAgentDist_LorenzCurve_FHorz_Case1_PType.m 23KB
ValueFnIter_Case2_FHorz_raw.m 23KB
StationaryDist_FHorz_Case1_SemiExo_Iteration_e_raw.m 22KB
ValueFnIter_Case1_Refine2.m 22KB
ValueFnIter_Case1_FHorz_EpsteinZin_raw.m 21KB
TransitionPath_Case1_FHorz_StockVar_shooting.m 21KB
TransitionPath_Case1_lowmem.m 21KB
TransitionPath_Case1_FHorz_StockVar_shooting_fastOLG.m 21KB
TransitionPath_Case1_shooting_endotype.m 21KB
SimPanelValues_Case1.m 21KB
StationaryDist_FHorz_Case2_AgeDepGrids_Dynasty_Iteration_raw.m 21KB
ValueFnIter_Case1_FHorz_ExpAssetSemiExo_nod1_raw.m 21KB
ValueFnIter_Case2_FHorz_Dynasty_raw.m 21KB
TransitionPath_Case1_FHorz_shooting.m 20KB
LifeCycleProfiles_FHorz_Case2.m 20KB
EvalFnOnAgentDist_Grid_Case1_withV.m 20KB
EvalFnOnTransPath_AggVars_Case1_FHorz_Direct.m 20KB
CreateReturnFnMatrix_Case1_Disc_Par2.m 20KB
TransitionPath_Case1_shooting.m 20KB
ValueFnIter_Case1_FHorz_EpsteinZin_nod_raw.m 20KB
LifeCycleProfiles_FHorz_Case1_noz.m 20KB
EvalFnOnAgentDist_Grid_Case1.m 20KB
EvalFnOnAgentDist_AllStats_Case1.m 20KB
StationaryDist_FHorz_Case2_AgeDepGrids_DynastyStoreP_Iter_raw.m 20KB
ValueFnIter_Case3_FHorz_raw.m 20KB
TransitionPath_Case1_no_d_lowmem.m 20KB
StationaryDist_FHorz_Case1_Iteration_e_raw.m 19KB
EvalFnOnTransPath_AggVars_Case2.m 19KB
ValueFnIter_Case1_FHorz_ExpAsset_raw.m 19KB
ValueFnIter_Case1_FHorz_ExpAsset_nod1_raw.m 19KB
TransitionPath_Case1_FHorz_shooting_noz.m 19KB
SimPanelValues_TransPath_Case1.m 19KB
ValueFnIter_Case1_FHorz_ExpAsset_e_raw.m 19KB
CreateReturnFnMatrix_Case1_ExpAsset_Disc_Par2.m 19KB
LifeCycleProfiles_TransPath_FHorz_Case1.m 19KB
ValueFnIter_Case1_FHorz_ExpAsset_nod1_e_raw.m 18KB
ValueFnIter_Case3_FHorz_e_raw.m 18KB
SimPanelIndexes_FHorz_Case1_semiz.m 18KB
共 625 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
paterWang
- 粉丝: 1066
- 资源: 1279
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功