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

st: old nl prolem still there


From   "FEIVESON, ALAN H. (AL) (JSC-SD) (NASA)" <[email protected]>
To   "'statalist'" <[email protected]>
Subject   st: old nl prolem still there
Date   Fri, 11 Oct 2002 15:29:26 -0500

Hi - 
Some time ago I noticed that when running -nl- with an "if"condition, that
condition is ignored when intitializing the parameter estimates in the first
part of the program. Apparently this is still the case- here's an example:


program define nlt4
args q a x 

if "`1'" == "?" {
   global S_1 " A V M X0"
   summ `x' [w=`a'],det
   global X0=r(mean)
   global A=r(sd)
   global V = 1
   global M = 1
   exit
   }

tempvar xp zf
gen `xp'=`x'-$X0
gen `zf'=-$M*log(1+ `xp'*`xp'/($A*$A) )-$V*atan(`xp'/$A)
cap gen fh=.
replace fh=exp(`zf')
integ fh `xp'
replace fh=fh/r(integral)
replace `1' = fh
end

In thiis program, the initial value of X0 is supposed to be the weighted
mean of `x'  - which it does correctly if I only keep the data for lead==8.

. summ x [w=ap] if lead==8
(analytic weights assumed)

    Variable |     Obs      Weight        Mean   Std. Dev.       Min
Max
-------------+--------------------------------------------------------------
---
           x |      42  .333115671    100.9182   12.83494         39
152


.        preserve

. keep if lead==8
(484 observations deleted)

. nl t4 ap ap x if lead==8,trace
(obs = 42)

Iteration 0:  
           A =  12.83494
           V =         1
           M =         1
           X0 =  100.9182
                                         residual SS =  .0035773


However if I run this -nl- program using the whole data set with the "if'
condition, I get the correct number of observations, but:

. nl t4 ap ap x if lead==8,trace
(obs = 42)

Iteration 0:  
           A =  15.15218
           V =         1
           M =         1
           X0 =  99.11866
                                         residual SS =  .0045832

This initial value of X0 is the weighted mean for all the data - in other
words my "if" is ignored.

. restore

. summ x [w=ap] 
(analytic weights assumed)

    Variable |     Obs      Weight        Mean   Std. Dev.       Min
Max
-------------+--------------------------------------------------------------
---
           x |     526  4.28911733    99.11866   15.15218         39
154

Any hope of having this problem corrected any time soon?

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