Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Optimize in Mata to solve for 2 unknwons. "initial values not feasible"


From   Austin Nichols <[email protected]>
To   [email protected]
Subject   Re: st: Optimize in Mata to solve for 2 unknwons. "initial values not feasible"
Date   Tue, 26 Jun 2012 15:23:13 -0400

Sean Lim <[email protected]> :
It's not clear to me which code by Thomas Jacobs you are referring to.
Did you read the follow-up?
http://www.stata.com/statalist/archive/2008-07/msg01029.html
See also
http://www.stata.com/help.cgi?mf_optimize#i_maxiter

On Tue, Jun 26, 2012 at 3:08 PM, Sean Lim <[email protected]> wrote:
> Dear Statalisters,
>
> I am trying to use optimize on Mata to numerically solve simultaneous
> equations with 2 unknowns. I am getting an error "initial values not
> feasible". I am using Stata 11.2 for Windows.
>
> I have this, based on code I found on statalist archives
> http://www.stata.com/statalist/archive/2008-07/msg01027.html by Thomas
> Jacobs. It is run on Mata:
>
> j=1
>
> T = st_data(j,"time_tomaturity")
> sqrtT = sqrt(T)
> rf= st_data(j,"rf3")
> F = st_data (j, "lag_tot_liab")
> E = st_data (j, "cur_mkt_cap")
> Evol = st_data (j, "market_cap_volatility")
> Avol = Evol/2
> Avalue = (E + F)
> c = (sqrtT, rf, E, Evol, F)
>
>        void Merton(todo, A, c, lnf, g, H)
>                        {
>                                d1=((ln(A[1]/c[5]))+(c[2]+0.5*(c[4]^2)*c[1]^2))/(A[2]*c[1])
>                                d2=d1-A[2]*c[1]
>                                f1=A[1]*normal(d1)- exp(-c[2]*c[1]^2)*c[5]*normal(d2)-c[3]
>                                f2=(A[1]/c[3])*normal(d1)*A[2]-c[4]
>                                lnf =(f1)^2 + (f2)^2
>                }
> while (j<=st_nobs()){
>                if (T!=.&rf!=.&F!=.&E!=.&Evol!=.) {
>
>                        S = optimize_init()
>                        optimize_init_evaluator(S, &Merton())
>                        optimize_init_evaluatortype(S, "d0")
>                        optimize_init_params(S, (Avalue,Avol))
>                        optimize_init_which(S, "min")
>                        optimize_init_argument(S,1,c)
>                        A = optimize(S)
>
>                        st_store(j, "value", A[1])
>                        st_store(j, "avol", A[2])
>
>                        j++
>
>                        if (j<=st_nobs()){
>                                T = st_data(j,"time_tomaturity")
>                                sqrtT = sqrt(T)
>                                rf= st_data(j,"rf3")
>                                F = st_data (j, "lag_tot_liab")
>                                E = st_data (j, "cur_mkt_cap")
>                                Evol = st_data (j, "market_cap_volatility")
>                                Avol = Evol/2
>                                Avalue = (E + F)
>                                c = (sqrtT, rf, E, Evol, F)
>                                }
>
>                        }
>                else {
>                        j++
>
>                        if (j<=st_nobs()){
>                                T = st_data(j,"time_tomaturity")
>                                sqrtT = sqrt(T)
>                                rf= st_data(j,"rf3")
>                                F = st_data (j, "lag_tot_liab")
>                                E = st_data (j, "cur_mkt_cap")
>                                Evol = st_data (j, "market_cap_volatility")
>                                Avol = Evol/2
>                                Avalue = (E + F)
>                                c = (sqrtT, rf, E, Evol, F)
>                                }
>
>                        }
>        }
>
>
> In short, I have a panel dataset, and would like to run the sovler for
> every observations (roughly24000). The code works fine except that
> every now there are problematic numerical values that have no solution
> or and error.
>
> Is there a way code so that it can use another variation of EVol for a
> starting value if initial values turn out to be infeasible? Or code so
> to tell the program to skip ahead to the next observation?
>
> I find that this happens after 10,000 ish iterations coming with the
> same (lack of) result. Is there a way to code a limit to the number of
> observations so the program moves on to solving for the next
> observation?
>
> Also, I am curious, what happens if after a large number of
> iterations, the equations are not solved. Does Mata give in a 'close'
> solution as a substitute?
>
> Thank you all for your time in reading this. I am new to using Mata so
> I will appreciate any comments that will provide me some direction.
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index