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: Nonlinear regression syntax
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Nonlinear regression syntax
Date
Sun, 20 Jan 2013 11:35:57 +0000
I don't understand what you have done. If "rg" is a parameter to be
estimated, as you said yesterday, then I don't see that you can feed
it to a -generate- statement.
I am lost on what your problem is precisely, as your story seems ever-shifting.
Nick
On Sun, Jan 20, 2013 at 6:52 AM, David Ashcraft
<[email protected]> wrote:
> Thanks Nick, Sorry for the late response. If I calculate the algebraic expression independently (outside the model) and use the calculated number as a variable for parameter estimation using OLS method may resolve my issue and I shall get the parameter estimates for all three variables. In Stata language:
>
> gen a= (rg*(1+exp(-gamma*(moveave-ci)))^-1)
> reg rx rg a gfc, robust
>
> Now I am not sure, if I do the above, would it resolve the nonlinearity? If it does not, what would you recommend as an alternative??
>
>
> David
>
>
> ----- Original Message -----
> From: Nick Cox <[email protected]>
> To: [email protected]
> Cc:
> Sent: Saturday, January 19, 2013 7:35:30 PM
> Subject: Re: st: Nonlinear regression syntax
>
> Thanks for this, but my answer is the same.
>
> {rg*(1+exp(-gamma*(moveave-ci)))^-1}
>
> is illegal, indeed meaningless, so far as -nl- is concerned.
>
> But
>
> nl (rx={rg}+{rg}*(1+exp(-gamma*(moveave-ci)))^-1}+{gfc})
>
> looks legal from what you say. It can be re-written, I think, as
>
> nl (rx={rg} * (1+ 1/(1+exp(-gamma*(moveave-ci)))+{gfc})
>
> leaving two parameters to estimate. I haven't read the paper you cite,
> but it seems to me your interest in a more complicated expression
> depending partly on parameter estimates is, as it were, downstream of
> this and the first job is estimating those parameters.
>
> -nl- often needs initial values for parameters to do a good job, or
> even to converge at all.
>
> Nick
>
> On Sat, Jan 19, 2013 at 3:18 PM, David Ashcraft
> <[email protected]> wrote:
>> Thanks Nick,
>>
>> when I said constant in the previous e-mail, I meant that the value of gamma and ci is fixed. however, both are defined as variables. I have generated both variables by following:
>>
>> Woodward, G., & Anderson, H. M. (2009). Does beta react to market conditions? Estimates of “bull” and “bear” betas using a nonlinear market model with an endogenous threshold parameter. Quantitative Finance, 9(8), 913–924. doi:10.1080/14697680802595643
>>
>>
>> In short gamma, ci, rg and moveave are variables. Complete algebraic expression that I want to solve is
>> {rg*(1+exp(-gamma*(moveave-ci)))^-1} where rg is multiplied with the inverse of the expression within parenthesis. I want to estimate three parameters: rg, algebraic expression and gfc
>>
>> if I don't use -nl- what would be the alternatives?
>> Regards
>>
>> David
>>
>>
>>
>> ----- Original Message -----
>> From: Nick Cox <[email protected]>
>> To: [email protected]
>> Cc:
>> Sent: Saturday, January 19, 2013 4:19:16 PM
>> Subject: Re: st: Nonlinear regression syntax
>>
>> You have
>>
>> {rg*(1+exp(-gamma*(moveave-ci)))^-1}
>>
>> That will make no sense to -nl-. The most basic syntax for braces { }
>> is that braces must enclose parameter names only. There are other
>> possibilities but they do not cover your syntax.
>>
>> {rg}*(1+exp(-gamma*(moveave-ci)))^-1
>>
>> would make sense if and only if the names
>>
>> gamma
>> moveave
>> ci
>>
>> are names of variables (or possibly names of known scalars).
>>
>> You need to tell us what your model is, distinguishing variables,
>> known scalars if any and parameters to be estimated.
>>
>> Nick
>>
>> On Sat, Jan 19, 2013 at 12:39 PM, David Ashcraft
>> <[email protected]> wrote:
>>
>>> rg, algebraic expression and gfc are parameters to be estimated and that's why I used braces {}. gamma and ci are constants. in the first line: rg and moveave are variables where moveave is the quarterly moving average of rg.
>>>
>>> You mentioned that a brace is omitted. I do not see the omitted brace. Can you please point out the missing brace in the following?
>>>
>>> nl (rx={rg}+{rg*(1+exp(-gamma*(moveave-ci)))^-1}+{gfc})
>>
>> Nick Cox <[email protected]>
>>
>>> Did you type _exactly_ the first line? If "rg" is a parameter to be
>>> estimated, then a brace "}" has been omitted. Is "gamma" really a
>>> variable as implied by your syntax?
>>>
>>> In general, there seems confusion here over algebraic conventions and
>>> Stata rules. In algebra you can use braces { } using similar rules to
>>> parentheses () and brackets []: i.e. they are all delimiters and must
>>> just match and nest logically. But in -nl- expressions braces {} have
>>> a special meaning to indicate parameters to be estimated and makes no
>>> sense otherwise.
>>>
>>> Nick
>>>
>>> On Sat, Jan 19, 2013 at 11:12 AM, David Ashcraft
>>> <[email protected]> wrote:
>>>> I want to run the following model as a non-linear regression:
>>>>
>>>> nl (rx={rg}+{rg*(1+exp(-gamma*(moveave-ci)))^-1}+{gfc})
>>>>
>>>> where rx is dependent variable. when I run this model Stata gives the error code: r(480); starting values invalid or some RHS variables have missing values
>>>>
>>>>
>>>> As a second option, I solved the non-linear function outside the equation by having a new variable fm={rg*(1+exp(-gamma*(moveave-ci)))^-1} and run again:
>>>>
>>>> nl (rx={rg}+{fm}+{gfc})
>>>>
>>>> Now I get the results with omitted values for fm.
>>>>
>>>> I don't know where is my mistake. Any help will be greatly appreciated.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/