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
}
}
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
}
}
Comment