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

st: Re: Problems programming nl least squares


From   "Thomas Cornelissen" <[email protected]>
To   <[email protected]>
Subject   st: Re: Problems programming nl least squares
Date   Mon, 17 Nov 2003 16:58:11 +0100

I don't know if that fits your problem. I had similar trouble with a line
that was too long. I splitted it into several parts, call them A, B and C,
in the following manner:

replace `1'= A;
replace `1'= `1'+B;
replace `1'= `1'+C;
etc...

Thomas


----- Original Message ----- 
From: "Paola De Agostini" <[email protected]>
To: <[email protected]>
Sent: Monday, November 17, 2003 4:41 PM
Subject: st: Problems programming nl least squares


> Dear statalisters,
>
> I am having some trouble programming an nl-command. I would like to
> program the following function:
>
> replace `1'=  ($B0 + $B1*x1 + $B2*x2 + $B3*x3)*exp( $GF*Z)
>
> Where X are individual characteristics, Z is ln of hhld income and $Bi
> and $GF are parameters to be estimated.
>
> My problems arise when I increase the number of explanatory vars X. In
> this case my command line becomes too long (more than 255 characters).
> Therefore I defined the sum of beta times X over `i' using a loop as
> shown below.
>
> program define nlexercise4_1
>     version 8.0
>     if "`1'"=="?" {
>
>     [parameters definition]
>     [parameters initialization]
>
>     exit
>     }
>
>     local sum = 0
>     forvalues i = 1/3 {
>         local sum= `sum' + ${B`i'}* x`i'
>     }
>
>     replace `1'=  ($B0 + `sum')*exp( $GF*Z)
> End
>
> Results:
>
> (stata4_1)
> ------------------------------------------------------------------------
> ------
>       milkcq |      Coef.   Std. Err.      t    P>|t|     [95% Conf.
> Interval]
> -------------+----------------------------------------------------------
> ------
>           B0 |   178.1014   8.751873    20.35   0.000     160.9446
> 195.2581
>           B1 |   116.3971          .        .       .            .
> .
>           B2 |   142.4194          .        .       .            .
> .
>           B3 |   114.4872          .        .       .            .
> .
>           GF |   .0219544   .0100062     2.19   0.028     .0023387
> .0415701
> ------------------------------------------------------------------------
> ------
> * Parameter B3 taken as constant term in model & ANOVA table
>  (SEs, P values, CIs, and correlations are asymptotic approximations)
>
>
> So, it looks like Stata does not recognize B1, B2 and B3 as parameters
> and does not estimate them.
>
> Has anybody encountered a similar problem before? Any hints,
> suggestions, references would be very much appreciated :-))
>
> Thank you,
>
> Paola De Agostini
>
> *
> *   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/
>

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index