I am trying to simulate a model with bank runs (think Gertler-Kiyotaki, 2013) so my question is: how do I tell dynare to start in one economy in which a bank is operating and then, following a shock, transition to a new economy in which the bank doesn’t exist anymore? That is, following a large shock (and bank run) many of the equations are no longer valid. I can attempt to clarify my question if this is unclear…

Perhaps you define a new parameter, which stands in front of all equations, that hold for economy, say A.
Then if economy A is valid, the parameter has the value 1, and if the economy A is not valid anymore, then the parameter value has the value 0.

Then you can calculated the transiton with the initval and endval command of dynare, where you set in initval the paramter on 1 and in endval the paramter on 0.

So here’s the issue: a bank run occurs if the price is below some threshold, Q_t < Qbar_t, where Qbar_t is some time-varying threshold. In the original SS, this condition is violated so there is no bank run. Now, suppose there’s an unexpected shock so large that this condition holds. Using your suggestion, I would define a variable like Run = Qbar - Q, and then another variable RunInd = 1*(Run<0) (so it’s 1 as long as there is no run). I then multiply every bank equation by RunInd. Fine. I want it to be the case that once there is a run, all banks are wiped out forever so N (net worth), S (equity), A (liabilities) are all zero going forward forever. However, it will be the case that the price Q will eventually return to its original SS so in the long-run I think the Run variable I just defined will be negative, and hence RunInd=1. But doesn’t this mean that those bank equations will then return?

Define a variable “run”. Then use the initval and endval to do the following:

[code]
initval;
run = 1; %meaning your “bank equations” are valid
end;

endval;
run = 0; %meaning your “bank equations” are not valid
end;[/code]

Then dynare computes the transition from one steady state to the new steady state.
Or when you want to do it with a shock variabel. Define a var_exo Qbar_t, which switches its value between 1 and 0, by using an approximation of an indicator function.
An indicator function of the following form

Run = 1 if Q_t<Qbar_t
Run = 0 else
can be approximated by the following logistic function:
Run = 1/(1+exp(-10000(Qbar_t - Q_t))*

and Qbar_t then follows some specified exogenous process.
I hope this helps and I hope I understood your problem right.

Please clarify the exercise you are trying to do. Is it a stochastic or deterministic setup? In stochastic setup, the type of nonlinearity is very hard to deal with. If we are talking about a deterministic perfect foresight setup where everything is certain after the initial shock, you can really work with the initval-endval construct.

It’s deterministic in the sense that the run is completely unanticipated, so I understand now that the initval-endval construct should work. Below is a portion of the code (I realize everything below is in logs but I will get rid of those later).

In the original SS (before the run), all of these equations hold. To understand what I’m doing, everything in the EQUATIONS 1 block denotes equations for bank 1, anything in EQUATIONS 2 is for bank 2, and the final block is market clearing. Also, S, A, N, D are bank 1 balance sheet terms and Sprime, Aprime, Nprime are bank 2 balance sheet terms. Pre-run, both banks exist so all of these terms are nonzero. Post-run, bank 2 disappears so Sprime = Aprime = Nprime = 0. A run will occur under conditions I specified in a previous post.