# Re: st: Return r(111) this time

 From Eva Poen To statalist@hsphsun2.harvard.edu Subject Re: st: Return r(111) this time Date Sun, 15 Mar 2009 18:00:25 +0000

Jingjing,

good to hear that the example now works for you. Without having gone
through all of your code, there are a few problems that I spotted. I
will first point those out, and then show you how you can debug your
program in Stata.

>        tempname at att blt bkt bmt bet
>        scalar `ai'=`at'[1,16]
>        scalar `aii'=`at'[1,17]

Here, you declare tempnames at and att, and then use ai and aii for
your scalars. Later on, you appear to use t and att. Therefore, this
is not going to work (the names have to be the same). In addition, you
and aii for your scalars to avoid confusion. Therefore, change it to

tempname ai aii blt bkt bmt bet
scalar `ai'=`at'[1,16]
scalar `aii'=`at'[1,17]

and also replace all instances of `t' with `ai', and all instances of
`att' with `aii'. Please note that I haven't checked any of the other
scalars for consistency.

The next problem comes at the end of your program, within the -quietly
{ }- part. There, you need to change

>                replace lnc =

to

replace `lnc' =

(note the single quotes). The same holds for the following two lines,
where you have to change sl to `sl', sk to `sk' and sm to `sm'.

Maybe we have found all mistakes, and the program will run. If not,
here is how you can figure out what's going wrong. First, create
copies of your four dependent variables lnc, sl, sk, and sm :

****
foreach x of varlist lnc sl sk sm {
gen c_`x' = `x'
}
****

Next, call your program directly (without -nlsur-):

****
matrix a = J(1,61,0)
set trace on
nlsurweb c_lnc c_sl c_sk c_sm lnpl lnpk lnpm lnpe lnq t d1 d2 d3 d4 d5 d6, at(a)
****

The -trace- output will show you where exactly the problem is.

Good luck,
Eva

2009/3/15  <jjc.li@utoronto.ca>:
> Thanks Eva! You are so nice and patient.
>
> After correcting all the typo you mentioned, the codes for the example
> works.
>
> However, in my own program, there's r(111) even correcting all the similar
> typo. I am not sure if r(11) is still a kind of error that caused by typo or
> other big errors. If it's caused by typo, I will check it again and agian
> until it works. What I am worried about is that it's the codes designing
> errors.
>
> My codes is:
>
> program nlsurweb
>
>        version 10.1
>
>        syntax varlist(min=16 max=16) [if], at(name)
>
>        tokenize `varlist'
>        args lnc sl sk sm lnpl lnpk lnpm lnpe lnq t d1 d2 d3 d4 d5 d6
>
>        tempname al ak am ae
>        scalar `al'=`at'[1,1]
>        scalar `ak'=`at'[1,2]
>        scalar `am'=`at'[1,3]
>        scalar `ae'=1-`al'-`ak'-`am'
>
>        tempname aq aqq
>        scalar `aq'=`at'[1,4]
>        scalar `aqq'=at'[1,5]
>
>        tempname blq bkq bmq beq
>        scalar `blq'=`at'[1,6]
>        scalar `bkq'=`at'[1,7]
>        scalar `bmq'=`at'[1,8]
>        scalar `beq'=-`blq'-`bkq'-`bmq'
>
>        tempname bqt bq1 bq2 bq3 bq4 bq5 bq6
>        scalar `bqt'=`at'[1,9]
>        scalar `bq1'=`at'[1,10]
>        scalar `bq2'=`at'[1,11]
>        scalar `bq3'=`at'[1,12]
>        scalar `bq4'=`at'[1,13]
>        scalar `bq5'=`at'[1,14]
>        scalar `bq6'=`at'[1,15]
>
>        tempname at att blt bkt bmt bet
>        scalar `ai'=`at'[1,16]
>        scalar `aii'=`at'[1,17]
>        scalar `blt'=`at'[1,18]
>        scalar `bkt'=`at'[1,19]
>        scalar `bmt'=`at'[1,20]
>        scalar `bet'=-`blt'-`bkt'-`bmt'
>
>        scalar `bt1'=`at'[1,27]
>        scalar `bt2'=`at'[1,28]
>        scalar `bt3'=`at'[1,29]
>        scalar `bt4'=`at'[1,30]
>        scalar `bt5'=`at'[1,31]
>        scalar `bt6'=`at'[1,32]
>
>        tempname bl1 bl2 bl3 bl4 bl5 bl6 bk1 bk2 bk3 bk4 bk5 bk6  bm1 bm2 bm3
> bm4 bm5 bm6  be1 be2 be3 be4 be5 be6
>        scalar `bl1'=`at'[1,33]
>        scalar `bl2'=`at'[1,34]
>        scalar `bl3'=`at'[1,35]
>        scalar `bl4'=`at'[1,36]
>        scalar `bl5'=`at'[1,37]
>        scalar `bl6'=`at'[1,38]
>        scalar `bk1'=`at'[1,39]
>        scalar `bk2'=`at'[1,40]
>        scalar `bk3'=`at'[1,41]
>        scalar `bk4'=`at'[1,42]
>        scalar `bk5'=`at'[1,43]
>        scalar `bk6'=`at'[1,44]
>        scalar `bm1'=`at'[1,45]
>        scalar `bm2'=`at'[1,46]
>        scalar `bm3'=`at'[1,47]
>        scalar `bm4'=`at'[1,48]
>        scalar `bm5'=`at'[1,49]
>        scalar `bm6'=`at'[1,50]
>        scalar `be1'=`at'[1,51]
>        scalar `be2'=`at'[1,52]
>        scalar `be3'=`at'[1,53]
>        scalar `be4'=`at'[1,54]
>        scalar `be5'=`at'[1,55]
>        scalar
> `be6'=-`bl1'-`bl2'-`bl3'-`bl4'-`bl5'-`bl6'-`bm1'-`bm2'-`bm3'-`bm4'-`bm5'-`bm6'-`bk1'-`bk2'-`bk3'-`bk4'-`bk5'-`bk6'-`be1'-`be2'-`be3'-`be4'-`be5'
>
>        tempname dll dkl dkk dml dmk dmm
>        scalar `dll'=`at'[1,56]
>        scalar `dkl'=`at'[1,57]
>        scalar `dkk'=`at'[1,58]
>        scalar `dml'=`at'[1,59]
>        scalar `dmk'=`at'[1,60]
>        scalar `dmm'=`at'[1,61]
>
>
>        quietly {
>
> replace lnc =
`l!
> nq'*`d3'+
> `bq4'*`lnq'*`d4'+`bq5'*`lnq'*`d5'+`bq6'*`lnq'*`d6'+`bt1'*`t'*`d1'+`bt2'*`t'*`d2'+`bt3'*`t'*`d3'+`bt4'*`t'*`d4'+`bt5'*`t'*`d5'+`bt6'*`t'*`d6'+(-`dll'*`dll'+`al'-`al'*`al')*0.5*`lnpl'*`lnpl'+(-`dll'*`dkl'-`al'*`ak')*`lnpl'*`lnpk'+(-`dll'*`dml'-`al'*`am')*`lnpl'*`lnpm'+(`dll'*`dll'-`al'+`al'*`al'+`dll'*`dkl'+`al'*`ak'+`dll'*`dml'+`al'*`am')*`lnpl'*`lnpe'+(-`dkl'*`dkl'-`dkk'*`dkk'+`ak'-`ak'*`ak')*0.5*`lnpk'*`lnpk'+(-`dkl'*`dml'-`dkk'*`dmk'-`ak'*`am')*`lnpk'*`lnpm'+(`dll'*`dkl'+`al'*`ak'+`dkl'*`dkl'+`dkk'*`dkk'-`ak'+`ak'*`ak'+`dkl'*`dml'+`dkk'*`dmk'+`ak'*`am')*`lnpk'*`lnpe'+(-`dml'*`dml'-`dmk'*`dmk'-`dmm'*`dmm'+`am'-`am'*`am')*0.5*`lnpm'*`lnpm'+(`dll'*`dml'+`al'*`am'+`dkl'*`dml'+`dkk'*`dmk'+`ak'*`am'+`dml'*`dml'+`dmk'*`dmk'+`dmm'*`dmm'-`am'+`am'*`am')*`lnpm'*`lnpe'+(-`dll'*`dll'+`al'-`al'*`al'-`dll'*`dkl'-`al'*`ak'-`dll'*`dml'-`al'*`am'-`dll'*`dml'-`al'*`am'-`dkl'*`dml'-`dkk'*`dmk'-`ak'*`am'-`dml'*`dml'-`dmk'*`dmk'-`dmm'*`dmm'+`am'-`am'*`am'-`dll'*`dkl'-`al'*`ak'-`dkl'*`dkl'-`d!
kk!
> '*`dkk'+`
> ak'-`ak'*`ak'-`dkl'*`dml'-`dkk'*`dmk'-`ak'*`am')*0.5*`lnpe'*`lnpe'
>
>
>
>                replace sl =
> `al'+`blq'*`lnq'+(-`dll'+`al'-`al'*`al')*`lnpl'+(-`dll'*`dkl'-`al'*`ak')*`lnpk'+(-`dll'*`dml'-`al'*`am')*`lnpm'+(`dll'-`al'+`al'*`al'+`dll'*`dkl'+`al'*`ak'+`dll'*`dml'+`al'*`am')*`lnpe'+`blt'*`t'+`bl1'*`d1'+`bl2'*`d2'+`bl3'*`d3'+`bl4'*`d4'+`bl5'*`d5'+`bl6'*`d6'
>
>
>                replace sk =
> `ak'+`bkq'*`lnq'+(-`dll'*`dkl'-`al'*`ak')*`lnpl'+(-`dkl'*`dkl'-`dkk'*`dkk'+`ak'-`ak'*`ak')*`lnpk'+(-`dkl'*`dml'-`dkk'*`dmk'-`ak'*`am')*`lnpm'+(`dll'*`dkl'+`al'*`ak'+`dkl'*`dkl'+`dkk'*`dkk'-`ak'+`ak'*`ak'+`dkl'*`dml'+`dkk'*`dmk'+`ak'*`am')*`lnpe'+`bkt'*`t'+`bk1'*`d1'+`bk2'*`d2'+`bk3'*`d3'+`bk4'*`d4'+`bk5'*`d5'+`bk6'*`d6'
>
>
>                replace sm =
> `am'+`bmq'*`lnq'+(-`dll'*`dml'-`al'*`am')*`lnpl'+(-`dkl'*`dml'-`dkk'*`dmk'-`ak'*`am')*`lnpk'+(-`dml'*`dml'-`dmk'*`dmk'-`dmm'*`dmm'+`am'-`am'*`am')*`lnpm'+(`dll'*`dml'+`al'*`am'+`dkl'*`dml'+`dkk'*`dmk'+`ak'*`am'+`dml'*`dml'+`dmk'*`dmk'+`dmm'*`dmm'-`am'+`am'*`am')*`lnpe'+`bmt'*`t'+`bm1'*`d1'+`bm2'*`d2'+`bm3'*`d3'+`bm4'*`d4'+`bm5'*`d5'+`bm6'*`d6'
>
>
>
>
>        }
>
> end
>
> nlsur web @ lnc sl sk sm lnpl lnpk lnpm lnpe lnq t d1 d2 d3 d4 d5 d6,
> parameters(al ak am aq aqq blq bkq bmq bqt bq1 bq2 bq3 bq4 bq5 bq6 ai aii
> bl5 bl6 bk1 bk2 bk3 bk4 bk5 bk6  bm1 bm2 bm3 bm4 bm5 bm6 be1 be2 be3 be4 be5
> dll dkl dkk dml dmk dmm) neq(4) ifgnls
>
>
>
>
>
>
> Quoting Eva Poen <eva.poen@gmail.com>:
>
>> This message that I sent earlier has not made it through to the list;
>> I therefore re-send it. My apologies, should it appear twice.
>>
>> Eva
>> ***************************
>>
>>  Jingjing,
>>
>>  Also, take a look at the following line:
>>
>>  > sca1ar `g4l'=`g14'
>>
>>  You want `g41' here, not `g4l' (i.e. the number 1 instead of the
>>  letter l, as in life). With the commands  -scalar- and -forvalues- it's
>> the
>>  other way round (you have the number 1 in those commands where
>>  and -help forvalues-.
>>
>>  Oh, and I just noticed that your line
>>
>>  > replace `w3' =
>>
>> `a3'+`g31'*`lnp1'+`g32*`lnp2'+`g33'*`lnp3'+`g34'*`lnp4'+`b3'*(`lnm'-`lnpindex')
>>
>>  still lacks a closing single quote after `g32. You want:
>>
>>  replace `w3' =
>>
>> `a3'+`g31'*`lnp1'+`g32'*`lnp2'+`g33'*`lnp3'+`g34'*`lnp4'+`b3'*(`lnm'-`lnpindex')
>>
>>
>>  Eva
>>
>>>
>>>
>>>
>>> 2009/3/15 Kit Baum <baum@bc.edu>:
>>>>
>>>> <>
>>>> The word is s c a L a r.  Eva pointed that out quite clearly.
>>>>
>>>>
>>>> Kit Baum   |   Boston College Economics and DIW Berlin   |
>>>> http://ideas.repec.org/e/pba1.html
>>>> An Introduction to Stata Programming   |
>>>> http://www.stata-press.com/books/isp.html
>>>> An Introduction to Modern Econometrics Using Stata   |
>>>> http://www.stata-press.com/books/imeus.html
>>>>
>>>>
>>>>
>>>> On Mar 15, 2009, at 02:33 , Jingjing wrote:
>>>>
>>>>>        sca1ar `a2'=`at'[1,2]
>>>>>        sca1ar `a3'=`at'[1,3]
>>>>>        sca1ar `a4'= 1-`a1'-`a2'-`a3'
>>>>>
>>>>>        tempname b1 b2 b3
>>>>>        sca1ar `b1'=`at'[1,4]
>>>>>        sca1ar `b2'=`at'[1,5]
>>>>>        sca1ar `b3'=`at'[1,6]
>>>>
>>>> etc.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/