Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • QUAIDS elasticities problem

    Hello Statalist, Im having some problems when creating my own code for QUAIDS Elasticities. I know there is the code from POI but I create my own code because I want to take into account the weights from my survey. I have 5 goods and the program calculates the Income, own and cross-price elasticites correctly for the first 3 goods. However, In the 4th good it shows the message Maximum number of iterations exceeded. I try to go around this problem multiplying and then dividing by 100, but Its not doing the trick. Please if anyone could help me Ill appreciate it.


    * Share means and price means
    quietly {
    foreach x of varlist w* lnp* lnexp {
    sum `x' [fweight = WeightedFactor] if incomegroup==3
    scalar `x'mean=r(mean)
    }
    * Price indexes
    glo asum "_b[a1]*lnp1mean"
    forv i=2(1)5 {
    glo asum "${asum} + _b[a`i']*lnp`i'mean"
    }
    glo gsum ""
    forv i=1(1)5 {
    forv j=1(1)5 {
    glo gsum "${gsum} + 0.5*_b[g`i'`j']*lnp`i'mean*lnp`j'mean"
    }
    }
    glo ap "5 + ${asum} ${gsum}"
    glo bp "_b[b1]*lnp1mean"
    forv i=2(1)5 {
    glo bp "${bp} + _b[b`i']*lnp`i'mean"
    }
    glo bp "(exp(${bp}))"
    * Mus
    forv i=1(1)5 {
    glo mu`i' "_b[b`i'] + 2*_b[l`i']/${bp}*(lnexpmean-(${ap}))"
    }
    forv j=1(1)5 {
    glo gsum2`j' ""
    forv k=1(1)5 {
    glo gsum2`j' "${gsum2`j'} + _b[g`j'`k']*lnp`k'mean"
    }
    }
    }
    *
    forv i=1(1)5 {
    forv j=1(1)5 {
    glo delta=cond(`i'==`j',1,0)
    glo mu`i'`j' "_b[g`i'`j'] - (${mu`i'})*(_b[a`j'] ${gsum2`j'})-_b[l`i']*_b[b`j']/${bp}*(lnexpmean - (${ap}))^2"
    cap nlcom (elasexp`i': (${mu`i'})/w`i'mean + 1) (mu`i'`j': ${mu`i'`j'}), post noheader
    if _rc {
    quietly {
    nlcom (a1:_b[/a1]) (a2:_b[/a2]) (a3:_b[/a3]) (a4:_b[/a4]) (a5:1-_b[/a1]-_b[/a2]-_b[/a3]- _b[/a4]) ///
    (b1:_b[/b1]) (b2:_b[/b2]) (b3:_b[/b3]) (b4:_b[/b4]) (b5:0-_b[/b1]-_b[/b2]-_b[/b3]- _b[/b4]) ///
    (g11:_b[/g11]) (g12:_b[/g12]) (g13:_b[/g13]) (g14:_b[/g14]) ///
    (g15:0-_b[/g11]-_b[/g12]-_b[/g13]- _b[/g14]) ///
    (g21:_b[/g12]) (g22:_b[/g22]) (g23:_b[/g23]) (g24:_b[/g24]) ///
    (g25:0-_b[/g12]-_b[/g22]-_b[/g23]- _b[/g24]) ///
    (g31:_b[/g13]) (g32:_b[/g23]) (g33:_b[/g33]) (g34:_b[/g34]) ///
    (g35:0-_b[/g13]-_b[/g23]-_b[/g33]- _b[/g34]) ///
    (g41:_b[/g14]) (g42:_b[/g24]) (g43:_b[/g34]) (g44:_b[/g44]) ///
    (g45:0-_b[/g14]-_b[/g24]-_b[/g34]- _b[/g44]) ///
    (g51:0-_b[/g11]-_b[/g12]-_b[/g13]- _b[/g14]) ///
    (g52:0-_b[/g12]-_b[/g22]-_b[/g23]- _b[/g24]) ///
    (g53:0-_b[/g13]-_b[/g23]-_b[/g33]- _b[/g34]) ///
    (g54:0-_b[/g14]-_b[/g24]-_b[/g34]- _b[/g44]) ///
    (g55:0-(0-_b[/g11]-_b[/g12]-_b[/g13]- _b[/g14]) ///
    -(0-_b[/g12]-_b[/g22]-_b[/g23]- _b[/g24]) ///
    -(0-_b[/g13]-_b[/g23]-_b[/g33]- _b[/g34]) ///
    -(0-_b[/g14]-_b[/g24]-_b[/g34]- _b[/g44])) ///
    (l1:_b[/l1]) (l2:_b[/l2]) (l3:_b[/l3]) (l4:_b[/l4])(l5:0-_b[/l1]-_b[/l2]-_b[/l3]- _b[/l4]), iterate(1000) post


    }

    *est restore Miguel
    *
    qui nlcom (elasexp`i': (${mu`i'})/w`i'mean + 1) (mu`i'`j'f: (100)*(${mu`i'`j'})), iterate(1000) post noheader
    qui nlcom (elasexp`i': _b[elasexp`i']) (mu`i'`j':_b[mu`i'`j'f]/(100)), iterate(1000) post noheader
    }

    * Uncompensated price elasticity
    nlcom (elasexp`i': _b[elasexp`i']) (elu`i'`j'_b[mu`i'`j'])/w`i'mean - ${delta}) , iterate(1000) post noheader
    * Compensated price elasticity
    nlcom (elc`i'`j': _b[elu`i'`j'] + _b[elasexp`i']*w`j'mean), iterate(1000) post noheader
    *

    est restore QUAIDS5
    *
    }
    }

    end

    Best Regards,

    Miguel Martinez

  • #2
    Miguel,

    On the main Statalist page, http://www.statalist.org/forums/, the purpose of the Sandbox forum, where this is posted is:

    Use this forum to make test posts, practice with the formatting features of the forum software, etc.
    So repost on the General Forum, but when you do, enclose all Stata code and results in code delimiters. Press the "A" (for Advanced Editor) button at the upper right of the edit window, and push the "#" to get the delimiters. This makes code much easier to read.
    Steve Samuels
    Statistical Consulting
    [email protected]

    Stata 14.2

    Comment


    • #3
      I appologize, I tough I read in sand box I should do a first comment. Thank you!

      Comment

      Working...
      X