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]
st: Code problem with NLSUR quadratic AIDS, when considering zero observations
From
<[email protected]>
To
<[email protected]>
Subject
st: Code problem with NLSUR quadratic AIDS, when considering zero observations
Date
Wed, 22 Jan 2014 16:04:06 +0000
Dear Stata users
I am trying to run a Quadratic AIDS model for 10 products. I tried to run it without considering zero observations and it worked fine.
Now I seem to have a mistake in my code, when I try to consider zero observations according to the method of Shonkwiler and Yen (1999).
Unfortunately I cannot find out what I did wrong in the code.
The output that Stata gives me is always:
nlsuraids returned 110
verify that nlsuraids is a function evaluator program
r(110);
I would appreciate if you could check the following code:
program nlsuraids
version 12
syntax varlist(min=38 max=38) [if] , at(name)
tokenize `varlist'
args wbio1 wbio2 wbio3 wbio4 wbio5 wbio6 wbio7 wbio8 wbio9 lnpbio1 lnpbio2 lnpbio3 lnpbio4 lnpbio5 lnpbio6 lnpbio7 lnpbio8 lnpbio9 lnpbio10 lnxbio cdf1 cdf2 cdf3 cdf4 cdf5 cdf6 cdf7 cdf8 cdf9 pdf1 pdf2 pdf3 pdf4 pdf5 pdf6 pdf7 pdf8 pdf9
tempname abio1 abio2 abio3 abio4 abio5 abio6 abio7 abio8 abio9 abio10 /* alpha */
scalar `abio1' = `at'[1,1]
scalar `abio2' = `at'[1,2]
scalar `abio3' = `at'[1,3]
scalar `abio4' = `at'[1,4]
scalar `abio5' = `at'[1,5]
scalar `abio6' = `at'[1,6]
scalar `abio7' = `at'[1,7]
scalar `abio8' = `at'[1,8]
scalar `abio9' = `at'[1,9]
scalar `abio10' = 1 - `abio1' - `abio2' - `abio3' - `abio4' - `abio5' - `abio6' - `abio7' - `abio8' - `abio9'
tempname bbio1 bbio2 bbio3 bbio4 bbio5 bbio6 bbio7 bbio8 bbio9 bbio10 /* beta */
scalar `bbio1' = `at'[1,10]
scalar `bbio2' = `at'[1,11]
scalar `bbio3' = `at'[1,12]
scalar `bbio4' = `at'[1,13]
scalar `bbio5' = `at'[1,14]
scalar `bbio6' = `at'[1,15]
scalar `bbio7' = `at'[1,16]
scalar `bbio8' = `at'[1,17]
scalar `bbio9' = `at'[1,18]
scalar `bbio10' = - `bbio1' - `bbio2' - `bbio3' - `bbio4' - `bbio5' - `bbio6' - `bbio7' - `bbio8' - `bbio9'
tempname gbio11 gbio12 gbio13 gbio14 gbio15 gbio16 gbio17 gbio18 gbio19 gbio110 /* gamma */
tempname gbio21 gbio22 gbio23 gbio24 gbio25 gbio26 gbio27 gbio28 gbio29 gbio210
tempname gbio31 gbio32 gbio33 gbio34 gbio35 gbio36 gbio37 gbio38 gbio39 gbio310
tempname gbio41 gbio42 gbio43 gbio44 gbio45 gbio46 gbio47 gbio48 gbio49 gbio410
tempname gbio51 gbio52 gbio53 gbio54 gbio55 gbio56 gbio57 gbio58 gbio59 gbio510
tempname gbio61 gbio62 gbio63 gbio64 gbio65 gbio66 gbio67 gbio68 gbio69 gbio610
tempname gbio71 gbio72 gbio73 gbio74 gbio75 gbio76 gbio77 gbio78 gbio79 gbio710
tempname gbio81 gbio82 gbio83 gbio84 gbio85 gbio86 gbio87 gbio88 gbio89 gbio810
tempname gbio91 gbio92 gbio93 gbio94 gbio95 gbio96 gbio97 gbio98 gbio99 gbio910
tempname gbio101 gbio102 gbio103 gbio104 gbio105 gbio106 gbio107 gbio108 gbio109 gbio1010
scalar `gbio11' = `at'[1,19]
scalar `gbio12' = `at'[1,20]
scalar `gbio13' = `at'[1,21]
scalar `gbio14' = `at'[1,22]
scalar `gbio15' = `at'[1,23]
scalar `gbio16' = `at'[1,24]
scalar `gbio17' = `at'[1,25]
scalar `gbio18' = `at'[1,26]
scalar `gbio19' = `at'[1,27]
scalar `gbio110' = -`gbio11' - `gbio12' -`gbio13' - `gbio14' -`gbio15' - `gbio16' -`gbio17' - `gbio18' - `gbio19'
scalar `gbio21' = `gbio12'
scalar `gbio22' = `at'[1,28]
scalar `gbio23' = `at'[1,29]
scalar `gbio24' = `at'[1,30]
scalar `gbio25' = `at'[1,31]
scalar `gbio26' = `at'[1,32]
scalar `gbio27' = `at'[1,33]
scalar `gbio28' = `at'[1,34]
scalar `gbio29' = `at'[1,35]
scalar `gbio210' = -`gbio21' - `gbio22' -`gbio23' - `gbio24' -`gbio25' - `gbio26' -`gbio27' - `gbio28' - `gbio29'
scalar `gbio31' = `gbio13'
scalar `gbio32' = `gbio23'
scalar `gbio33' = `at'[1,36]
scalar `gbio34' = `at'[1,37]
scalar `gbio35' = `at'[1,38]
scalar `gbio36' = `at'[1,39]
scalar `gbio37' = `at'[1,40]
scalar `gbio38' = `at'[1,41]
scalar `gbio39' = `at'[1,42]
scalar `gbio310' = -`gbio31' - `gbio32' -`gbio33' - `gbio34' -`gbio35' - `gbio36' -`gbio37' - `gbio38' - `gbio39'
scalar `gbio41' = `gbio14'
scalar `gbio42' = `gbio24'
scalar `gbio43' = `gbio34'
scalar `gbio44' = `at'[1,43]
scalar `gbio45' = `at'[1,44]
scalar `gbio46' = `at'[1,45]
scalar `gbio47' = `at'[1,46]
scalar `gbio48' = `at'[1,47]
scalar `gbio49' = `at'[1,48]
scalar `gbio410' = -`gbio41' - `gbio42' -`gbio43' - `gbio44' -`gbio45' - `gbio46' -`gbio47' - `gbio48' - `gbio49'
scalar `gbio51' = `gbio15'
scalar `gbio52' = `gbio25'
scalar `gbio53' = `gbio35'
scalar `gbio54' = `gbio45'
scalar `gbio55' = `at'[1,49]
scalar `gbio56' = `at'[1,50]
scalar `gbio57' = `at'[1,51]
scalar `gbio58' = `at'[1,52]
scalar `gbio59' = `at'[1,53]
scalar `gbio510' = -`gbio51' - `gbio52' -`gbio53' - `gbio54' -`gbio55' - `gbio56' -`gbio57' - `gbio58' - `gbio59'
scalar `gbio61' = `gbio16'
scalar `gbio62' = `gbio26'
scalar `gbio63' = `gbio36'
scalar `gbio64' = `gbio46'
scalar `gbio65' = `gbio56'
scalar `gbio66' = `at'[1,54]
scalar `gbio67' = `at'[1,55]
scalar `gbio68' = `at'[1,56]
scalar `gbio69' = `at'[1,57]
scalar `gbio610' = -`gbio61' - `gbio62' -`gbio63' - `gbio64' -`gbio65' - `gbio66' -`gbio67' - `gbio68' - `gbio69'
scalar `gbio71' = `gbio17'
scalar `gbio72' = `gbio27'
scalar `gbio73' = `gbio37'
scalar `gbio74' = `gbio47'
scalar `gbio75' = `gbio57'
scalar `gbio76' = `gbio67'
scalar `gbio77' = `at'[1,58]
scalar `gbio78' = `at'[1,59]
scalar `gbio79' = `at'[1,60]
scalar `gbio710' = -`gbio71' - `gbio72' -`gbio73' - `gbio74' -`gbio75' - `gbio76' -`gbio77' - `gbio78' - `gbio79'
scalar `gbio81' = `gbio18'
scalar `gbio82' = `gbio28'
scalar `gbio83' = `gbio38'
scalar `gbio84' = `gbio48'
scalar `gbio85' = `gbio58'
scalar `gbio86' = `gbio68'
scalar `gbio87' = `gbio78'
scalar `gbio88' = `at'[1,61]
scalar `gbio89' = `at'[1,62]
scalar `gbio810' = -`gbio81' - `gbio82' -`gbio83' - `gbio84' -`gbio85' - `gbio86' -`gbio87' - `gbio88' - `gbio89'
scalar `gbio91' = `gbio19'
scalar `gbio92' = `gbio29'
scalar `gbio93' = `gbio39'
scalar `gbio94' = `gbio49'
scalar `gbio95' = `gbio59'
scalar `gbio96' = `gbio69'
scalar `gbio97' = `gbio79'
scalar `gbio98' = `gbio89'
scalar `gbio99' = `at'[1,63]
scalar `gbio910' = -`gbio91' - `gbio92' -`gbio93' - `gbio94' -`gbio95' - `gbio96' -`gbio97' - `gbio98' - `gbio99'
scalar `gbio101' = `gbio110'
scalar `gbio102' = `gbio210'
scalar `gbio103' = `gbio310'
scalar `gbio104' = `gbio410'
scalar `gbio105' = `gbio510'
scalar `gbio106' = `gbio610'
scalar `gbio107' = `gbio710'
scalar `gbio108' = `gbio810'
scalar `gbio109' = `gbio910'
scalar `gbio1010' = -`gbio101' - `gbio102' -`gbio103' - `gbio104' -`gbio105' - `gbio106' -`gbio107' - `gbio108' - `gbio109'
tempname lbio1 lbio2 lbio3 lbio4 lbio5 lbio6 lbio7 lbio8 lbio9 lbio10 /* lambda */
scalar `lbio1' = `at'[1,64]
scalar `lbio2' = `at'[1,65]
scalar `lbio3' = `at'[1,66]
scalar `lbio4' = `at'[1,67]
scalar `lbio5' = `at'[1,68]
scalar `lbio6' = `at'[1,69]
scalar `lbio7' = `at'[1,70]
scalar `lbio8' = `at'[1,71]
scalar `lbio9' = `at'[1,72]
scalar `lbio10' = -`lbio1' - `lbio2' - `lbio3' - `lbio4' - `lbio5' - `lbio6' - `lbio7' - `lbio8' - `lbio9'
tempname del1 del2 del3 del4 del5 del6 del7 del8 del9 del10 /* delta */
scalar `del1' = `at'[1,73]
scalar `del2' = `at'[1,74]
scalar `del3' = `at'[1,75]
scalar `del4' = `at'[1,76]
scalar `del5' = `at'[1,77]
scalar `del6' = `at'[1,78]
scalar `del7' = `at'[1,79]
scalar `del8' = `at'[1,80]
scalar `del9' = `at'[1,81]
scalar `del10'= -`del1'-`del2'-`del3'-`del4'-`del5'-`del6'-`del7'-`del8'-`del9'
quietly {
* ln a(p)
tempvar lnpbioindex
forvalues k = 1/10 {
gen double `lnpbioindex' = 5 + `abio`k''*`lnpbio`k''
}
forvalues i = 1/10 {
forvalues j = 1/10 {
replace `lnpbioindex' = `lnpbioindex' + 0.5*`gbio`i'`j''*`lnpbio`i''*`lnpbio`j''
}
}
* b(p) (logarithm)
tempvar bbioofp
gen double `bbioofp' = 0
forvalues i = 1/10 {
replace `bbioofp' = `bbioofp' + `lnpbio`i''*`bbio`i''
}
* b(p)
replace `bbioofp' = exp(`bbioofp')
forvalues j = 1/10 {
replace `wbio1' = (`abio1' + `gbio1`j''*`lnpbio`j'' + `bbio1'*(`lnxbio' - `lnpbioindex')+ (`lbio1'/`bbioofp')*(`lnxbio' - `lnpbioindex')^2) * `cdf1' + `del1' * `pdf1'
replace `wbio2' = (`abio2' + `gbio2`j''*`lnpbio`j'' + `bbio2'*(`lnxbio' - `lnpbioindex')+ (`lbio2'/`bbioofp')*(`lnxbio' - `lnpbioindex')^2) * `cdf2' + `del2' * `pdf2'
replace `wbio3' = (`abio3' + `gbio3`j''*`lnpbio`j'' + `bbio3'*(`lnxbio' - `lnpbioindex')+ (`lbio3'/`bbioofp')*(`lnxbio' - `lnpbioindex')^2) * `cdf3' + `del3' * `pdf3'
replace `wbio4' = (`abio4' + `gbio4`j''*`lnpbio`j'' + `bbio4'*(`lnxbio' - `lnpbioindex')+ (`lbio4'/`bbioofp')*(`lnxbio' - `lnpbioindex')^2) * `cdf4' + `del4' * `pdf4'
replace `wbio5' = (`abio5' + `gbio5`j''*`lnpbio`j'' + `bbio5'*(`lnxbio' - `lnpbioindex')+ (`lbio5'/`bbioofp')*(`lnxbio' - `lnpbioindex')^2) * `cdf5' + `del5' * `pdf5'
replace `wbio6' = (`abio6' + `gbio6`j''*`lnpbio`j'' + `bbio6'*(`lnxbio' - `lnpbioindex')+ (`lbio6'/`bbioofp')*(`lnxbio' - `lnpbioindex')^2) * `cdf6' + `del6' * `pdf6'
replace `wbio7' = (`abio7' + `gbio7`j''*`lnpbio`j'' + `bbio7'*(`lnxbio' - `lnpbioindex')+ (`lbio7'/`bbioofp')*(`lnxbio' - `lnpbioindex')^2) * `cdf7' + `del7' * `pdf7'
replace `wbio8' = (`abio8' + `gbio8`j''*`lnpbio`j'' + `bbio8'*(`lnxbio' - `lnpbioindex')+ (`lbio8'/`bbioofp')*(`lnxbio' - `lnpbioindex')^2) * `cdf8' + `del8' * `pdf8'
replace `wbio9' = (`abio9' + `gbio9`j''*`lnpbio`j'' + `bbio9'*(`lnxbio' - `lnpbioindex')+ (`lbio9'/`bbioofp')*(`lnxbio' - `lnpbioindex')^2) * `cdf9' + `del9' * `pdf9'
}
}
end
nlsur aids @ wbio1 wbio2 wbio3 wbio4 wbio5 wbio6 wbio7 wbio8 wbio9 ///
lnpbio1 lnpbio2 lnpbio3 lnpbio4 lnpbio5 lnpbio6 lnpbio7 lnpbio8 lnpbio9 lnpbio10 lnxbio ///
cdf1 cdf2 cdf3 cdf4 cdf5 cdf6 cdf7 cdf8 cdf9 pdf1 pdf2 pdf3 pdf4 pdf5 pdf6 pdf7 pdf8 pdf9, ///
parameters(abio1 abio2 abio3 abio4 abio5 abio6 abio7 abio8 abio9 bbio1 bbio2 bbio3 bbio4 bbio5 bbio6 bbio7 bbio8 bbio9 ///
gbio11 gbio12 gbio13 gbio14 gbio15 gbio16 gbio17 gbio18 gbio19 ///
gbio22 gbio23 gbio24 gbio25 gbio26 gbio27 gbio28 gbio29 ///
gbio33 gbio34 gbio35 gbio36 gbio37 gbio38 gbio39 ///
gbio44 gbio45 gbio46 gbio47 gbio48 gbio49 ///
gbio55 gbio56 gbio57 gbio58 gbio59 ///
gbio66 gbio67 gbio68 gbio69 ///
gbio77 gbio78 gbio79 ///
gbio88 gbio89 gbio99 ///
del1 del2 del3 del4 del5 del6 del7 del8 del9 ///
lbio1 lbio2 lbio3 lbio4 lbio5 lbio6 lbio7 lbio8 lbio9) neq(9) ifgnls
***
Thanks a lot in advance
Franziska
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/