I’m a novice at using Dynare and I’d greatly appreciate any suggestions you might have regarding this possibly simple problem. I’d like to use a standard matlab function (nthroot), but Dynare doesn’t support it. I want to calculate an odd number root of a negative number (for example (-1)^(1/3)), but typing (-1)^(1/3) gives 0.5+0.0866i. To get -1, I need to use the nthroot function. So I can I use it in Dynare?
I tried following the instructions in the Dynare guide by creating a function called root which uses nthroot to do the calculation, and declared root in the mod file with “external_function(name = root,nargs = 3);” before using the function in one of the model equations. However I got this error “terminate called after throwing an instance of 'ExternalFunctionNode::UnknownFunctionNameAndArgs’”.
Attached are the mod and m files. The function is declared after the block of parameters, and it’s the last model equation (taud = root((d(-1)/(p_N^(1-gamma))),(k1/k2),tau) that uses the root function.
Thank you in advance for your help!
root.m (60 Bytes)
basicmodel3.mod (3.73 KB)
There has been a bug related to external functions in 4.4.2. Please try the most recent unstable version and report back.
Hello Prof. Pfeifer,
Thank you for the reply. I tried the same codes with the unstable version 4.4_2013-10-31 for Mac, and it still isn’t working without giving an error message to indicate the cause (model diagnostics did not return anything). Below are the output. Could there be syntactical errors in my attempt to declare the external function? I tried following the manual. Anything suggestion would be greatly appreciated! Thank you!
“/Applications/Dynare/4.4_2013-10-31/matlab/dynare_m” basicmodel3.mod: Bus error
Starting Dynare (version 4.4-unstable).
Starting preprocessing of the model file …
Found 14 equation(s).
Computing static model derivatives:
- order 1
Computing dynamic model derivatives:
- order 1
- order 2
Error using dynare (line 141)
DYNARE: preprocessing failed
Thank you very Houtan.
I have OS X 10.8.5, but we ended up compiling Dynare on a cluster and now the external function is working. However, Dynare cannot find the steady state, it’s giving the following error whenever I try to take a root of greater than 1 with the nthroot external function:
Error using print_info (line 74)
Impossible to find the steady state. Either the model doesn’t have a steady state, there are
an infinity of steady states, or the guess values are too far from the solution
Is that because there’s still something wrong with the external function, or because one of my equations is wrong? I attached the mod file.
Thank you so much, I really appreciate your help!
basicmodel3.mod (3.78 KB)
It seems you just need to provide better starting values. If you put resid before steady you will see that particularly equation 9 has a big residual.