This is a frequent thread in Statalist, people having trouble with their qaids evaluators. The way to find errors is to use the trace command with a high depth
and look at a run of the routine. Look at line 26 of your code:
Thats a q, not a g in q13. Should be
After that, it should work. The following example worked for me:
Code:
set trace on set tracedepth 4
Code:
scalar `g14' = - `g11' - `g12' - `q13'
Thats a q, not a g in q13. Should be
Code:
scalar `g14' = - `g11' - `g12' - `g13'
After that, it should work. The following example worked for me:
Code:
clear webuse food foreach x in dmem location poverty pdf1 pdf2 pdf3 cdf1 cdf2 cdf3 { gen `x'=uniform() } cap program drop nlsurqaids program nlsurqaids version 13 syntax varlist(min=17 max=17) if, at(name) tokenize `varlist' args w1 w2 w3 lnprice1 lnprice2 lnprice3 lnprice4 lnexptot dmem location poverty pdf1 pdf2 pdf3 cdf1 cdf2 cdf3 // With four goods, parameters can be // estimated, after eliminating one of the goods and // imposing adding up, symmetry, and homogeneity // constraints, in the QUAIDS model // Here, we extract those parameters from the `at'vector, and impose constraints as we go along ///Here, since after incorporating cdf and pdf the right hand side will not add up to one, coefficients of all equations are obtained/// tempname a1 a2 a3 a4 scalar `a1' = `at'[1,1] scalar `a2' = `at'[1,2] scalar `a3' = `at'[1,3] scalar `a4' = 1 - `a1' - `a2' - `a3' tempname b1 b2 b3 b4 scalar `b1' = `at'[1,4] scalar `b2' = `at'[1,5] scalar `b3' = `at'[1,6] scalar `b4' = - `b1' - `b2' - `b3' tempname g11 g12 g13 g14 tempname g21 g22 g23 g24 tempname g31 g32 g33 g34 tempname g41 g42 g43 g44 scalar `g11' = `at'[1,7] scalar `g12' = `at'[1,8] scalar `g13' = `at'[1,9] scalar `g14' = - `g11' - `g12' - `q13' scalar `g21' = `g12' scalar `g22' = `at'[1,10] scalar `g23' = `at'[1,11] scalar `g24' = - `g21' - `g22' - `g23' scalar `g31' = `g13' scalar `g32' = `g23' scalar `g33' = `at'[1,12] scalar `g34' = - `g31' - `g32' -`g33' scalar `g41' = `g14' scalar `g42' = `g24' scalar `g43' = `g34' scalar `g44' = - `g41' - `g42' - `g43' tempname L1 L2 L3 L4 scalar `L1' = `at'[1,13] scalar `L2' = `at'[1,14] scalar `L3' = `at'[1,15] scalar `L4' = - `L1' - `L2' - `L3' // constant and household demographics tempname r12 r13 r14 tempname r22 r23 r24 tempname r32 r33 r34 tempname r42 r43 r44 scalar `r12' = `at'[1,16] scalar `r13' = `at'[1,17] scalar `r14' = `at'[1,18] scalar `r22' = `at'[1,19] scalar `r23' = `at'[1,20] scalar `r24' = `at'[1,21] scalar `r32' = `at'[1,22] scalar `r33' = `at'[1,23] scalar `r34' = `at'[1,24] scalar `r42' = `at'[1,25] scalar `r43' = `at'[1,26] scalar `r44' = `at'[1,27] // pdf tempname d1 d2 d3 d4 scalar `d1' = `at'[1,28] scalar `d2' = `at'[1,29] scalar `d3' = `at'[1,30] scalar `d4' = `at'[1,31] //// Okay, now that we have all the parameters, we can // calculate the expenditure shares. // Okay, now that we have all the parameters, we can // calculate the expenditure shares. quietly { tempvar lnpindex gen double `lnpindex' = 4 + `a1'*`lnprice1' + `a2'*`lnprice2' + `a3'*`lnprice3' + `a4'*`lnprice4' forvalues i = 1/4 { forvalues j = 1/4 { replace `lnpindex' = `lnpindex' + 0.5*`g`i'`j''*`lnprice`i''*`lnprice`j'' } } // The b(p) term in the QUAIDS model: tempvar bofp gen double `bofp' = 0 forvalues i = 1/4 { replace `bofp' = `bofp' + `lnprice`i''*`b`i'' } replace `bofp' = exp(`bofp') replace `w1' = (`a1' + `g11'*`lnprice1' + `g12'*`lnprice2' + `g13'*`lnprice3' + `g14'*`lnprice4' + `b1'*(`lnexptot' - `lnpindex') + `L1'/`bofp'*(`lnexptot' - `lnpindex')^2 + `r12'*`dmem' + `r13'*`location' + `r14'*`poverty')*`cdf1' + `d1'*`pdf1' replace `w2' = (`a2' + `g21'*`lnprice1' + `g22'*`lnprice2' + `g23'*`lnprice3' + `g24'*`lnprice4' + `b2'*(`lnexptot' - `lnpindex') + `L2'/`bofp'*(`lnexptot' - `lnpindex')^2 + `r22'*`dmem' + `r23'*`location' + `r24'*`poverty')*`cdf2' + `d2'*`pdf2' replace `w3' = (`a3' + `g31'*`lnprice1' + `g32'*`lnprice2' + `g33'*`lnprice3' + `g34'*`lnprice4' + `b3'*(`lnexptot' - `lnpindex') + `L3'/`bofp'*(`lnexptot' - `lnpindex')^2 + `r32'*`dmem' + `r33'*`location' + `r34'*`poverty')*`cdf3' + `d3'*`pdf3' } end nlsur qaids @ w1 w2 w3 lnp1 lnp2 lnp3 lnp4 lnexp dmem location poverty pdf1 pdf2 pdf3 cdf1 cdf2 cdf3, parameters(a1 a2 a3 b1 b2 b3 g11 g12 g13 g14 g22 g23 g24 g33 g34 L1 L2 L3 r12 r13 r14 r22 r23 r24 r32 r33 r34 d1 d2 d3) ifgnls nequations(3)
Comment