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   Sean Lim <[email protected]>
To   [email protected]
Subject   Re: st: Optimize in Mata to solve for 2 unknwons. "initial values not feasible"
Date   Wed, 27 Jun 2012 03:31:30 +0100

Dear Austin Nichols,

Thanks for your time in considering my question and your reply. The
code I am using is based on the first one appearing on the link
http://www.stata.com/statalist/archive/2008-07/msg01027.html . He
firsts posts it here
http://www.stata.com/statalist/archive/2008-07/msg01026.html .

On the follow ups, I guess I did not, and did not think about it very
carefully (my apologies for that). There was a suggestion that I
reparamatrize the variables taking logs. I have not tried this but
will look into it.

I think I have found the asnwer to my quesitons in your the links you
posted. I apologize for being so rash in posting my questions- I need
not have bothered anyone to find what I was looking for.


Sean



On 26 June 2012 20:25, Austin Nichols <[email protected]> wrote:
> Sean Lim <[email protected]> :
> See also
> http://www.stata.com/statalist/archive/2009-01/msg01140.html
> http://www.stata.com/statalist/archive/2010-04/msg01113.html
>
> On Tue, Jun 26, 2012 at 3:23 PM, Austin Nichols <[email protected]> wrote:
>> 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/

*
*   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