Hi,
I wrote a program to estimate almost ideal demand system with demographic variables.
I modified a bit from Example 5 in the STATA manual for nlsur, but could not figure it out what is wrong.
When I run it, STATA says
"nlsuraids returned 198
verify that nlsuraids is a function evaluator program "
The following is the code that I wrote.
===========
program nlsuraids
version 15
syntax varlist(min=17 max=17) if, at(name)
tokenize `varlist'
args w1 w2 w3 w4 w5 w6 lnp1 lnp2 lnp3 lnp4 lnp5 lnp6 lnp7 lnm d1 d2 d3
tempname a1 a2 a3 a4 a5 a6 a7
scalar `a1' = `at'[1,1]
scalar `a2' = `at'[1,2]
scalar `a3' = `at'[1,3]
scalar `a4' = `at'[1,4]
scalar `a5' = `at'[1,5]
scalar `a6' = `at'[1,6]
scalar `a7' = 1 - `a1' - `a2' - `a3' -`a4' -`a5' -`a6'
tempname b1 b2 b3 b4 b5 b6 b7
scalar `b1' = `at'[1,7]
scalar `b2' = `at'[1,8]
scalar `b3' = `at'[1,9]
scalar `b4' = `at'[1,10]
scalar `b5' = `at'[1,11]
scalar `b6' = `at'[1,12]
scalar `b7' = -`b1' - `b2' - `b3' - `b4' - `b5' - `b6'
tempname g11 g12 g13 g14 g15 g16 g17
tempname g21 g22 g23 g24 g25 g26 g27
tempname g31 g32 g33 g34 g35 g36 g37
tempname g41 g42 g43 g44 g45 g46 g47
tempname g51 g52 g53 g54 g55 g56 g57
tempname g61 g62 g63 g64 g65 g66 g67
tempname g71 g72 g73 g74 g75 g76 g77
scalar `g11' = `at'[1,13]
scalar `g12' = `at'[1,14]
scalar `g13' = `at'[1,15]
scalar `g14' = `at'[1,16]
scalar `g15' = `at'[1,17]
scalar `g16' = `at'[1,18]
scalar `g17' = -`g11'-`g12'-`g13'-`g14'-`g15'-`g16'
scalar `g21' = `g12'
scalar `g22' = `at'[1,19]
scalar `g23' = `at'[1,20]
scalar `g24' = `at'[1,21]
scalar `g25' = `at'[1,22]
scalar `g26' = `at'[1,23]
scalar `g27' = -`g21'-`g22'-`g23'-`g24'-`g25'-`g26'
scalar `g31' = `g13'
scalar `g32' = `g23'
scalar `g33' = `at'[1,24]
scalar `g34' = `at'[1,25]
scalar `g35' = `at'[1,26]
scalar `g36' = `at'[1,27]
scalar `g37' = -`g31'-`g32'-`g33'-`g34'-`g35'-`g36'
scalar `g41' = `g14'
scalar `g42' = `g24'
scalar `g43' = `g34'
scalar `g44' = `at'[1,28]
scalar `g45' = `at'[1,29]
scalar `g46' = `at'[1,30]
scalar `g47' = -`g41'-`g42'-`g43'-`g44'-`g45'-`g46'
scalar `g51' = `g15'
scalar `g52' = `g25'
scalar `g53' = `g35'
scalar `g54' = `g45'
scalar `g55' = `at'[1,31]
scalar `g56' = `at'[1,32]
scalar `g57' = -`g51'-`g52'-`g53'-`g54'-`g55'-`g56'
scalar `g61' = `g16'
scalar `g62' = `g26'
scalar `g63' = `g36'
scalar `g64' = `g46'
scalar `g65' = `g56'
scalar `g66' = `at'[1,33]
scalar `g67' = -`g61'-`g62'-`g63'-`g64'-`g65'-`g66'
scalar `g71' = `g17'
scalar `g72' = `g27'
scalar `g73' = `g37'
scalar `g74' = `g47'
scalar `g75' = `g57'
scalar `g76' = `g67'
scalar `g77' = -`g71'-`g72'-`g73'-`g74'-`g75'-`g76'
tempname a11 a12 a13
tempname a21 a22 a23
tempname a31 a32 a33
tempname a41 a42 a43
tempname a51 a52 a53
tempname a61 a62 a63
tempname a71 a72 a73
scalar `a11' = `at'[1,34]
scalar `a12' = `at'[1,35]
scalar `a13' = `at'[1,36]
scalar `a21' = `at'[1,37]
scalar `a22' = `at'[1,38]
scalar `a23' = `at'[1,39]
scalar `a31' = `at'[1,40]
scalar `a32' = `at'[1,41]
scalar `a33' = `at'[1,42]
scalar `a41' = `at'[1,43]
scalar `a42' = `at'[1,44]
scalar `a43' = `at'[1,45]
scalar `a51' = `at'[1,46]
scalar `a52' = `at'[1,47]
scalar `a53' = `at'[1,48]
scalar `a61' = `at'[1,49]
scalar `a62' = `at'[1,50]
scalar `a63' = `at'[1,51]
scalar `a71' = -`a11'-`a21'-`a31'-`a41'-`a51'-`a61'
scalar `a72' = -`a12'-`a22'-`a32'-`a42'-`a52'-`a62'
scalar `a73' = -`a13'-`a23'-`a33'-`a43'-`a53'-`a63'
quietly {
tempvar lnpindex
gen double `lnpindex' = 5 + (`a1'+`a11'*`d1' +`a12'*`d2' + `a13'*`d3')*`lnp1' + ///
(`a2'+`a21'*`d1' +`a22'*`d2' + `a23'*`d3')*`lnp2' + ///
(`a3'+`a31'*`d1' +`a32'*`d2' + `a33'*`d3')*`lnp3' + ///
(`a4'+`a41'*`d1' +`a42'*`d2' + `a43'*`d3')*`lnp4' + ///
(`a5'+`a51'*`d1' +`a52'*`d2' + `a53'*`d3')*`lnp5' + ///
(`a6'+`a61'*`d1' +`a62'*`d2' + `a63'*`d3')*`lnp6' + ///
(`a7'+`a71'*`d1' +`a72'*`d2' + `a73'*`d3')*`lnp7'
forvalues i = 1/7 {
forvalues j = 1/7 {
replace `lnpindex' = `lnpindex' + 0.5*`g`i'`j''*`lnp`i''*`lnp`j''
}
}
replace `w1' = `a1' + `a11'*`d1' + `a12'*`d2' + `a13'*`d3' +///
`g11'*(`lnp1'-`lnp7') + ///
`g12'*(`lnp2'-`lnp7') + ///
`g13'*(`lnp3'-`lnp7') + ///
`g14'*(`lnp4'-`lnp7') + ///
`g15'*(`lnp5'-`lnp7') + ///
`g16'*(`lnp6'-`lnp7') + ///
`b1'*(`lnm' - `lnpindex')
replace `w2' = `a2' + `a21'*`d1' +`a22'*`d2' + `a23'*`d3' +///
`g21'*(`lnp1'-`lnp7') + ///
`g22'*(`lnp2'-`lnp7') + ///
`g23'*(`lnp3'-`lnp7') + ///
`g24'*(`lnp4'-`lnp7') + ///
`g25'*(`lnp5'-`lnp7') + ///
`g26'*(`lnp6'-`lnp7') + ///
`b2'*(`lnm' - `lnpindex')
replace `w3' = `a3' + `a31'*`d1' + `a32'*`d2' + `a33'*`d3' +///
`g31'*(`lnp1'-`lnp7') + ///
`g32'*(`lnp2'-`lnp7') + ///
`g33'*(`lnp3'-`lnp7') + ///
`g34'*(`lnp4'-`lnp7') + ///
`g35'*(`lnp5'-`lnp7') + ///
`g36'*(`lnp6'-`lnp7') + ///
`b3'*(`lnm' - `lnpindex')
replace `w4' = `a4' + `a41'*`d1' + `a42'*`d2' + `a43'*`d3' +///
`g41'*(`lnp1'-`lnp7') + ///
`g42'*(`lnp2'-`lnp7') + ///
`g43'*(`lnp3'-`lnp7') + ///
`g44'*(`lnp4'-`lnp7') + ///
`g45'*(`lnp5'-`lnp7') + ///
`g46'*(`lnp6'-`lnp7') + ///
`b4'*(`lnm' - `lnpindex')
replace `w5' = `a5' + `a51'*`d1' + `a52'*`d2' + `a53'*`d3' +///
`g51'*(`lnp1'-`lnp7') + ///
`g52'*(`lnp2'-`lnp7') + ///
`g53'*(`lnp3'-`lnp7') + ///
`g54'*(`lnp4'-`lnp7') + ///
`g55'*(`lnp5'-`lnp7') + ///
`g56'*(`lnp6'-`lnp7') + ///
`b5'*(`lnm' - `lnpindex')
replace `w6' = `a6' + `a61'*`d1' + `a62'*`d2' + `a63'*`d3' +///
`g61'*(`lnp1'-`lnp7') + ///
`g62'*(`lnp2'-`lnp7') + ///
`g63'*(`lnp3'-`lnp7') + ///
`g64'*(`lnp4'-`lnp7') + ///
`g65'*(`lnp5'-`lnp7') + ///
`g66'*(`lnp6'-`lnp7') + ///
`b6'*(`lnm' - `lnpindex')
}
end
nlsur aids @ w1 w2 w3 w4 w5 w6 lnp1 lnp2 lnp3 lnp4 lnp5 lnp6 lnp7 lnm d1 d2 d3, ///
parameters(a1 a2 a3 a4 a5 a6 ///
b1 b2 b3 b4 b5 b6 ///
g11 g12 g13 g14 g15 g16 ///
g22 g23 g24 g25 g26 ///
g33 g34 g35 g36 ///
g44 g45 g46 ///
g55 g56 ///
g66 ///
a11 a12 a13 ///
a21 a22 a23 ///
a31 a32 a33 ///
a41 a42 a43 ///
a51 a52 a53 ///
a61 a62 a63) neq(6) ifgnls
0 Response to Fitting the basic AIDS model using nlsur
Post a Comment