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]

st: QUAIDS


From   nigussie Tefera <nitefera@yahoo.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: QUAIDS
Date   Mon, 28 Jan 2013 06:32:50 -0800 (PST)

Dear Stataliusers,
Following my previous post on QUAIDS estimation augmented for CDF and PDF, Dr. Poi kindly correct my program path and it perfectly worked out for me when I use the food.dta data posted by Stata Corporation.  However, when I am trying to modify and use my own data that has 10 expenditure shares , 10 prices variables  and 13 demographic variables, it fails to do so.  Your kind help is really important to easy my life. I do prefer to use Poi’s quaids programme “Easy Demand Estimation techniques” but  it is difficult to augment for CDF and PDF.
Here is my progamme
*! version 1.0.0  21Jan2013
// This program uses to run nlsurquaids with constant, CDF and PDF as trial
program nlsurquaidsNN
version 12.1
syntax varlist(min=51 max=51) if, at(name)
tokenize `varlist'
args w1-w9 lnp1-lnp10 lnm x1-x13 pdf1-pdf9 cdf1-cdf9   
tempname a1 a2 a3 a4 a5 a6 a7 a8 a9 a10
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' = `at'[1,7]
scalar `a8' = `at'[1,8]
scalar `a9' = `at'[1,9]
scalar `a10' = 1 - `a1' - `a2' - `a3'- `a4'- `a5'- `a6'- `a7'- `a8'- `a9'
tempname b1 b2 b3 b4 b5 b6 b7 b8 b9 b10
scalar `b1' = `at'[1,10]
scalar `b2' = `at'[1,11]
scalar `b3' = `at'[1,12]
scalar `b4' = `at'[1,13]
scalar `b5' = `at'[1,14]
scalar `b6' = `at'[1,15]
scalar `b7' = `at'[1,16]
scalar `b8' = `at'[1,17]
scalar `b9' = `at'[1,18]
scalar `b10' = - `b1' - `b2' - `b3'- `b4'- `b5'- `b6'- `b7'- `b8'- `b9'
tempname g11 g12 g13 g14 g15 g16 g17 g18 g19 g110
tempname g21 g22 g23 g24 g25 g26 g27 g28 g29 g210
tempname g31 g32 g33 g34 g35 g36 g37 g38 g39 g310
tempname g41 g42 g43 g44 g45 g46 g47 g48 g49 g410
tempname g51 g52 g53 g54 g55 g56 g57 g58 g59 g510
tempname g61 g62 g63 g64 g65 g66 g67 g68 g69 g610
tempname g71 g72 g73 g74 g75 g76 g77 g78 g79 g710
tempname g81 g82 g83 g84 g85 g86 g87 g88 g89 g810
tempname g91 g92 g93 g94 g95 g96 g97 g98 g99 g910
tempname g101 g102 g103 g104 g105 g106 g107 g108 g109 g1010
scalar `g11' = `at'[1,19]
scalar `g12' = `at'[1,20]
scalar `g13' = `at'[1,21]
scalar `g14' = `at'[1,22]
scalar `g15' = `at'[1,23]
scalar `g16' = `at'[1,24]
scalar `g17' = `at'[1,25]
scalar `g18' = `at'[1,26]
scalar `g19' = `at'[1,27]
scalar `g110' = -`g11'-`g12'-`g13'-`g14'-`g15'-`g16'-`g17'-`g18'-`g19'
scalar `g21' = `g12'
scalar `g22' = `at'[1,28]
scalar `g23' = `at'[1,29]
scalar `g24' = `at'[1,30]
scalar `g25' = `at'[1,31]
scalar `g26' = `at'[1,32]
scalar `g27' = `at'[1,33]
scalar `g28' = `at'[1,34]
scalar `g29' = `at'[1,35]
scalar `g210' = -`g21'-`g22'-`g23'-`g24'-`g25'-`g26'-`g27'-`g28'-`g29'
scalar `g31' = `g13'
scalar `g32' = `g23'
scalar `g33' = `at'[1,36]
scalar `g34' = `at'[1,37]
scalar `g35' = `at'[1,38]
scalar `g36' = `at'[1,39]
scalar `g37' = `at'[1,40]
scalar `g38' = `at'[1,41]
scalar `g39' = `at'[1,42]
scalar `g310' = -`g31'-`g32'-`g33'-`g34'-`g35'-`g36'-`g37'-`g38'-`g39'
scalar `g41' = `g14'
scalar `g42' = `g24'
scalar `g43' = `g34'
scalar `g44' = `at'[1,43]
scalar `g45' = `at'[1,44]
scalar `g46' = `at'[1,45]
scalar `g47' = `at'[1,46]
scalar `g48' = `at'[1,47]
scalar `g49' = `at'[1,48]
scalar `g410' = -`g41'-`g42'-`g43'-`g44'-`g45'-`g46'-`g47'-`g48'-`g49'
scalar `g51' = `g15'
scalar `g52' = `g25'
scalar `g53' = `g35'
scalar `g54' = `g45'
scalar `g55' = `at'[1,49]
scalar `g56' = `at'[1,50]
scalar `g57' = `at'[1,51]
scalar `g58' = `at'[1,52]
scalar `g59' = `at'[1,53]
scalar `g510' = -`g51'-`g52'-`g53'-`g54'-`g55'-`g56'-`g57'-`g58'-`g59'
scalar `g61' = `g16'
scalar `g62' = `g26'
scalar `g63' = `g36'
scalar `g64' = `g46'
scalar `g65' = `g56'
scalar `g66' = `at'[1,54]
scalar `g67' = `at'[1,55]
scalar `g68' = `at'[1,56]
scalar `g69' = `at'[1,57]
scalar `g610' = -`g61'-`g62'-`g63'-`g64'-`g65'-`g66'-`g67'-`g68'-`g69'
scalar `g71' = `g17'
scalar `g72' = `g27'
scalar `g73' = `g37'
scalar `g74' = `g47'
scalar `g75' = `g57'
scalar `g76' = `g67'
scalar `g77' = `at'[1,58]
scalar `g78' = `at'[1,59]
scalar `g79' = `at'[1,60]
scalar `g710' = -`g71'-`g72'-`g73'-`g74'-`g75'-`g76'-`g77'-`g78'-`g79'
scalar `g81' = `g18'
scalar `g82' = `g28'
scalar `g83' = `g38'
scalar `g84' = `g48'
scalar `g85' = `g58'
scalar `g86' = `g68'
scalar `g87' = `g78'
scalar `g88' = `at'[1,61]
scalar `g89' = `at'[1,62]
scalar `g810' = -`g81'-`g82'-`g83'-`g84'-`g85'-`g86'-`g87'-`g88'-`g89'
scalar `g91' = `g19'
scalar `g92' = `g29'
scalar `g93' = `g39'
scalar `g94' = `g49'
scalar `g95' = `g59'
scalar `g96' = `g69'
scalar `g97' = `g79'
scalar `g98' = `g89'
scalar `g99' = `at'[1,63]
scalar `g910' = -`g91'-`g92'-`g93'-`g94'-`g95'-`g96'-`g97'-`g98'-`g99'
scalar `g101' = `g110'
scalar `g102' = `g210'
scalar `g103' = `g310'
scalar `g104' = `g410'
scalar `g105' = `g510'
scalar `g106' = `g610'
scalar `g107' = `g710'
scalar `g108' = `g810'
scalar `g109' = `g910'
scalar `g1010' = -`g101'-`g102'-`g103'-`g104'-`g105'-`g106'-`g107'-`g108'-`g109'
* lamida
tempname l1 l2 l3 l4 l5 l6 l7 l8 l9 l10
scalar `l1' = `at'[1,64]
scalar `l2' = `at'[1,65]
scalar `l3' = `at'[1,66]
scalar `l4' = `at'[1,67]
scalar `l5' = `at'[1,68]
scalar `l6' = `at'[1,69]
scalar `l7' = `at'[1,70]
scalar `l8' = `at'[1,71]
scalar `l9' = `at'[1,72]
scalar `l10' = - `l1' - `l2' - `l3'- `l4'- `l5'- `l6'- `l7'- `l8'- `l9'
* Constant and household demographics
tempname r11 r12 r13 r14 r15 r16 r17 r18 r19 r110 r111 r112 r113
tempname r21 r22 r23 r24 r25 r26 r27 r28 r29 r210 r211 r212 r213
tempname r31 r32 r33 r34 r35 r36 r37 r38 r39 r310 r311 r312 r313
tempname r41 r42 r43 r44 r45 r46 r47 r48 r49 r410 r411 r412 r413
tempname r51 r52 r53 r54 r55 r56 r57 r58 r59 r510 r511 r512 r513
tempname r61 r62 r63 r64 r65 r66 r67 r68 r69 r610 r611 r612 r613
tempname r71 r72 r73 r74 r75 r76 r77 r78 r79 r710 r711 r712 r713
tempname r81 r82 r83 r84 r85 r86 r87 r88 r89 r810 r811 r812 r813
tempname r91 r92 r93 r94 r95 r96 r97 r98 r99 r910 r911 r912 r913
scalar `r11' = `at'[1,73]
scalar `r12' = `at'[1,74]
scalar `r13' = `at'[1,75]
scalar `r14' = `at'[1,76]
scalar `r15' = `at'[1,77]
scalar `r16' = `at'[1,78]
scalar `r17' = `at'[1,79]
scalar `r18' = `at'[1,80]
scalar `r19' = `at'[1,81]
scalar `r110' = `at'[1,82]
scalar `r111' = `at'[1,83]
scalar `r112' = `at'[1,84]
scalar `r113' = `at'[1,85]
scalar `r21' = `at'[1,86]
scalar `r22' = `at'[1,87]
scalar `r23' = `at'[1,88]
scalar `r24' = `at'[1,89]
scalar `r25' = `at'[1,90]
scalar `r26' = `at'[1,91]
scalar `r27' = `at'[1,92]
scalar `r28' = `at'[1,93]
scalar `r29' = `at'[1,94]
scalar `r210' = `at'[1,95]
scalar `r211' = `at'[1,96]
scalar `r212' = `at'[1,97]
scalar `r213' = `at'[1,98]
scalar `r31' = `at'[1,99]
scalar `r32' = `at'[1,100]
scalar `r33' = `at'[1,101]
scalar `r34' = `at'[1,102]
scalar `r35' = `at'[1,103]
scalar `r36' = `at'[1,104]
scalar `r37' = `at'[1,105]
scalar `r38' = `at'[1,106]
scalar `r39' = `at'[1,107]
scalar `r310' = `at'[1,108]
scalar `r311' = `at'[1,109]
scalar `r312' = `at'[1,110]
scalar `r313' = `at'[1,111]
scalar `r41' = `at'[1,112]
scalar `r42' = `at'[1,113]
scalar `r43' = `at'[1,114]
scalar `r44' = `at'[1,115]
scalar `r45' = `at'[1,116]
scalar `r46' = `at'[1,117]
scalar `r47' = `at'[1,118]
scalar `r48' = `at'[1,119]
scalar `r49' = `at'[1,120]
scalar `r410' = `at'[1,121]
scalar `r411' = `at'[1,122]
scalar `r412' = `at'[1,123]
scalar `r413' = `at'[1,124]
scalar `r51' = `at'[1,125]
scalar `r52' = `at'[1,126]
scalar `r53' = `at'[1,127]
scalar `r54' = `at'[1,128]
scalar `r55' = `at'[1,129]
scalar `r56' = `at'[1,130]
scalar `r57' = `at'[1,131]
scalar `r58' = `at'[1,132]
scalar `r59' = `at'[1,133]
scalar `r510' = `at'[1,134]
scalar `r511' = `at'[1,135]
scalar `r512' = `at'[1,136]
scalar `r513' = `at'[1,137]
scalar `r61' = `at'[1,138]
scalar `r62' = `at'[1,139]
scalar `r63' = `at'[1,140]
scalar `r64' = `at'[1,141]
scalar `r65' = `at'[1,142]
scalar `r66' = `at'[1,143]
scalar `r67' = `at'[1,144]
scalar `r68' = `at'[1,145]
scalar `r69' = `at'[1,146]
scalar `r610' = `at'[1,147]
scalar `r611' = `at'[1,148]
scalar `r612' = `at'[1,149]
scalar `r613' = `at'[1,150]
scalar `r71' = `at'[1,151]
scalar `r72' = `at'[1,152]
scalar `r73' = `at'[1,153]
scalar `r74' = `at'[1,154]
scalar `r75' = `at'[1,155]
scalar `r76' = `at'[1,156]
scalar `r77' = `at'[1,157]
scalar `r78' = `at'[1,158]
scalar `r79' = `at'[1,159]
scalar `r79' = `at'[1,160]
scalar `r710' = `at'[1,161]
scalar `r711' = `at'[1,162]
scalar `r712' = `at'[1,163]
scalar `r713' = `at'[1,164]
scalar `r81' = `at'[1,165]
scalar `r82' = `at'[1,166]
scalar `r83' = `at'[1,167]
scalar `r84' = `at'[1,168]
scalar `r85' = `at'[1,169]
scalar `r86' = `at'[1,170]
scalar `r87' = `at'[1,171]
scalar `r88' = `at'[1,172]
scalar `r89' = `at'[1,173]
scalar `r810' = `at'[1,174]
scalar `r811' = `at'[1,175]
scalar `r812' = `at'[1,176]
scalar `r813' = `at'[1,177]
scalar `r91' = `at'[1,178]
scalar `r92' = `at'[1,179]
scalar `r93' = `at'[1,180]
scalar `r94' = `at'[1,181]
scalar `r95' = `at'[1,182]
scalar `r96' = `at'[1,183]
scalar `r97' = `at'[1,184]
scalar `r98' = `at'[1,185]
scalar `r99' = `at'[1,186]
scalar `r910' = `at'[1,187]
scalar `r911' = `at'[1,188]
scalar `r912' = `at'[1,189]
scalar `r913' = `at'[1,190]
* PDF
tempname d1 d2 d3 d4 d5 d6 d7 d8 d9
scalar `d1' = `at'[1,191]
scalar `d2' = `at'[1,192]
scalar `d3' = `at'[1,193]
scalar `d4' = `at'[1,194]
scalar `d5' = `at'[1,195]
scalar `d6' = `at'[1,196]
scalar `d7' = `at'[1,197]
scalar `d8' = `at'[1,198]
scalar `d9' = `at'[1,199]
* Price aggregators
quietly {
tempvar lnpindex
gen double `lnpindex' = 5 + `a1'*`lnp1' + `a2'*`lnp2' + ///
 `a3'*`lnp3' + `a4'*`lnp4' + `a5'*`lnp5'  + `a6'*`lnp6' + ///
 `a7'*`lnp7' + `a8'*`lnp8' + `a9'*`lnp9' + `a10'*`lnp10'
forvalues i = 1/10 {
forvalues j = 1/10 {
replace `lnpindex' = `lnpindex' + 0.5*`g`i'`j''*`lnp`i''*`lnp`j''
}
}
// The b(p) terms in the QUAIDS
tempvar bofp
gen double `bofp'=0
forvalues i=1/10{
replace `bofp'=`bofp' + `lnp`i''*`b`i''
 }
 replace `bofp'=exp(`bofp')
 
 // Finally the expenditure share for 9 of the 10 goods (the 10th is dropped)
 
replace `w1' =  (`a1' + `g11'*`lnp1' + `g12'*`lnp2' +               ///
    `g13'*`lnp3' + `g14'*`lnp4' + `g15'*`lnp5' +        ///
    `g16'*`lnp6' +`g17'*`lnp7' + `g18'*`lnp8' +         ///
    `g19'*`lnp9' + `g110'*`lnp10' +                     ///
    `b1'*(`lnm' - `lnpindex') +       ///
    `l1'/`bofp'*(`lnm'-`lnpindex')^2 +                  ///
    `r11'*`x1' + `r12'*`x2' + `r13'*`x3' + `r14'*`x4' + ///
       `r15'*`x5' + `r16'*`x6' + `r17'*`x7' +              ///
       `r18'*`x8' + `r19'*`x9' + `r110'*`x10' +            ///
       `r111'*`x11' + `r112'*`x12'+ `r113'*`x13')*`cdf1' + ///
    `d1'*`pdf1'
      
replace `w2' =  (`a2' + `g12'*`lnp1' + `g22'*`lnp2' +                ///
    `g23'*`lnp3' + `g24'*`lnp4' + `g25'*`lnp5' +         ///
    `g26'*`lnp6' + `g27'*`lnp7' + `g28'*`lnp8' +         ///
       `g29'*`lnp9' + `g210'*`lnp10' +      /// 
    `b1'*(`lnm' - `lnpindex') +       ///
    `l1'/`bofp'*(`lnm'-`lnpindex')^2 +      ///
    `r12'*`x1' + `r22'*`x2' + `r23'*`x3' + `r24'*`x4' +  ///
       `r25'*`x5' + `r26'*`x6' + `r27'*`x7' +               ///
       `r28'*`x8' + `r29'*`x9' + `r210'*`x10' +             ///
       `r211'*`x11' + `r212'*`x12'+ `r213'*`x13')*`cdf2' +   ///    `d2'*`pdf2'
      
replace `w3' =  (`a3' + `g13'*`lnp1' + `g23'*`lnp2' +                ///
    `g33'*`lnp3' + `g34'*`lnp4' + `g35'*`lnp5' +         ///
    `g36'*`lnp6' + `g37'*`lnp7' + `g38'*`lnp8' +         ///
       `g29'*`lnp9' + `g210'*`lnp10' +      /// 
    `b1'*(`lnm' - `lnpindex') +       ///
    `l1'/`bofp'*(`lnm'-`lnpindex')^2 +      ///
    `r13'*`x1' + `r23'*`x2' + `r33'*`x3' + `r34'*`x4' +  ///
       `r35'*`x5' + `r36'*`x6' + `r37'*`x7' +               ///
       `r38'*`x8' + `r39'*`x9' + `r310'*`x10' +             ///
       `r311'*`x11' + `r312'*`x12'+ `r313'*`x13')*`cdf3' +  ///
    `d3'*`pdf3'
    
replace `w4' =  (`a4' + `g14'*`lnp1' + `g24'*`lnp2' +               ///
       `g34'*`lnp3' + `g44'*`lnp4' + `g45'*`lnp5' +        ///
       `g46'*`lnp6' + `g47'*`lnp7' + `g48'*`lnp8' +        ///
       `g49'*`lnp9' + `g410'*`lnp10' +      ///
    `b1'*(`lnm' - `lnpindex') +       ///
    `l1'/`bofp'*(`lnm'-`lnpindex')^2 +                  ///
    `r14'*`x1' + `r24'*`x2' + `r34'*`x3' + `r44'*`x4' +  ///
       `r45'*`x5' + `r46'*`x6' + `r47'*`x7' +               ///
       `r48'*`x8' + `r49'*`x9' + `r410'*`x10' +             ///
       `r411'*`x11' + `r412'*`x12'+ `r413'*`x13')*`cdf4'+   ///
    `d4'*`pdf4'
      
replace `w5' =  (`a5' + `g11'*`lnp1' + `g25'*`lnp2' +               ///
       `g35'*`lnp3' + `g45'*`lnp4' + `g55'*`lnp5' +        ///
       `g56'*`lnp6' + `g57'*`lnp7' + `g58'*`lnp8' +        ///
       `g59'*`lnp9' + `g510'*`lnp10' +                     ///
    `b1'*(`lnm' - `lnpindex') +       ///
    `l1'/`bofp'*(`lnm'-`lnpindex')^2 +      ///
    `r15'*`x1' + `r25'*`x2' + `r35'*`x3' + `r45'*`x4' + ///
       `r55'*`x5' + `r56'*`x6' + `r57'*`x7' +              ///
       `r58'*`x8' + `r59'*`x9' + `r510'*`x10' +            ///
       `r511'*`x11' + `r512'*`x12'+ `r513'*`x13')*`cdf5' + ///
    `d5'*`pdf5'
      
replace `w6' =  (`a6' + `g16'*`lnp1' + `g26'*`lnp2' +                 ///
       `g36'*`lnp3' + `g46'*`lnp4' + `g56'*`lnp5' +          ///
       `g66'*`lnp6' + `g67'*`lnp7' + `g68'*`lnp8' +          ///
       `g69'*`lnp9' + `g610'*`lnp10' +                       ///
    `b1'*(`lnm' - `lnpindex') +         ///
    `l1'/`bofp'*(`lnm'-`lnpindex')^2 +                    ///
    `r16'*`x1' + `r26'*`x2' + `r36'*`x3' + `r46'*`x4' +   ///
       `r56'*`x5' + `r66'*`x6' + `r67'*`x7' +                ///
       `r68'*`x8' + `r69'*`x9' + `r610'*`x10' +              ///
       `r611'*`x11' + `r612'*`x12'+ `r613'*`x13')*`cdf6' +   ///
    `d6'*`pdf6'
      
replace `w7' =  (`a7' + `g17'*`lnp1' + `g27'*`lnp2' +                 ///
       `g37'*`lnp3' + `g47'*`lnp4' + `g57'*`lnp5' +          ///
       `g67'*`lnp6' + `g77'*`lnp7' + `g78'*`lnp8' +          ///
       `g79'*`lnp9' + `g710'*`lnp10' +                       ///
    `b1'*(`lnm' - `lnpindex') +         ///
    `l1'/`bofp'*(`lnm'-`lnpindex')^2 +                    ///
    `r17'*`x1' + `r27'*`x2' + `r37'*`x3' + `r47'*`x4' +   ///
       `r57'*`x5' + `r67'*`x6' + `r77'*`x7' +                ///
       `r78'*`x8' + `r79'*`x9' + `r710'*`x10' +              ///
       `r711'*`x11' +`r712'*`x12'+ `r713'*`x13')*`cdf7' +    ///
    `d7'*`pdf7'
      
replace `w8' =  (`a8' + `g18'*`lnp1' + `g28'*`lnp2' +                 ///
       `g38'*`lnp3' + `g48'*`lnp4' + `g58'*`lnp5' +          ///
       `g68'*`lnp6' + `g78'*`lnp7' + `g88'*`lnp8' +          ///
       `g89'*`lnp9' + `g810'*`lnp10' +                       ///
    `b1'*(`lnm' - `lnpindex') +         ///
    `l1'/`bofp'*(`lnm'-`lnpindex')^2 +       ///
    `r18'*`x1' + `r28'*`x2' + `r38'*`x3' + `r48'*`x4' +   ///
    `r58'*`x5' + `r68'*`x6' + `r78'*`x7' +                ///
       `r88'*`x8' + `r89'*`x9' + `r810'*`x10' +              ///
       `r811'*`x11' + `r812'*`x12'+ `r813'*`x13')*`cdf8' +   ///
    `d8'*`pdf8'
      
replace `w9' =  (`a9' + `g19'*`lnp1' + `g29'*`lnp2' +                  ///
       `g39'*`lnp3' + `g49'*`lnp4' + `g59'*`lnp5' +           ///
       `g69'*`lnp6' + `g79'*`lnp7' + `g89'*`lnp8' +           ///
       `g99'*`lnp9' + `g910'*`lnp10' +         ///
    `b1'*(`lnm' - `lnpindex') +          ///
    `l1'/`bofp'*(`lnm'-`lnpindex')^2 +         ///
    `r19'*`x1' + `r29'*`x2' + `r39'*`x3' + `r49'*`x4' +    ///
       `r59'*`x5' + `r69'*`x6' + `r79'*`x7' +                 ///
       `r89'*`x8' + `r99'*`x9' + `r910'*`x10' +               ///
       `r911'*`x11' + `r912'*`x12'+ `r913'*`x13')*`cdf9' +    ///
    `d9'*`pdf9'
}
end


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


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