Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: NLSUR Quaids


From   "Rahkovsky, Ilya" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: NLSUR Quaids
Date   Thu, 27 Oct 2011 18:55:29 +0000

Thank you very much Brian and Nick. It finally worked and I learnt how to read traces.

Ilya


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Brian P. Poi
Sent: Thursday, October 27, 2011 2:26 PM
To: [email protected]
Subject: Re: st: NLSUR Quaids

The line

     tempname g41 g42 g43 g44 g44

has g44 twice but no g45.

It should be

     tempname g41 g42 g43 g44 g45


To spot that kind of error, look at the trace log where your program ends:

>       - scalar `g45' = -`g41' - `g42' - `g43' - `g44'
>       = scalar  = -__000016 - __000017 - __000018 - __00001A

Once Stata evaluated that line of your program, `g45' translated into nothing.  That means it doesn't know what `g45' means, which implies it was never defined.


Brian P. Poi
Senior Economist
StataCorp LP


Rahkovsky, Ilya wrote:
> Nick, thank you very much for catching it. I have fixed the a0 issue. Now I am getting the 198 error.
> 
> ERROR:
> 
> 
>     = scalar __000018 = __000014
>       - scalar `g44' = `at'[1,18]
>       = scalar __00001A = __000003[1,18]
>       - scalar `g45' = -`g41' - `g42' - `g43' - `g44'
>       = scalar  = -__000016 - __000017 - __000018 - __00001A
>       -------------------------------------------------------------------- end nlsuraids ---
>     - }
>     - if _rc {
>     - di as error "nlsur`eqn' returned " _rc
>     = di as error "nlsuraids returned " _rc
> nlsuraids returned 198
>     - di as error "verify that nlsur`eqn' is a function evaluator program"
>     = di as error "verify that nlsuraids is a function evaluator program"
> verify that nlsuraids is a function evaluator program
>     - exit _rc
>       }
>       }
>     ----------------------------------------------------------------- end nlsur.Estimate ---
>   ---------------------------------------------------------------------------- end nlsur ---
> r(198);
> 
> end of do-file
> 
> r(198);
> 
> Ilya
> 
> 
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
> Sent: Thursday, October 27, 2011 1:58 PM
> To: '[email protected]'
> Subject: RE: st: NLSUR Quaids
> 
> This line is wrong 
> 
> scalar `a5' = 1 - `a1' - `a2' - `a3' - `a0'
> 
> `a0' is not defined. I guess you mean `a4'. 
> 
> Nick 
> [email protected] 
> 
> 
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Rahkovsky, Ilya
> Sent: 27 October 2011 18:52
> To: [email protected]
> Subject: RE: st: NLSUR Quaids
> 
> Brian thank you for very much for your response. I have tried it and now I am getting an error 199. I looked at the previous discussion about this error, but it seems that I don't have the issues discussed.  Please let me know if there are any other errors there. 
> 
> 
> CODE 
> 
> *
> set trace on
> set tracedepth 4
> */
> 
> 
> 
> use "E:\Data\Demand\agg_aids.dta", clear
> 
> gen exp = s0 + s1 + s2 + s3 + s9
> gen lnexp =ln(exp)
> 
> gen lnp1 = ln(p0)
> gen lnp2 = ln(p1)
> gen lnp3 = ln(p2)
> gen lnp4 = ln(p3)
> gen lnp5 = ln(p9)
> 
> drop w*
> 
> gen w1 = s0 / exp
> gen w2 = s1 / exp
> gen w3 = s2 / exp
> gen w4 = s3 / exp
> gen w5 = s9 / exp
> 
>  
> 
> keep w1 w2 w3 w4 lnp1 lnp2 lnp3 lnp4 lnp5 lnexp 
> */
> 
> *program drop nlsuraids
> program nlsuraids
>         version 10.1
> syntax varlist(min=10 max=10) if, at(name) 
> 
> tokenize `varlist'
> 
> args w1 w2 w3 w4 lnp1 lnp2 lnp3 lnp4 lnp5 lnexp 
> 
>   
> tempname a1 a2 a3 a4 a5
> 
> scalar `a1' = `at'[1,1] 
> 
> scalar `a2' = `at'[1,2] 
> 
> scalar `a3' = `at'[1,3] 
> 
> scalar `a4' = `at'[1,4] 
> 
> scalar `a5' = 1 - `a1' - `a2' - `a3' - `a0'
> 
>   
> 
> tempname b1 b2 b3 b4 b5 
> 
> scalar `b1' = `at'[1,5] 
> 
> scalar `b2' = `at'[1,6] 
> 
> scalar `b3' = `at'[1,7] 
> 
> scalar `b4' = `at'[1,8] 
>   
> scalar `b5' = -`b1' - `b2' - `b3' - `b4'
> 
>   
> 
> tempname g11 g12 g13 g14 g15
> 
> tempname g21 g22 g23 g24 g25
> 
> tempname g31 g32 g33 g34 g35
> 
> tempname g41 g42 g43 g44 g44
> 
> tempname g51 g52 g53 g54 g55
> 
>   
> scalar `g11' = `at'[1,9] 
> 
> scalar `g12' = `at'[1,10] 
> 
> scalar `g13' = `at'[1,11] 
> 
> scalar `g14' = `at'[1,12]  
> 
> scalar `g15' = -`g11' - `g12' - `g13' - `g14'
> 
>   
> 
> scalar `g21' = `g12' 
> 
> scalar `g22' = `at'[1,13] 
> 
> scalar `g23' = `at'[1,14] 
> 
> scalar `g24' = `at'[1,15]
> 
> scalar `g25' = -`g21' - `g22' - `g23' - `g24'
> 
>   
> scalar `g31' = `g13' 
> 
> scalar `g32' = `g23' 
> 
> scalar `g33' = `at'[1,16] 
> 
> scalar `g34' = `at'[1,17]
> 
> scalar `g35' = -`g31' - `g32' - `g33' - `g34'
>  
> 
> scalar `g41' = `g14' 
> 
> scalar `g42' = `g24' 
> 
> scalar `g43' = `g34' 
> 
> scalar `g44' = `at'[1,18]
> 
> scalar `g45' = -`g41' - `g42' - `g43' - `g44'  
> 
>   
> scalar `g51' = `g15' 
> 
> scalar `g52' = `g25' 
> 
> scalar `g53' = `g35' 
> 
> scalar `g54' = `g45'
> 
> scalar `g55' = -`g51' - `g52' - `g53' - `g54' 
>   
> 
> quietly { 
> 
> tempvar lnpindex 
> 
> gen double `lnpindex' = 5 + `a1'*`lnp1' + `a2'*`lnp2' + `a3'*`lnp3' + `a4'*`lnp4' + `a5'*`lnp5'
> 
> forvalues i = 1/5 { 
> 
> forvalues j = 1/5 { 
> 
> replace `lnpindex' = `lnpindex' + 0.5*`g`i'`j''*`lnp`i''*`lnp`j'' 
> 
> } 
> 
> } 
> 
> replace `w1' = `a1' + `g11'*`lnp1' + `g12'*`lnp2' + `g13'*`lnp3' + `g14'*`lnp4' + `g15'*`lnp5' + `b1'*(`lnexp' - `lnpindex') 
> 
> replace `w2' = `a2' + `g21'*`lnp1' + `g22'*`lnp2' + `g23'*`lnp3' + `g24'*`lnp4' + `g25'*`lnp5' + `b2'*(`lnexp' - `lnpindex') 
> 
> replace `w3' = `a3' + `g31'*`lnp1' + `g32'*`lnp2' + `g33'*`lnp3' + `g34'*`lnp4' + `g35'*`lnp5' + `b3'*(`lnexp' - `lnpindex') 
> 
> replace `w4' = `a4' + `g41'*`lnp1' + `g42'*`lnp2' + `g43'*`lnp3' + `g44'*`lnp4' + `g45'*`lnp5' + `b4'*(`lnexp' - `lnpindex') 
> } 
>  
> 
> end 
> 
> nlsur aids @ w1 w2 w3 w4  lnp1 lnp2 lnp3 lnp4 lnp5 lnexp, ifgnls nequations(4) param(a1 a2 a3 a4 b1 b2 b3 b4  g11 g12 g13 g14 g22 g23 g24 g33 g34 g44 ) nolog
> 
> 
> ERROR
> 
> 
>       ------------------------------------------------------------------ begin nlsuraids ---
>       - version 10.1
>       - syntax varlist(min=10 max=10) if, at(name)
>       - tokenize `varlist'
>       = tokenize __00000D __00000E __00000F __00000G lnp1 lnp2 lnp3 lnp4 lnp5 lnexp
>       - args w1 w2 w3 w4 lnp1 lnp2 lnp3 lnp4 lnp5 lnexp
>       - tempname a1 a2 a3 a4 a5
>       - scalar `a1' = `at'[1,1]
>       = scalar __00000H = __000003[1,1]
>       - scalar `a2' = `at'[1,2]
>       = scalar __00000I = __000003[1,2]
>       - scalar `a3' = `at'[1,3]
>       = scalar __00000J = __000003[1,3]
>       - scalar `a4' = `at'[1,4]
>       = scalar __00000K = __000003[1,4]
>       - scalar `a5' = 1 - `a1' - `a2' - `a3' - `a0'
>       = scalar __00000L = 1 - __00000H - __00000I - __00000J - 
>       -------------------------------------------------------------------- end nlsuraids ---
>     - }
>     - if _rc {
>     - di as error "nlsur`eqn' returned " _rc
>     = di as error "nlsuraids returned " _rc
> nlsuraids returned 198
>     - di as error "verify that nlsur`eqn' is a function evaluator program"
>     = di as error "verify that nlsuraids is a function evaluator program"
> verify that nlsuraids is a function evaluator program
>     - exit _rc
>       }
>       }
>     ----------------------------------------------------------------- end nlsur.Estimate ---
>   ---------------------------------------------------------------------------- end nlsur ---
> r(198);
> 
> end of do-file
> 
> r(198);
> 
> 
> Ilya
> 
> 
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Brian P. Poi
> Sent: Thursday, October 27, 2011 11:36 AM
> To: [email protected]
> Subject: Re: st: NLSUR Quaids
> 
> Rahkovsky, Ilya wrote:
>> Hello,
>>
>> I am trying to follow Brians Poi (2008) QAIDS model. I keep getting an error 111. I have a trace on, and I guess that the error is in the specifying the number of equations, but I am not sure what I should change in the code.
>>
>> Thank you, Ilya
> ...
>> MY CODE 
>>
>> set trace on
>> set tracedepth 4
>>
>> program drop nlsuraids
>> program nlsuraids
>>         version 10.1
>> use "E:\Data\Demand\agg_aids.dta", clear
>>
>>
>> gen exp = s0 + s1 + s2 + s3 + s9
>> gen lnexp =ln(exp)
>>
>> gen lnp1 = ln(p0)
>> gen lnp2 = ln(p1)
>> gen lnp3 = ln(p2)
>> gen lnp4 = ln(p3)
>> gen lnp5 = ln(p9)
>>
>> drop w*
>>
>> gen w1 = s0 / exp
>> gen w2 = s1 / exp
>> gen w3 = s2 / exp
>> gen w4 = s3 / exp
>> gen w5 = s9 / exp
>>
>> keep w1 w2 w3 w4 lnp1 lnp2 lnp3 lnp4 lnp5 lnexp 
>>
>> syntax varlist(min=10 max=10) if, at(name) 
> ...
> 
> 
> The problem is that the way your program is written, you are reloading the dataset every time the program nlsuraids gets called.  Instead, you should load in the data once, define the nlsuraids program to just compute the predicted share equations, then call -nlsur- The solution is simple.  In your sample code, just move the three lines
> 
> program drop nlsuraids
> program nlsuraids
>          version 10.1
> 
> down, just before the -syntax- statement.
> 
> The other problem is that your -tokenize- statement is not correct.
> 
> The outline of your entire do-file should be something like
> 
> 
> use "E:\Data\Demand\agg_aids.dta", clear
> gen exp = ...
> gen lnexp = ln(exp)
> gen lnp1 = ...
> ...
> gen w1 = ...
> 
> 
> capture program drop nlsuraids
> program nlsuraids
>          version 10.1
>          syntax varlist(min=10 max=10) if, at(name)
> 
>          tokenize `varlist'
> 	args w1 w2 w3 w4 lnp1 lnp2 lnp3 lnp4 lnp5 lnexp
> 
>          ...
>          <I haven't studied the rest of your code carefully, but it looks okay>
>          ...
>          replace `w1' ...
>          replace `w2' ...
>          replace `w3' ...
>          replace `w4' ...
> 
> end
> 
> nlsur aids @ w1 w2 w3 w4  lnp1-lnp5 lnexp, ifgnls nequations(4) param(a1 a2 a3 a4 b1 b2 b3 b4  g11 g12 g13 g14 g22 g23 g24 g33 g34 g44 ) nolog
> 
> *
> *   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/
> 
> 
> *
> *   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/
> 
*
*   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/


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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index