Parameter structure with non-scalar fields

The toolkit requires you to specify all model parameters in a structure that will be used by the return functions and by other toolkit functions.

If one of your parameters depends on age, then you can give the parameter as a vector and that’s handled internally by the toolkit, so e.g.

Params.kappa_j = [1, 1.2, 1.3 etc.]

But can you specify a parameter as a vector in cases other than age-dependent parameters? For example, suppose you have a model with an aggregate shock z2 that takes two values, expansion and recession. Then you have a parameter lambda for the job finding rate and lambda is higher if z2=1, where 1 is expansion. Can you write

Params.lambda = [0.3, 0.5]

and then access it in the Return Function as

Params.lambda(z) or

depending on z, where z denotes the index of z (slight abuse of notation)?

Or will the toolkit mistakely interpret lambda as an age-dependent parameter?

Thanks!!

Not possible. But you can do a work-around.

Quick bit of background. The way arrayfun() on the gpu works I would have to get the codes to recognise that the size of the parameter vector is the same length as the number of points in the exogenous shock and then move the parameter to this dimension. This is in the ‘too hard’ basket, as while it could easily be done for any specific dependence of the parameter on a dimension there are a huge number of variations on how it could be done that would all need to be implemented so for now I just avoid it (I have not thought of a way to write a generic code that intelligently figures out these variations; probably it could be done but is certainly not simple).

The work around would be, say we have parameter lambda that depends on z, and we also need the values of z itself (otherwise we would just make z_grid take the values of lambda). We can do this by setting z_grid=[0;1], then having four parameters, lambda1, lambda2, z1, z2 and wherever we use them we just write something like

if z==0
 lambda=lambda1;
 zval=z1;
elseif z==1
 lambda=lambda2;
 zval=z2;
end

Obviously this is slight overkill as I could just make the if statement based on the values of z, but it makes the idea clear.

[In your example lambda would only be misinterpreted as age-dependent if the size is N_j-by-1 (or 1-by-N_j). What you describe would instead just throw an error as the parameter lambda is neither scalar, nor age-dependent.]

Note: the above code could alternatively be done in a nice manner as

lambda=(z==0)*lambda1+(z==1)*lambda2;
zval=(z==0)*z1+(z==1)*z2;
1 Like

Remembered another option worth mentioning for when z takes lots of values, which is you can set lambda as a parameterized function of z (e.g lambda=b0+b1z+b2z^2). This is essentially doing the same as above, but in a way that is easier to extend to when z has many values.

1 Like

Thanks Robert, this is useful! I have seen this also applied to age-dependent parameters: sometimes the age-deterministic productivity profile is parameterized as a low order polynomial in age (second order is enough to get the hump-shape).

The toolkit is great in that it handles all age dependent parameters automatically; the other types of dependencies can be dealt with in an ad hoc fashion as you explain above