If commands, using certain model equations depending on the realization of a productivity shock

I am working with a very basic stochastic two-country model with migration. There are productivity shocks that result in agents migrating to the relatively more productive sector (note that in this simple model, agents only move in one direction at a time). However, this means that I need Dynare to recognize that only certain equations should be used given certain realizations of the shock. That is, if a shock makes country 1 more desirable, I want Dynare to use the equations that govern migration to country 1, but if the shock makes country 2 more desirable, I want Dynare to use the equations that govern migration to country 2. I have seen a few papers that use Dynare in a migration setting, but they are scant on the programming details. Any sort of guidance would be greatly appreciated!

Dear Ben,

I don’t see how to do that in Dynare with the perturbation approach (to solve locally the stochastic model). But you can implement this in a perfect foresight model (and if you need to simulate time series you can consider the extended path approach). To do that you may use the inequality binary operators (> or <), and write a state dependent equation like this:

(HomeIsBetter>0)*( EXPRESSION ) + (1-(HomeIsBetter>0))*( ANOTHER EXPRESSION ) = 0 ;

where HomeIsBetter may be an exogenous or an endogenous variable, EPRESSION and ANOTHER EXPRESSION are expressions involving parameters, endogenous and exogenous variables (your two equations).

There is no unique representation of your problem (you can use other kind of conditions), and different representations may have different advantages numerically (i.e. Dynare may fail to find the solution for one representation but not for another which is logically equivalent). With this state dependent equation, we introduce a non differentiability in the model (as we would do with a positivity constraint)… So you may experience difficulties in finding the solution.

Note also that you can do that, in principle, on more than one equation.


Thanks Stephane, I appreciate the help. It looks like the closest way to achieve what I want is to use the add-on OccBin, which is not standard in Dynare as of now. Thanks again!


Dear Ben,

I do not know if OccBin is working with current stable (we have plans to integrate it in the official Dynare distribution). Alternatively you can use the extended path approach (which is implemented in Dynare). This approach is more general that the one considered in Occbin because you can have as many constraint as you want and we do not not rely on linearization of the model (accounting for the full nonlinearity of the model). The output of this approach is a time series of simulated endogenous variables. Obviously this comes at a cost: the extended path approach is more time consuming. A brief description of this description is given in these slides (starting page 47), more detailed explanations are available on my webpage.

Thank you for the information! I will look into it.