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

st: nl within another nl


From   "FEIVESON, ALAN H. (AL) (JSC-SD) (NASA)" <alan.h.feiveson@nasa.gov>
To   "'statalist'" <statalist@hsphsun2.harvard.edu>
Subject   st: nl within another nl
Date   Tue, 26 Nov 2002 08:57:17 -0600

Hello Statalist - 

I am trying to use nl-program#2 within the first part ("query" section) of
nl-program#1 to obtain first guesses. To my surprise, the nl#2 actually ran
properly, however something got messed up when I got to the iteration part
of nl#1. Here are some of the  program statements from Stata's nl routine
where the error occured. Any clues as to what is messed up or how to get
around this? Is it because the number of parameters in nl#2 is smaller than
the number in nl#1? 

Al Feiveson




- gen double `RESID' = `YVAR'-`YHAT' if `touse'
- scalar `gm2' = 1
- local scaled ""
- }
- reg `RESID' `Z' `exp' if `touse', nocons
- scalar `old_ssr' = e(rss)*`gm2'
- local done 0
- local its 0
- tempname hest
- while ~`done' {
- if "`log'" == "" {
- noi di in gr "Iteration " `its' ":  " _c
Iteration 0:  - if "`trace'"!="" { noi di }
- }
- local j 1
- while `j' <= `np' {
- local old_pj = ${``j''}
invalid syntax


- - - - - - - - - - -  - - -- - - - - - - - - - - - - -- - - - - - - - - - -
- - -- - - - - - - - - - -  - - -
Here is the listing of nl-program#1 (the big one).


program define nlmcl3b

   if "`1'" == "?" {
      global S_1 " BULL1 BULL2 BULL3 T11 T22 T33 "    /* T21 T31 T32"*/



   /* Get estimates $Q1, $Q2, $Q3, of qi = sigii assuming ui and sigij = 0
*/

      nl q3 `2' `2'   /*Note: nlq3.ado has only 3 parameters (Q1, Q2 and Q3)
*/

      global BULL1=10
      global BULL2=10
      global BULL3=10

      global T11=$Q1+10
      global T22=$Q2+10
      global T33=$Q3+10

      global T21=10
      global T31=10
      global T32=10

       matrix A1=(1,0,0 \ 0,1,0 \ 0,0,0)
       matrix A2=(0,0.5,0 \ 0.5,0,0.5 \ 0,0.5,0)       
       matrix A3=(0,0,0 \ 0,1,0 \ 0,0,1)
      set trace on
      exit

      }


      global M1=$BULL1-10
      global M2=$BULL2-10
      global M3=$BULL3-10
      global SIG11=$T11-10
      global SIG22=$T22-10
      global SIG33=$T33-10
      global SIG21=$T21-10
      global SIG31=$T31-10
      global SIG32=$T32-10



      matrix SIG = ($SIG11, $SIG21, $SIG31 \ $SIG21, $SIG22, $SIG32 \
$SIG31, $SIG32
> , $SIG33)
      matrix MU = ($M1 \ $M2 \ $M3)
      matrix MUt=MU'
      

      cap gen yh=.
      forv i=1(1)3 {
      matrix MAM=MUt*A`i'*MU 
      matrix SA=SIG*A`i'
      scalar trsa=trace(SA)
      replace yh= MAM[1,1] + scalar(trsa) in `i'
      forv j=1(1)`i' {
      matrix SASA=SIG*A`i'*SIG*A`j'
      matrix MASAM=MUt*A`i'*SIG*A`j'*MU
      scalar t`i'`j'=trace(SASA)
      scalar b`i'`j'=MASAM[1,1]
      }
      }
      replace yh=4*scalar(b11)+2*scalar(t11) in 4   /* var(y1) */
      replace yh=4*scalar(b21)+2*scalar(t21) in 5   /* cov(y2,y1) */
      replace yh=4*scalar(b22)+2*scalar(t22) in 6   /* var(y2) */
      replace yh=4*scalar(b31)+2*scalar(t31) in 7   /* cov(y3,y1) */
      replace yh=4*scalar(b32)+2*scalar(t32) in 8   /* cov(y3,y2) */
      replace yh=4*scalar(b33)+2*scalar(t33) in 9   /* var(y3) */

      replace `1' = yh

end

. 
*
*   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