Problem running hopenhayn1992

Dear Robert,

I am running Hopenhayn1992 and Hopenhayn&Rogerson1993 while studying with Chris Edmonds’ notes, and encountered errors in both. I couldn’t really figure out why, and it doesn’t seem to be the same problem as in previous posts. I must be missing something… Could you please help me fix this?

Error in Hopenhayn1992

Hopenhayn1992

vfoptions =

struct with fields:

          endogenousexit: 1
        keeppolicyonexit: 1
          ReturnToExitFn: @(a_val,s_val)0
ReturnToExitFnParamNames: {}

Error using gpuArray/subsasgn
Assignment has more non-singleton rhs dimensions than non-singleton subscripts.

Error in ValueFnIter_Case1_EndogExit_Par2_raw (line 40)
ExitPolicy(:,z_c)=((ReturnToExitMatrix_z-Vtemp)>0); % Assumes that when indifferent you do not exit.

Error in ValueFnIter_Case1_EndogExit (line 98)
[VKron, Policy,ExitPolicy]=ValueFnIter_Case1_EndogExit_Par2_raw(V0Kron, n_d,n_a,n_z, pi_z, DiscountFactorParamsVec, ReturnMatrix, ReturnToExitMatrix, vfoptions.howards,
vfoptions.maxhowards,vfoptions.tolerance, vfoptions.keeppolicyonexit);

Error in ValueFnIter_Case1 (line 168)
[V, Policy,ExitPolicy]=ValueFnIter_Case1_EndogExit(V0, n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, ReturnFn, Parameters, DiscountFactorParamNames, ReturnFnParamNames, vfoptions);

Error in Hopenhayn1992 (line 91)
[V,Policy,ExitPolicy]=ValueFnIter_Case1(n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, ReturnFn, Params, DiscountFactorParamNames, ReturnFnParamNames, vfoptions);

Error in HopenhaynRogerson1993_Example

HopenhaynRogerson1993_Example

simoptions =

struct with fields:

agententryandexit: 1
   endogenousexit: 1

Starting parallel pool (parpool) using the ‘local’ profile …
Connected to the parallel pool (number of workers: 6).

simoptions =

struct with fields:

    DistOfNewAgents: {'upsilon'}
    MassOfNewAgents: {'Ne'}
CondlProbOfSurvival: {'zeta'}
     endogenousexit: 0

Not enough input arguments.

Error in EvalFnOnAgentDist_AggVars_Case1 (line 18)
AggVars=EvalFnOnAgentDist_AggVars_Case1_Mass(StationaryDist.pdf,StationaryDist.mass, PolicyIndexes, FnsToEvaluate, Parameters, FnsToEvaluateParamNames, EntryExitParamNames, n_d, n_a, n_z, d_grid,
a_grid, z_grid, Parallel,simoptions);

Error in HopenhaynRogerson1993_Example (line 155)
AggVars=EvalFnOnAgentDist_AggVars_Case1(StationaryDist, Policy, FnsToEvaluate, Params, FnsToEvaluateParamNames, n_d, n_a, n_z, d_grid, a_grid, z_grid, simoptions,EntryExitParamNames);

Thank you

Dear hyunsk92,

have fixed the Hopenhayn & Rogerson (1993) example codes. Just update the example codes and the VFI Toolkit codes and they should work. Let me know if there is any issue.

I fixed the error you mentioned in Hopenhayn1992 but there is now a further error. Hopefully I can fix this one tomorrow.

Sorry about those. They were introduced as a result of some changes I made last week when uploading codes to allow for models that have a mix of both endogenous and exogenous exit.

Hi Robert,

Thank you very much! With regards to Hopenhayn & Rogerson(1993), the error above has been fixed, and I noticed another error appears in line 218 that a function is not recognized. It seems that in the Subcodes folder, only “CreateGridvals” & “CreateGridvals_Policy” m files exist and not the one below.

Unrecognized function or variable ‘CreateGridvals_Policy_IgnoringNan’.

Error in SimPanelValues_Case1 (line 132)
** [d_gridvals, aprime_gridvals]=CreateGridvals_Policy_IgnoringNan(Policy,n_d,n_a,n_a,n_z,d_grid,a_grid,1,2);**

Error in HopenhaynRogerson1993_Example (line 218)
SimPanel=SimPanelValues_Case1(StationaryDist,Policy,FnsToEvaluate,FnsToEvaluateParamNames,Params,n_d,n_a,n_z,d_grid,a_grid,z_grid,pi_z, simoptions, EntryExitParamNames);

Thank you very much again!

Have pushed ‘CreateGridvals_Policy_IgnoringNan’ to github. Apologies for missing this previously. (It was sitting on my harddrive.) Hopenhayn & Rogerson (1993) should now work right through :slight_smile: You will need to update VFI Toolkit to the latest.

I think Hopenhayn (1992) is working but haven’t had chance to do some proper testing and won’t until early next week (I have courses to teach in the meantime) will let you know but it should be fully working again by then (currently I am confident it works for some hardware combinations but not confident for others).

Found time. Both Hopenhayn (1992) and Hopenhayn & Rogerson (1993) examples should be fully working again (after accidently breaking them last week when makings some improvements to speed elsewhere).

Please let me know if you have any remaining issues when running them.

(PS. the Hopenhayn (1992) example runs usably fast on gpu, but slow on cpu. Note that code is actually solving a much more complicated DSGE version of the problem because it ignores some simplifying tricks that can be used to make most of the model shrink away.)

Thank you very much Robert!!

Now Hopenhayn(1992) works fine! With regards to Hopenhayn & Rogerson(1993), I’ve updated the master kit from github and see that the function has been added. I reset the path, but still I get the error

simoptions =

struct with fields:

agententryandexit: 1
   endogenousexit: 1
 keeppolicyonexit: 1
     entryinpanel: 0
       simperiods: 2
       numbersims: 10000

Unrecognized function or variable ‘CreateGridvals_Policy_IgnoringNan’.

Error in SimPanelValues_Case1 (line 132)
[d_gridvals, aprime_gridvals]=CreateGridvals_Policy_IgnoringNan(Policy,n_d,n_a,n_a,n_z,d_grid,a_grid,1,2);

Error in HopenhaynRogerson1993_Example (line 218)
SimPanel=SimPanelValues_Case1(StationaryDist,Policy,FnsToEvaluate,FnsToEvaluateParamNames,Params,n_d,n_a,n_z,d_grid,a_grid,z_grid,pi_z, simoptions, EntryExitParamNames);

I don’t understand why…

Dear hyunsk92,

this is likely an issue with matlab, rather than VFI toolkit itself.

First, double-check that you do have the file. Wherever on your harddrive you put VFI toolkit the file ‘CreateGridvals_Policy_IgnoringNan.m’ should be in a folder called SubCodes
[ https://github.com/vfitoolkit/VFIToolkit-matlab/tree/master/SubCodes ]

To check if Matlab is seeing the file, try just pulling up help on it
help CreateGridvals_Policy_IgnoringNan

My suggestion for trying to fix if first just to make sure that VFI Toolkit and all subfolders are on the matlab path and then the ever reliable ‘restart the computer’. [If this doesn’t work, maybe some ‘desperate’ moves, like removing VFI Toolkit and subfolders from the matlab path, quit matlab, open matlab, add VFI Toolkit and subfolders to the matlab path.] There is no obvious reason why it would give this error if the function is on your harddrive and matlab can see it.

Hope that helps!

And thanks for your patience in letting me know about these. Nothing worse from my perspective that when a code doesn’t work and no-one tells me. :smiley:

Thank you very much again! :slight_smile: This is a great source for learning codes

Hi Robert,

There are still some problem I encountered when running the firmentryexitmodels.

Hopenhayn1992

vfoptions =

struct with fields:

parallel: 0

vfoptions =

struct with fields:

                parallel: 0
          endogenousexit: 1
        keeppolicyonexit: 1
          ReturnToExitFn: @(a,s)0
ReturnToExitFnParamNames: {}

Elapsed time is 1.188970 seconds.

simoptions =

struct with fields:

agententryandexit: 1
   endogenousexit: 1

Starting parallel pool (parpool) using the ‘Processes’ profile …
Connected to the parallel pool (number of workers: 2).
Error using Hopenhayn1992>@(d,aprime,a,z,alpha)z*(d^alpha)
Too many input arguments.

Error in EvalFnOnAgentDist_AggVars_Case1_Mass (line 146)
Values(ii)=FnsToEvaluate{i}(d_gridvals{j1+(j2-1)*N_a,:},aprime_gridvals{j1+(j2-1)*N_a,:},a_gridvals{j1,:},z_gridvals{j2,:},StationaryDistmass,FnToEvaluateParamsVec{:});

Error in EvalFnOnAgentDist_AggVars_Case1 (line 206)
AggVars=EvalFnOnAgentDist_AggVars_Case1_Mass(StationaryDist.pdf,StationaryDist.mass, PolicyIndexes, FnsToEvaluate, Parameters, FnsToEvaluateParamNames, EntryExitParamNames, n_d, n_a, n_z, d_grid, a_grid, z_grid, Parallel, simoptions);

Error in Hopenhayn1992 (line 167)
AggVars=EvalFnOnAgentDist_AggVars_Case1(StationaryDist, Policy, FnsToEvaluate, Params, , n_d, n_a, n_z, d_grid, a_grid, z_grid, , simoptions, EntryExitParamNames);

HopenhaynRogerson1993_Example

simoptions =

struct with fields:

agententryandexit: 1
   endogenousexit: 1
 keeppolicyonexit: 1

FAILED TO FIND PARAMETER agentmassError using HopenhaynRogerson1993_Example>@(aprime,a,z,agentmass,alpha)z*(aprime^alpha)
Too many input arguments.

Error in EvalFnOnAgentDist_AggVars_Case1_Mass (line 180)
Values(ii)=FnsToEvaluate{i}(aprime_gridvals{j1+(j2-1)*N_a,:},a_gridvals{j1,:},z_gridvals{j2,:},StationaryDistmass,FnToEvaluateParamsVec{:});

Error in EvalFnOnAgentDist_AggVars_Case1 (line 206)
AggVars=EvalFnOnAgentDist_AggVars_Case1_Mass(StationaryDist.pdf,StationaryDist.mass, PolicyIndexes, FnsToEvaluate, Parameters, FnsToEvaluateParamNames, EntryExitParamNames, n_d, n_a, n_z, d_grid, a_grid, z_grid, Parallel, simoptions);

Error in HopenhaynRogerson1993_Example (line 148)
AggVars=EvalFnOnAgentDist_AggVars_Case1(StationaryDist, Policy, FnsToEvaluate, Params, , n_d, n_a, n_z, d_grid, a_grid, z_grid, , simoptions,EntryExitParamNames);

RestucciaRogerson2008_Example
No vfoptions given, using defaults

simoptions =

struct with fields:

agententryandexit: 1
   endogenousexit: 1
 keeppolicyonexit: 1

Calculating price vector corresponding to the stationary eqm
Output argument “varargout{3}” (and possibly others) not assigned a value in the execution with “ValueFnIter_Case1”
function.

Error in HeteroAgentStationaryEqm_Case1_EntryExit_subfn (line 94)
[V,Policy,ExitPolicy]=ValueFnIter_Case1(n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, ReturnFn, Parameters, DiscountFactorParamNames, ReturnFnParamNames, vfoptions);

Error in HeteroAgentStationaryEqm_Case1_EntryExit>@(p)HeteroAgentStationaryEqm_Case1_EntryExit_subfn(p,n_d,n_a,n_s,pi_s,d_grid,a_grid,s_grid,ReturnFn,FnsToEvaluate,GeneralEqmEqns,Parameters,DiscountFactorParamNames,ReturnFnParamNames,FnsToEvaluateParamNames,GeneralEqmEqnParamNames,GEPriceParamNames,EntryExitParamNames,heteroagentoptions,simoptions,vfoptions) (line 102)
GeneralEqmConditionsFnOpt=@(p) HeteroAgentStationaryEqm_Case1_EntryExit_subfn(p, n_d, n_a, n_s, pi_s, d_grid, a_grid, s_grid, ReturnFn, FnsToEvaluate, GeneralEqmEqns, Parameters, DiscountFactorParamNames, ReturnFnParamNames, FnsToEvaluateParamNames, GeneralEqmEqnParamNames, GEPriceParamNames, EntryExitParamNames, heteroagentoptions, simoptions, vfoptions);

Error in fminsearch (line 201)
fv(:,1) = funfcn(x,varargin{:});

Error in HeteroAgentStationaryEqm_Case1_EntryExit (line 116)
[p_eqm_vec,GeneralEqmConditions]=fminsearch(GeneralEqmConditionsFnOpt,p0,minoptions);

Error in HeteroAgentStationaryEqm_Case1 (line 113)
[p_eqm,p_eqm_index, GeneralEqmConditions]=HeteroAgentStationaryEqm_Case1_EntryExit(n_d, n_a, n_z, n_p, pi_z, d_grid, a_grid, z_grid, ReturnFn, FnsToEvaluate, GeneralEqmEqns, Parameters, DiscountFactorParamNames, ReturnFnParamNames, FnsToEvaluateParamNames, GeneralEqmEqnParamNames, GEPriceParamNames, EntryExitParamNames, heteroagentoptions, simoptions, vfoptions);

Error in RestucciaRogerson2008_Example (line 246)
[p_eqm,p_eqm_index, GeneralEqmCondition]=HeteroAgentStationaryEqm_Case1(0, n_a, n_z, n_p, pi_z, , a_grid, z_grid, ReturnFn, FnsToEvaluate, GeneralEqmEqns, Params, DiscountFactorParamNames, , , , GEPriceParamNames,heteroagentoptions, simoptions, , EntryExitParamNames);

Could you please let me know how to fix these bugs, thanks!

Edward Wu

Sorry about that. I believe this is now fixed. Please update VFI Toolkit and try run again. Let me know if it still doesn’t work.

(The cpu codes (parallel=0) were not fully up to date for EvalFnOnAgentDist_AggVars_Case1_Mass, I rarely ever use anything except gpu (parallel=2) so only the gpu codes get run in all my tests.)

Dear Robert,

Thank you very much for your reply. I dowmload the late VFI Toolkit, but it still does not work well.

RestucciaRogerson2008_Example
No vfoptions given, using defaults

simoptions =

struct with fields:

agententryandexit: 1

Calculating price vector corresponding to the stationary eqm
Error using fieldnames
Invalid input argument of type ‘double’. Input must be a structure or a Java or COM
object.

Error in HeteroAgentStationaryEqm_Case1_EntryExit_subfn (line 146)
AggVarNames=fieldnames(AggVars); % Using GeneralEqmEqns as a struct presupposes using FnsToEvaluate (and hence AggVars) as a stuct

Error in HeteroAgentStationaryEqm_Case1_EntryExit>@(p)HeteroAgentStationaryEqm_Case1_EntryExit_subfn(p,n_d,n_a,n_s,pi_s,d_grid,a_grid,s_grid,ReturnFn,FnsToEvaluate,GeneralEqmEqns,Parameters,DiscountFactorParamNames,ReturnFnParamNames,FnsToEvaluateParamNames,GeneralEqmEqnParamNames,GEPriceParamNames,EntryExitParamNames,heteroagentoptions,simoptions,vfoptions) (line 102)
GeneralEqmConditionsFnOpt=@(p) HeteroAgentStationaryEqm_Case1_EntryExit_subfn(p, n_d, n_a, n_s, pi_s, d_grid, a_grid, s_grid, ReturnFn, FnsToEvaluate, GeneralEqmEqns, Parameters, DiscountFactorParamNames, ReturnFnParamNames, FnsToEvaluateParamNames, GeneralEqmEqnParamNames, GEPriceParamNames, EntryExitParamNames, heteroagentoptions, simoptions, vfoptions);

Error in fminsearch (line 201)
fv(:,1) = funfcn(x,varargin{:});

Error in HeteroAgentStationaryEqm_Case1_EntryExit (line 116)
[p_eqm_vec,GeneralEqmConditions]=fminsearch(GeneralEqmConditionsFnOpt,p0,minoptions);

Error in HeteroAgentStationaryEqm_Case1 (line 113)
[p_eqm,p_eqm_index, GeneralEqmConditions]=HeteroAgentStationaryEqm_Case1_EntryExit(n_d, n_a, n_z, n_p, pi_z, d_grid, a_grid, z_grid, ReturnFn, FnsToEvaluate, GeneralEqmEqns, Parameters, DiscountFactorParamNames, ReturnFnParamNames, FnsToEvaluateParamNames, GeneralEqmEqnParamNames, GEPriceParamNames, EntryExitParamNames, heteroagentoptions, simoptions, vfoptions);

Error in RestucciaRogerson2008_Example (line 246)
[p_eqm,p_eqm_index, GeneralEqmCondition]=HeteroAgentStationaryEqm_Case1(0, n_a, n_z, n_p, pi_z, , a_grid, z_grid, ReturnFn, FnsToEvaluate, GeneralEqmEqns, Params, DiscountFactorParamNames, , , , GEPriceParamNames,heteroagentoptions, simoptions, , EntryExitParamNames);

Best,

Edward Wu

Just to check I understand. The previous issue was about the Hopenhayn (1992) example. I updated it. And I am guessing from your post that it now works? But you are now reporting a different issue running Restuccia & Rogerson (2008) instead.

Is this correct?

Okay. Have just run Hopenhayn 1992 side by side on gpu and cpu and corrected the cpu version. Should work cleanly now. I am going to do the same for Restuccia & Rogerson 2008 soon. (update VFI Toolkit)

Dear Robert,

Sorry for making you confused. I try to run the three examples of Firm-Entry-Exit-Models. But due the cpu of my personal computer, the first two last more than one day, so I have to break them. I hope and now belive it will work when run on other platform. But, in running the third code, i.e. RestucciaRogerson2008_Example.m, I got the error warnings above.

best

Great! I just read your new reply. I will try it right now.

I have just updated both the Restuccia & Rogerson 2008 example and the toolkit. This should now work fine on cpu.

[Problem was a weird thing about how it deals with FnsToEvaluate being empty, for some reason this worked on gpu but not on cpu.]

I have just run all three examples of the firm entry/exit on my laptop, which does not have a gpu. Two were fast, but all should be measured in minutes (longest was hopenhayn and rogerson which took 10-20 minutes). On desktop with gpu all are done in a minute or two each.

Thanks for bringing both of those to my attention. Because I almost never run codes without a gpu I rarely notice if there is an error in the cpu versions.

Anyway, should now all be fixed and running nicely with cpu :slight_smile:

Dear Robert,

I am running Hopenhayn 1992 while studying with Chris Edmond’s notes and encountered that i can’t seem to resolve.

vfoptions =

struct with fields:

          endogenousexit: 1
        keeppolicyonexit: 1
          ReturnToExitFn: @(a,s)0
ReturnToExitFnParamNames: {}

Unrecognized field name “returnmatrix”.

Error in ValueFnIter_Case1_EndogExit (line 61)
if vfoptions.returnmatrix==0
^^^^^^^^^^^^^^^^^^^^^^
Error in ValueFnIter_Case1 (line 296)
[V, Policy,ExitPolicy]=ValueFnIter_Case1_EndogExit(V0, n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, ReturnFn, Parameters, DiscountFactorParamNames, ReturnFnParamNames, vfoptions);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in Hopenhayn1992 (line 92)
[V,Policy,ExitPolicy]=ValueFnIter_Case1(n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, ReturnFn, Params, DiscountFactorParamNames, , vfoptions);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I can’t move past line in the Hopehayn1992 file, and further attempts to address the code just give me more errors. I appreciate any help you can provide on this.

Kaitlin

Should work now. Update to latest toolkit version from github and also redownload the examples (you need to do both). Thanks for letting me know!

Unimportant background info: In version 0.1 you input the return fn as a matrix instead of a function. Somewhere around version 0.2 I added that the return fn could be a function. vfoptions.returnmatrix was a option so that you could input either the matrix or function. Nowadays though, no-one would ever want to input the matrix (because GPU is so good at turning fn into matrix, and the fn is so much easier to write for the user). So I have removed the vfoptions.returnmatrix option, helps keep the internal code cleaner. I had missed where it appeared in the firm entry/exit codes so have now cleaned this up.

1 Like