Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: nonlinear least square


From   "Brian P. Poi" <bpoi@stata.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: nonlinear least square
Date   Mon, 22 Aug 2005 10:47:10 -0500 (CDT)

On Mon, 22 Aug 2005, clothilde dufort wrote:

hi,

I am trying to estimate the follwing non linear
equation :

spe=alpha + beta*hpe^gamma

so I use the function "nl" in stata and before I write
the following program.

---

program nlsal, rclass

syntax varlist(min=2 max=2) [aw fw iw] if
local lhs: word 1 of `varlist'
local rhs: word 2 of `varlist'
regress `lhs' `rhs' [`weight'`exp'] `if'
tempname a b
scalar `a' = _b[_cons]
scalar `b' = _b[`rhs']
return local eq "`lhs' = {alpha=`=`a''}+{beta=`=`b''}*`rhs'^{gamma=1}"
return local title "`lhs' = alpha+beta*`rhs'^gamma"

end

---

and then i write :

nl sal: spe hpe

but stata reply  :

: invalid name
nlsal: refused query, rc=198

I strongly suspect that Clothilde is using Stata 8 with an -nl- program written for Stata 9.

When I run her code using the auto dataset in Stata 9, I do not get an error message and -nl- goes through its iterations.

When I run her code using Stata 8, I get precisely the same error message that Clothilde reports.

The solution is to either use the existing program "nlsal" with Stata 9, or else rewrite it using the syntax required by Stata 8's version of -nl-.

Hope this helps


Brian Poi
bpoi@stata.com
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index