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: nlsur command for a six commodity demand system


From   Yonas Alem <[email protected]>
To   [email protected]
Subject   st: nlsur command for a six commodity demand system
Date   Sun, 2 Jan 2011 06:51:44 -0800 (PST)

Dear Stata Users,
I'm trying to estimate a quadratic demand system of six equations but the 
function evaluator program I wrote is not working.  When I try to run the nlsur 
regression, Stata generates an error message (nlsuryonquaid returned 109-verify 
that nlsuryonquaid is a function evaluator program). 
 
Below is the function evaluator program I wrote and I would appreciate it very 
much if somone can help me figure out what the problem is.
Thanks,
Yonas
 
program nlsuryonquaid
  version 11 
  syntax varlist(min=12 max=12) if, at(name)
  tokenize `varlist'
  args w1 w2 w3 w4 w5 lnp1 lnp2 lnp3 lnp4 lnp5 lnp6 lnexp
  tempname a1 a2 a3 a4 a5 a6
  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' = 1 -`a1' - `a2' - `a3' - `a4' - `a5'
  tempname b1 b2 b3 b4 b5 b6
  scalar `b1' = `at' [1,6]
  scalar `b2' = `at' [1,7]
  scalar `b3' = `at' [1,8]
  scalar `b4' = `at' [1,9]
  scalar `b5' = `at' [1,10]
  scalar `b6' = 1 -`b1' - `b2' - `b3' - `b4' - `b5'
  tempname g11 g12 g13 g14 g15 g16
  tempname g21 g22 g23 g24 g25 g26
  tempname g31 g32 g33 g34 g35 g36
  tempname g41 g42 g43 g44 g45 g46
  tempname g51 g52 g53 g54 g55 g56
  tempname g61 g62 g63 g64 g65 g66
  scalar `g11' = `at' [1,11]
  scalar `g12' = `at' [1,12]
  scalar `g13' = `at' [1,13]
  scalar `g14' = `at' [1,14]
  scalar `g15' = `at' [1,15]
  scalar `g16' = -`g11' - `g12' - `g13'- `g14'- `g15'
  scalar `g21' = `g12' 
  scalar `g22' = `at' [1,16]
  scalar `g23' = `at' [1,17]
  scalar `g24' = `at' [1,18]
  scalar `g25' = `at' [1,19]
  scalar `g26' = -`g21' - `g22' - `g23'- `g24'- `g25'
  scalar `g31' = `g13' 
  scalar `g32' = `g23' 
  scalar `g33' = `at' [1,20]
  scalar `g34' = `at' [1,21]
  scalar `g35' = `at' [1,22]
  scalar `g36' = -`g31' - `g32' - `g33'- `g34'- `g35'
  scalar `g41' = `g14'
  scalar `g42' = `g24'
  scalar `g43' = `g34'
  scalar `g44' = `at' [1,23]
  scalar `g45' = `at' [1,24]
  scalar `g46' =  -`g41' - `g42' - `g43'- `g44'- `g45'
  scalar `g51' = `g15' 
  scalar `g52' = `g25' 
  scalar `g53' = `g35' 
  scalar `g54' = `g45' 
  scalar `g55' = `at'  [1,25]
  scalar `g56' =  -`g51' - `g52' - `g53'- `g54'- `g55'
  scalar `g61' = `g16' 
  scalar `g62' = `g26' 
  scalar `g63' = `g36' 
  scalar `g64' = `g46' 
  scalar `g65' = `g56' 
  scalar `g66' =  -`g61' - `g62' - `g63'- `g64'- `g65' 
  
  tempname l1 l2 l3 l4 l5 l6  
  scalar `l1' = `at'[1,26] 
  scalar `l2' = `at'[1,27] 
  scalar `l3' = `at'[1,28] 
  scalar `l4' = `at'[1,29] 
  scalar `l5' = `at'[1,30] 
  scalar `l6' = 1 -`l1' - `l2' - `l3'- `l4'- `l5'
    
  quietly {
    /* generate the price index */
    tempvar lnpindex
    gen double `lnpindex' = 5 +`a1'*`lnp1' 
+`a2'*`lnp2'+`a3'*`lnp3'+`a4'*`lnp4'+`a5'*`lnp5'+`a6'*`lnp6'
    forvalues i = 1/6 {
      forvalues j = 1/6 {
           replace `lnpindex' = `lnpindex'+ 0.5*`g`i'`j''*`lnp`i''*`lnp`j'' 
      }
   }
   
   /* The b(p) term in the QUAIDS model*/ 
        
  tempvar  bofp
        gen double `bofp' = 0 
        forvalues i = 1/6 { 
                  replace `bofp' = `bofp' + `lnp`i''*`b`i'' 
    
        } 
        replace `bofp' = exp(`bofp') 
   replace `w1' = `a1' + `g11'*`lnp1' + `g12'*`lnp2' + `g13'*`lnp3' + 
`g14'*`lnp4' + `g15'*`lnp5' + `g16'*`lnp6' + `b1'*(`lnexp' - `lnpindex') + 
`l1'/`bofp'*(`lnexp' - `lnpindex')^2
   replace `w2' = `a2' + `g21'*`lnp1' + `g22'*`lnp2' + `g23'*`lnp3' + 
`g24'*`lnp4' + `g25'*`lnp5' + `g26'*`lnp6' + `b2'*(`lnexp' - `lnpindex') + 
`l1'/`bofp'*(`lnexp' - `lnpindex')^2
   replace `w3' = `a3' + `g31'*`lnp1' + `g32'*`lnp2' + `g33'*`lnp3' + 
`g34'*`lnp4' + `g35'*`lnp5' + `g36'*`lnp6' + `b3'*(`lnexp' - `lnpindex') + 
`l1'/`bofp'*(`lnexp' - `lnpindex')^2
   replace `w4' = `a4' + `g41'*`lnp1' + `g42'*`lnp2' + `g43'*`lnp3' + 
`g44'*`lnp4' + `g45'*`lnp5' + `g46'*`lnp6' + `b4'*(`lnexp' - `lnpindex') + 
`l1'/`bofp'*(`lnexp' - `lnpindex')^2
   replace `w5' = `a5' + `g51'*`lnp1' + `g52'*`lnp2' + `g53'*`lnp3' + 
`g54'*`lnp4' + `g55'*`lnp5' + `g56'*`lnp6' + `b5'*(`lnexp' - `lnpindex') + 
`l1'/`bofp'*(`lnexp' - `lnpindex')^2
  }
end 

 nlsuryonquaid @ w1 w2 w3 w4 w5 lnp1 lnp2 lnp3 lnp4 lnp5 lnp6 lnexp, parameters 
(a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 /*
*/ g11 g12 g13 g14 g15 g22 g32 g33 g42 g43 g44 g52 g53 g54 g55 l1 l2 l3 l4 l5) 
neq(5) ifgnls 

_____________________________________________
PPlease consider the environment before printing this email.
 ____________________________



      

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