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: QUAIDS with demographic translation


From   Khalida Akhtar Choudhury <[email protected]>
To   [email protected]
Subject   Re: st: QUAIDS with demographic translation
Date   Wed, 29 Aug 2012 16:28:13 +0100

On 29 August 2012 15:26, Nick Cox <[email protected]> wrote:
> The definition is
>
> local d1 :word count `demographics'
>
> but no local -demographics- is defined by you in the program. So -d1-
> will be zero.
>
> This kind of error can be caught by careful line-by-line reading,
> which is just how I found it.
>
> Nick
>
> On Wed, Aug 29, 2012 at 2:04 PM, Khalida Akhtar Choudhury
> <[email protected]> wrote:
>> Dear Nick,
>>
>> I've run the first few commands without the inclusion of demographic
>> variables and it has worked. I think the error lies some where with
>> the inclusion of local macro d1, and the inclusion of d1 in the model.
>>
>> Khalida
>>
>> On 29 August 2012 13:34, Nick Cox <[email protected]> wrote:
>>> This loop
>>>
>>> local j 1
>>>
>>> forvalues i = 1/$nminus1 {
>>>
>>> local w`i' `:word `j' of `varlist''
>>>
>>> local `++j'
>>>
>>> }
>>>
>>> seems unlikely to be what you intend. You don't need two macros to
>>> loop over a list, and the effect of
>>>
>>> local `++j'
>>>
>>> is not that of
>>>
>>> local ++j
>>>
>>> I'd guess that you want
>>>
>>> forvalues i = 1/$nminus1 {
>>>                   local w`i' `:word `i' of `varlist''
>>> }
>>>
>>> In general, this is a long program and I guess that you are not an
>>> experienced Stata programmer. It is best to use -set trace- and lots
>>> of -display- statements to go through your program line by line.
>>>
>>> Nick
>>>
>>>
>>> On Wed, Aug 29, 2012 at 12:40 PM, Khalida Akhtar Choudhury
>>> <[email protected]> wrote:
>>>> Hello,
>>>>
>>>> I have tried to code my own do file for QUAIDS with demographic
>>>> translation. I am using the approach of Gould & Dong (2004). There are
>>>> two differences between my approach and that of Banks et al. (1997).
>>>> There is a scalar term representing demographic variables(ti(d)) in
>>>> the welfare share equation(wi) and the expenditure m* is now dependent
>>>> on demographic variables.
>>>>
>>>> I get error 198, "nlsurquaids returned 198 verify that nlsurquaids is
>>>> a function evaluator program an error occurred when bootstrap executed
>>>> estimate."
>>>>
>>>> set seed 1
>>>>
>>>> global ngoods =3D 4 // no. of goods
>>>>
>>>> global nbootstraps =3D 3 // no. of bootstrap replications
>>>>
>>>> global anot =3D 6 // alpha_0 parameter
>>>>
>>>>
>>>>
>>>>
>>>> global nminus1 =3D $ngoods - 1
>>>>
>>>>
>>>>
>>>> capture program drop nlsurquaids
>>>>
>>>> program nlsurquaids, rclass
>>>>
>>>>
>>>>
>>>> version 10
>>>>
>>>>
>>>>
>>>> local nv =3D $ngoods + $nminus1 + 1
>>>>
>>>> syntax varlist(min=3D`=3D`nv'' max=3D`=3D`nv'') if, at(name)
>>>>
>>>>
>>>>
>>>> local j 1
>>>>
>>>> forvalues i =3D 1/$nminus1 {
>>>>
>>>> local w`i' `:word `j' of `varlist''
>>>>
>>>> local `++j'
>>>>
>>>> }
>>>>
>>>> forvalues i =3D 1/$ngoods {
>>>>
>>>> local lnp`i' `:word `j' of `varlist''
>>>>
>>>> local `++j'
>>>>
>>>> }
>>>>
>>>> local lnm `:word `j' of `varlist''
>>>>
>>>> local col 1
>>>>
>>>> local d1 :word count `demographics'
>>>>
>>>> // alpha
>>>>
>>>> forvalues i =3D 1/$nminus1 {
>>>>
>>>> tempname a`i'
>>>>
>>>> scalar `a`i'' =3D `at'[1,`col']
>>>>
>>>> local `++col'
>>>>
>>>> }
>>>>
>>>> tempname a${ngoods}
>>>>
>>>> scalar `a${ngoods}' =3D 1
>>>>
>>>> forvalues i =3D 1/$nminus1 {
>>>>
>>>> scalar `a${ngoods}' =3D `a${ngoods}' - `a`i''
>>>>
>>>> }
>>>>
>>>> // beta
>>>>
>>>> forvalues i =3D 1/$nminus1 {
>>>>
>>>> tempname b`i'
>>>>
>>>> scalar `b`i'' =3D `at'[1,`col']
>>>>
>>>> local `++col'
>>>>
>>>> }
>>>>
>>>> tempname b${ngoods}
>>>>
>>>> scalar `b${ngoods}' =3D 0
>>>>
>>>> forvalues i =3D 1/$nminus1 {
>>>>
>>>> scalar `b${ngoods}' =3D `b${ngoods}' - `b`i''
>>>>
>>>> }
>>>>
>>>> // gamma
>>>>
>>>> forvalues i =3D 1/$nminus1 {
>>>>
>>>> forvalues j =3D 1/$nminus1 {
>>>>
>>>> tempname g`i'`j'
>>>>
>>>> if `i' > `j' {
>>>>
>>>> scalar `g`i'`j'' =3D `g`j'`i''
>>>>
>>>> }
>>>>
>>>> else {
>>>>
>>>> scalar `g`i'`j'' =3D `at'[1, `col']
>>>>
>>>> local `++col'
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>> tempname g`i'${ngoods}
>>>>
>>>> scalar `g`i'${ngoods}' =3D 0
>>>>
>>>> forvalues j =3D 1/$nminus1 {
>>>>
>>>> scalar `g`i'${ngoods}' =3D  `g`i'${ngoods}' - `g`i'`j''
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>> forvalues j =3D 1/$nminus1 {
>>>>
>>>> tempname g${ngoods}`j'
>>>>
>>>> scalar `g${ngoods}`j'' =3D `g`j'${ngoods}'
>>>>
>>>> }
>>>>
>>>> tempname g${ngoods}${ngoods}
>>>>
>>>> scalar `g${ngoods}${ngoods}' =3D 0
>>>>
>>>> forvalues j =3D 1/${ngoods} {
>>>>
>>>> scalar `g${ngoods}${ngoods}' =3D `g${ngoods}${ngoods}' -  ///
>>>>
>>>> `g${ngoods}`j''
>>>>
>>>> }
>>>>
>>>> // lambda
>>>>
>>>> forvalues i =3D 1/$nminus1 {
>>>>
>>>> tempname l`i'
>>>>
>>>> scalar `l`i'' =3D `at'[1,`col']
>>>>
>>>> local `++col'
>>>>
>>>> }
>>>>
>>>> tempname l${ngoods}
>>>>
>>>> scalar `l${ngoods}' =3D 0
>>>>
>>>> forvalues i =3D 1/$nminus1 {
>>>>
>>>> scalar `l${ngoods}' =3D `l${ngoods}' - `l`i''
>>>>
>>>> }
>>>>
>>>> //omega
>>>>
>>>> forvalues i =3D 1/$nminus1 {
>>>>
>>>> tempname o`i'
>>>>
>>>> scalar `o`i'' =3D `at'[1,`col']
>>>>
>>>> local `++col'
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> quietly {
>>>>
>>>> tempvar lnpindex
>>>>
>>>> gen double `lnpindex' =3D $anot
>>>>
>>>> forvalues i =3D 1/$ngoods {
>>>>
>>>> replace `lnpindex' =3D `lnpindex' + `a`i''*`lnp`i''
>>>>
>>>> }
>>>>
>>>> forvalues i =3D 1/$ngoods {
>>>>
>>>> forvalues j =3D 1/$ngoods {
>>>>
>>>> replace `lnpindex' =3D `lnpindex' +  ///
>>>>
>>>> 0.5*`g`i'`j''*`lnp`i''*`lnp`j''
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>> tempvar bp
>>>>
>>>> gen double `bp' =3D 0
>>>>
>>>> forvalues i =3D 1/$ngoods {
>>>>
>>>> replace `bp' =3D `bp' + `lnp`i''*`b`i''
>>>>
>>>> }
>>>>
>>>> replace `bp' =3D exp(`bp')
>>>>
>>>> forvalues i =3D 1/$nminus1 {
>>>>
>>>> replace `w`i'' =3D `a`i'' + `o`i''*`demographics'
>>>>
>>>> forvalues j =3D 1/$ngoods {
>>>>
>>>> replace `w`i'' =3D `w`i'' + `g`i'`j''*`lnp`j''
>>>>
>>>> }
>>>>
>>>> replace `w`i'' =3D `w`i'' +  ///
>>>>
>>>> `o`i''*`demographics'+ ///
>>>>
>>>> `b`i''*(`lnm' - `lnpindex') + ///
>>>>
>>>> `l`i''/`bp'*(`lnm' - `lnpindex')^2
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> end
>>>>
>>>>
>>>>
>>>> // This program fits the QUAIDS model, then it calculates the elasticities
>>>>
>>>> // at the sample means.
>>>>
>>>>
>>>>
>>>> capture program drop estimate
>>>>
>>>> program estimate, rclass
>>>>
>>>>
>>>>
>>>> // Build up nlsur command
>>>>
>>>> forvalues i =3D 1/$nminus1 {
>>>>
>>>> local vlist `vlist' w`i'
>>>>
>>>> local alist `alist' a`i'
>>>>
>>>> local blist `blist' b`i'
>>>>
>>>> local llist `llist' l`i'
>>>>
>>>> local tlist `olist' o`i'
>>>>
>>>> }
>>>>
>>>> forvalues i =3D 1/$ngoods {
>>>>
>>>> local vlist `vlist' lnp`i'
>>>>
>>>> }
>>>>
>>>> local vlist `vlist' lnexp
>>>>
>>>> forvalues i =3D 1/$nminus1 {
>>>>
>>>> forvalues j =3D `i'/$nminus1 {
>>>>
>>>> local glist `glist' g`i'`j'
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>> nlsur quaids @ `vlist', ifgnls nequations($nminus1) ///
>>>>
>>>> param(`alist' `blist' `glist' `llist'`olist')
>>>> *
>>>> *   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/
>>> *
>>> *   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/
>> *
>> *   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/
> *
> *   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/
*
*   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