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]

Re: st: nlsur function evaluator program QUAIDS with demographics


From   Jorge Eduardo Pérez Pérez <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: nlsur function evaluator program QUAIDS with demographics
Date   Fri, 8 Mar 2013 12:51:32 -0500

You can use Brian Poi's recent command -quaids- to handle all these
problems for you.

-ssc install quaids-
_______________________
Jorge Eduardo Pérez Pérez


On Fri, Mar 8, 2013 at 10:39 AM, RD <[email protected]> wrote:
> Dear Statalist-ers,
>
> I am trying to write a function evaluator program using -nlsur- in Stata 12 to estimate a QUAIDS model (Banks et al., Restat 1997) with household demographics. So far, I had no success, as Stata returns an error message:
>
> 'nlsurtry returned 199
>     - di as error "verify that nlsur`eqn' is a function evaluator program"
>     = di as error "verify that nlsurtry is a function evaluator program"
> verify that nlsurtry is a function evaluator program
>     - exit _rc'
>
> I do not understand what I am doing wrong.
>
> Also, copying the nlsurquaids program (st0029_1) by Brian Poi (2008) - which works properly - in a .ado file with a different name, placed in the same directory or in other directories "sysdir set", Stata returns the same exact error. I am puzzled.
>
> Another silly question: is it possible to write a function evaluator program including, e.g., 15 "potential" demographic variables, but practically feeding it with, say, 7? I was wondering it because otherwise I should write different programs for different sets of demographics.
>
> Last, but not least, when I use -nlcom- to compute elasticities, should I type variable mean values (for the full sample or for a subsample) to be multiplied to the coefficients or it is allowed to type variable names?
>
> Here follows the code, slightly modified to include only one demographic variable (z1), which I plan to enlarge with more demographics.
>
> Thanks in advance for your help.
>
>
> // Demographics z_k enter as taste-shifters into the share equations and,
> // to mantain integrability, are part of the a_i terms in the price index:
> // ln[a(p)] = a_0 + sum_i[a_i + sum_k(a_ik*z_k)]*ln(p_i) +
> // 1/2*sum_isum_j[g_ij*ln(p_i)*ln(p_j)]
> // the model in share form looks like:
> // w_i = a_i + sum_k(a_ik*z_k) + sum_j[g_ij*ln(p_j)] + b_i*ln[m/a(p)] +
> // [l_i/b(p)]*ln[m/a(p)]^2
> // where w_i=share of good i, p_i=price of good i, etc.
> // b(p)=prod_i(p_i^b_i)
>
> program nlsurtry
>
> version 10
> syntax varlist(min=9 max=9) if, at(name)
> tokenize `varlist'
> args w1 w2 w3 lnp1 lnp2 lnp3 lnp4 lnm z1
> 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 az11 az12 az13 az14
> scalar `az11' = `at'[1,4]
> scalar `az12' = `at'[1,5]
> scalar `az13' = `at'[1,6]
> scalar `az14' = -`az11' - `az12' - `az13'
> tempname b1 b2 b3 b4
> scalar `b1' = `at'[1,7]
> scalar `b2' = `at'[1,8]
> scalar `b3' = `at'[1,9]
> 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,10]
> scalar `g12' = `at'[1,11]
> scalar `g13' = `at'[1,12]
> scalar `g14' = -`g11' - `g12' - `g13'
>
> scalar `g21' = `g12'
> scalar `g22' = `at'[1,13]
> scalar `g23' = `at'[1,14]
> scalar `g24' = -`g21' - `g22' - `g23'
>
> scalar `g31' = `g13'
> scalar `g32' = `g23'
> scalar `g33' = `at'[1,15]
> 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,16]
> scalar `l2' = `at'[1,17]
> scalar `l3' = `at'[1,18]
> scalar `l4' = -`l1' - `l2' - `l3'
>
> quietly {
> tempvar lnpindex
> gen double `lnpindex' = 5 + `a1'*`lnp1' + `a2'*`lnp2' + `a3'*`lnp3' + `a4'*`lnp4' + `az11'*`z1'*`lnp1' + `az12'*`z1'*`lnp2' + `az13'*`z1'*`lnp3' + `az14'*`z1'*`lnp4'
>
> forvalues i = 1/4 {
> forvalues j = 1/4 {
> replace `lnpindex' = `lnpindex' + 0.5*`g`i'`j''*`lnp`i''*`lnp`j''
>           }
>   }
> tempvar bofp
> gen double `bofp' = 0
> forvalues i = 1/4 {
> replace `bofp' = `bofp' + `lnp`i''*`b`i''
>  }
> replace `bofp' = exp(`bofp')
> replace `w1' = `a1' + `az11'*`z1' + `g11'*`lnp1' + `g12'*`lnp2' +  `g13'*`lnp3' + `g14'*`lnp4' + `b1'*(`lnm' - `lnpindex')  +  `l1'/`bofp'*(`lnm' - `lnpindex')^2
> replace `w2' = `a2' + `az12'*`z1' + `g21'*`lnp1' + `g22'*`lnp2' +  `g23'*`lnp3' + `g24'*`lnp4' + `b2'*(`lnm' - `lnpindex')  +  `l2'/`bofp'*(`lnm' - `lnpindex')^2
> replace `w3' = `a3' + `az13'*`z1' + `g31'*`lnp1' + `g32'*`lnp2' + `g33'*`lnp3'  + `g34'*`lnp4' + `b3'*(`lnm' - `lnpindex')  +  `l3'/`bofp'*(`lnm' - `lnpindex')^2
>
> }
> 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/
>
>


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