Announcement

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

  • Error message using QUAIDS nlcom command to calculate elasticities - “expression too long" r(130) error message

    Dear Stata listers
    I am estimating a system of 12 food demand equations using Quadratic Almost Ideal Demand System (QUAIDS) model (with demographic variables) whose coefficient estimates are saved under “quaids”. When trying to estimate price and expenditure elasticities, I get “expression too long” r(130) error message. Others have reported similar problems but I have not come across a solution.
    I am including part of my codes. From previous listings, it appears that I need to “split a long expression” but it is not clear which of lines (between lines 4 and 5 in the SECOND PART of the code) I need to split and how.
    I greatly appreciate any suggestion.
    Thank you in advance
    *****************************FIRST PART
    quietly {
    foreach x of varlist w* lnp* cdf* lnexp x hhsize numwomen {
    sum `x', d
    scalar `x'mean=r(mean)
    }
    * Compute price indices
    * First, compute the price index defined by ln a(p)
    gl asum "_b[a1]*lnp1mean +(_b[r11]*xmean + _b[r12]*hhsizemean + _b[r13]*numwomenmean)*lnp1mean"

    forv i=2(1)12{
    gl asum "${asum} + (_b[r`i'1]*xmean + _b[r`i'2]*hhsizemean + _b[r`i'3]*numwomenmean)*lnp`i'mean" //QUAIDS with demo vars
    }
    gl gsum ""
    forv i=1(1)12{
    forv j=1(1)12 {
    gl gsum "${gsum} + 0.5*_b[g`i'_`j']*lnp`i'mean*lnp`j'mean"
    }
    }
    gl ap "a_0+ ${asum} ${gsum}" // translog price index: ln a(p)

    * Then, compute the price index defined by b(p)
    gl bp "_b[b1]*lnp1mean"
    forv i=2(1)12 {
    gl bp "${bp} + _b[b`i']*lnp`i'mean"
    }
    gl bp "(exp(${bp}))" // Cobb-Douglas price aggregator b(p)

    * Computing the Mus
    * Compute expenditure elasticities of SHARES:delta budget share/delta ln-expenditure
    forv i=1(1)12 {
    gl mu`i' "(cdf`i'mean)*(_b[b`i'] + 2*_b[l`i']/${bp}*(lnexpmean-(${ap})))"
    }
    forv j=1(1)12 {
    gl gsum2`j' ""
    forv k=1(1)12 {
    gl gsum2`j' "${gsum2`j'} + _b[g`j'_`k']*lnp`k'mean"
    }
    }
    }

    *****************************SECOND PART
    forv i=1(1)12 {
    forv j=1(1)12 {
    gl delta=cond(`i'==`j',1,0) // Kronecker delta
    gl mu`i'`j' "(cdf`i'mean)*(_b[g`i'_`j'] - (${mu`i'})*(_b[a`j'] ${gsum2`j'}) -_b[l`i']*_b[b`j']/${bp}*(lnexpmean - (${ap}))^2)"
    nlcom (e`i': (${mu`i'})/w`i'mean + 1) (mu`i'`j': ${mu`i'`j'}), post

    if _rc {
    nlcom (e`i': (${mu`i'})/w`i'mean + 1) (mu`i'`j'f: 100*(${mu`i'`j'})), post

    nlcom (e`i': _b[e`i']) (mu`i'`j': _b[mu`i'`j'f]/100), post
    }
    * Uncompensated price elasticity
    nlcom (e`i': _b[e`i']) (e`i'_`j'u: _b[mu`i'`j']/w`i'mean - ${delta}), post
    mat x2 = r(b)
    mat y2 = r(V)
    mat nlcom1_el[1,`i']=x2[1..1, 1..1]
    mat nlcom2_el[`j',`i'] =x2[1..1, 2..2]
    mat nlcom1_var[1,`i']=y2[1..1,1..1]
    mat nlcom2_var[`j',`i']=y2[2..2,2..2]

    * Compensated price elasticity
    nlcom (e`i'_`j'c: _b[e`i'_`j'u] + _b[e`i']*w`j'mean), post
    mat nlcom3_el[`j',`i']=r(b)
    mat nlcom3_var[`j',`i']=r(V)

    qui est restore quaids
    }
    }



  • #2
    I'm so tired of fixing quaids routines! But I'll keep at it for the meantime until I (or someone else) work on extending Poi's code. Maybe I should write a single, clear post about this.

    Sara, are you aware of the quaids command by Brian Poi? If you are, why do you need to estimate this by hand? Are you using a censoring correction or something else that is not included in Poi's command?
    Last edited by Jorge Eduardo Perez Perez; 22 Sep 2015, 18:21.
    Jorge Eduardo Pérez Pérez
    www.jorgeperezperez.com

    Comment


    • #3
      Thank you Jorge Eduardo.

      Sorry, in my previous post I forgot to mention that I actually tried to use Poi’s “quaids” stata command at the beginning.
      But I realized that I needed to write my own evaluator function (following others) to correct for two issues. First, a significant share of the households in our sample reported zero expenditure for many food groups and so I had to use a two-step estimation approach proposed by Shonkwiler and Yen (1990) to account for this censoring. Second, one of the right hand side vars -- food expenditure – could be endogenous and so I needed to instrument it before fitting the system of food equations. “quaids” does not address this two issues and for this reason I need to estimate elasticities by hand.

      Comment


      • #4
        Try adapting the last piece of code in this post:

        http://www.statalist.org/forums/foru...-command/page2

        Jorge Eduardo Pérez Pérez
        www.jorgeperezperez.com

        Comment


        • #5
          Hi Sara,

          How did you solve your problem?
          I am trying to estimate a Quadratic Almost Ideal Demand System (QUAIDS) model (with demographic variables) for 9 food items.
          When I try to estimate price and expenditure elasticities, I get “expression too long” r(130) error message too.

          So I would like to know how did you solve this error.
          Any ideas are welcome.
          Thanks!

          Comment

          Working...
          X