# st: RE: predictnl and nonlinear regression

 From "Scott Merryman" To Subject st: RE: predictnl and nonlinear regression Date Fri, 5 Aug 2005 21:15:31 -0500

```> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of Wallace, John
> Sent: Friday, August 05, 2005 7:03 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: predictnl and nonlinear regression
>
> Dear listmembers:
> I'm working my way through learning how to use regressions other than OLS
> within stata.  One model I frequently use in Excel is the exponential fit.
> I believe the following is the way to specify that model within Stata's nl
> function:
> nl(y = {beta}*exp({alpha}*x)
> I have used the predict function following this estimation to generate a
> fit and graphed the results, which look like the chart I was expecting to
> see.  I then looked for a way to generate confidence intervals for the
> fit, and have run aground.  It looks like the predictnl function would do
> what I want, but I can't get it to work.  Here's what I've tried:
> (after first -drop-ing the fit variable I made with -predict-)
>
> . predictnl fit = predict(fit), ci(ub lb)
> 	Result: fit not allowed \\\ predict(fit) invalid
> . predictnl fit = nl (y = {beta}*exp({alpha}*x)), ci(ub lb)
> 	Result: Unknown function nl()
> . predictnl fit = y = {beta}*exp({alpha}*x), ci(ub lb)
> 	Result: =exp not allowed

You don't need the y term in the -predictnl- statement.

For example:

. sysuse auto,clear
(1978 Automobile Data)

. qui nl (price = {beta}*exp({alpha}*mpg))

. predictnl fit = _b[beta]*exp(_b[alpha]*mpg), ci(lb ub)
note: Confidence intervals calculated using t(72) critical values.

> Also, is it possible to use the stored estimation command interactively to
> solve for a specific x?
> e.g.: . predicti(0.5)
> which returns some value y according to the model?
>

How about using -nlcom-.  For example, if price = 1000:

. nlcom (ln(1000/_b[beta]))/_b[alpha]

_nl_1:  (ln(1000/_b[beta]))/_b[alpha]

----------------------------------------------------------------------------
--
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf.
Interval]
-------------+--------------------------------------------------------------
--
_nl_1 |   52.22725   6.330777     8.25   0.000     39.60708
64.84742
----------------------------------------------------------------------------
--

Hope this helps,
Scott

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