I’m now working on a heterogeneous model with CDF to solve it. An endogenous variable x, whose steady state value is negative, turns positive under the exogenous shock. And I then calculate the following:

y = 0.5 * (1+erf(max(0,x)))

as the CDF. As the stochastic simulation fails in this case, I write it as:

[mcp=‘x > 1e-6’]
y = 0.5*(1+erf(x));

But in the deterministic simulation, I still meet with the error
“Error using erf
Input must be real and full.”
Why could this happen? Didn’t I just restrict x to be larger than 0 in mcp?
Thank you for your help!

I’ve attached my code below. The code is triggered by main00.m, and my question is in lines 102-108 of the mod file. Here, Z is the idiosyncratic tech of firms, and it follows log-normal distribution. Zdag is the cutoff under which some firms will fail. Under steady state, all firms are safe so Zdag is negative, whose numerator <0 and denominator >0.

And after we exert negative shock to RB, the numerator turns positive, so we can calculate nudag as the CDF of failing firms. (line 107 is calculated by internal function, line 108 is calculated by my self-defined external function, which is robust when input is negative ). As I ultimately need nudag = log(max(Zdag,0)), I have a mcp constraint. But if I use line 106-107, the code fails in evaluating steady-state by the error I meet above; if I use line 108 and simul, the simulation also fails as ‘NaN or Inf detected in the residuals or endogenous variables’. I also try to use Occbin, which fails again.

Yes, in the steady-state the Zdag will be negative. And I hope nudag is the CDF of log-normal distribution once Zdag>0. So actually I need nudag = 0.5\times (1+erf(\frac{\log(\max{(Zdag,1e-6)})-\mu_z}{\sigma\sqrt{2}})), and thus its steady-state will be 0.