Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# st: Quaids + Elasticities and censoring

 From "Joris Wauters" To Subject st: Quaids + Elasticities and censoring Date Wed, 7 Jul 2010 16:54:27 +0200

```Dear STATA users,

```
At present I am performing QUAIDS demand system estimation by altering the code provided by Poi (2008). My query concerns how to reach elasticity estimates from the Quaids coefficient estimates. More specifically:
```
```
1) Is it good practice to use sample averages for budget shares, expenditure, and prices when creating the elasticities (as done below)?
```
```
2) I add my code below as an example that should run on any pc with Poi's code and dataset installed (results available on request). Tips for improvement always welcome.
```
3)  Also tips on Censored Quaids are most welcome.

Sincerely,

JW

*********************
use food
```
nlsur quaids @ w1 w2 w3 lnp1-lnp4 lnexp, ifgnls nequations(3) param(a1 a2 a3 b1 b2 b3 g11 g12 g13 g22 g23 g33 l1 l2 l3) nolog
```
* Step 1: create averages (suffix "bar")
qui summ p1
scalar p1bar=r(mean)
scalar lnp1bar=log(p1bar)
qui summ p2
scalar p2bar=r(mean)
scalar lnp2bar=log(p2bar)
qui summ p3
scalar p3bar=r(mean)
scalar lnp3bar=log(p3bar)
qui summ p4
scalar p4bar=r(mean)
scalar lnp4bar=log(p4bar)

qui summ w1
scalar w1bar=r(mean)
qui summ w2
scalar w2bar=r(mean)
qui summ w3
scalar w3bar=r(mean)
qui summ w4
scalar w4bar=r(mean)

qui summ expfd
scalar expbar=r(mean)
scalar lnexpbar=log(expbar)

```
* Step 2: use delta method to calculate all coefficients and with the "post" option these are kept in memory (and used later)
```sjlog using demand1, replace
nlcom (a1:_b[/a1]) (a2:_b[/a2]) (a3:_b[/a3]) 			///
(a4:1-_b[/a1]-_b[/a2]-_b[/a3])				///
(b1:_b[/b1]) (b2:_b[/b2]) (b3:_b[/b3]) 			///
(b4:-_b[/b1]-_b[/b2]-_b[/b3])				///
(g11:_b[/g11]) (g12:_b[/g12]) (g13:_b[/g13]) 		///
(g14:-_b[/g11]-_b[/g12]-_b[/g13])			///
(g21:_b[/g12]) (g22:_b[/g22]) (g23:_b[/g23]) 				///
(g24:-_b[/g12]-_b[/g22]-_b[/g23])			///
(g31:_b[/g13]) (g32:_b[/g23]) (g33:_b[/g33]) ///
(g34:-_b[/g13]-_b[/g23]-_b[/g33])		///
```
(g41:-_b[/g11]-_b[/g12]-_b[/g13]) (g42:-_b[/g12]-_b[/g22]-_b[/g23]) (g43:-_b[/g13]-_b[/g23]-_b[/g33]) ///
```	(g44:-(-_b[/g11]-_b[/g12]-_b[/g13]) - 			///
(-_b[/g12]-_b[/g22]-_b[/g23]) -				///
(-_b[/g13]-_b[/g23]-_b[/g33]))				///
(l1:_b[/l1]) (l2:_b[/l2]) (l3:_b[/l3]) 		///
(l4:-_b[/l1]-_b[/l2]-_b[/l3]), post iterate(999)
sjlog close, replace

scalar bofp = 0
forvalues i = 1/4 {
scalar bofp = bofp + lnp`i'bar*_b[b`i']
}
scalar bofp = exp(bofp)
di bofp

scalar aofp=0  //
scalar aofp = 5 + _b[a1]*lnp1bar + _b[a2]*lnp2bar	///
+ _b[a3]*lnp3bar + _b[a4]*lnp4bar

forvalues i = 1/4 {
forvalues j = 1/4 {
scalar aofp = aofp + 0.5*_b[g`i'`j']*lnp`i'bar*lnp`j'bar
}
}
scalar aofp=exp(aofp)

```
* Finally, we calculate the elasticities at the average values for budget shares, expenditure and prices
```
nlcom (e1: (_b[b1] + 2*_b[l1]/bofp * (lnexpbar-log(aofp)) )/w1bar +1)   ///
(e2: (_b[b2] + 2*_b[l2]/bofp * (lnexpbar-log(aofp)) )/w2bar +1)  ///
(e3: (_b[b3] + 2*_b[l3]/bofp * (lnexpbar-log(aofp)) )/w3bar +1)  ///
(e4: (_b[b4] + 2*_b[l4]/bofp * (lnexpbar-log(aofp)) )/w4bar +1) ///
```
(e11u: (_b[g11] - (_b[b1] + 2*_b[l1]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a1]+_b[g11]*lnp1bar+_b[g12]*lnp2bar+_b[g13]*lnp3bar+_b[g14]*lnp4bar) - _b[l1]*_b[b1]/bofp *(lnexpbar-log(aofp))^2 )/w1bar -1 ) /// (e12u: (_b[g12] - (_b[b1] + 2*_b[l1]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a2]+_b[g21]*lnp1bar+_b[g22]*lnp2bar+_b[g23]*lnp3bar+_b[g24]*lnp4bar) - _b[l1]*_b[b2]/bofp *(lnexpbar-log(aofp))^2 )/w1bar -0 ) /// (e13u: (_b[g13] - (_b[b1] + 2*_b[l1]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a3]+_b[g31]*lnp1bar+_b[g32]*lnp2bar+_b[g33]*lnp3bar+_b[g34]*lnp4bar) - _b[l1]*_b[b3]/bofp *(lnexpbar-log(aofp))^2 )/w1bar -0 ) /// (e14u: (_b[g14] - (_b[b1] + 2*_b[l1]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a4]+_b[g41]*lnp1bar+_b[g42]*lnp2bar+_b[g43]*lnp3bar+_b[g44]*lnp4bar) - _b[l1]*_b[b4]/bofp *(lnexpbar-log(aofp))^2 )/w1bar -0 ) /// (e21u: (_b[g21] - (_b[b2] + 2*_b[l2]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a1]+_b[g11]*lnp1bar+_b[g12]*lnp2bar+_b[g13]*lnp3bar+_b[g14]*lnp4bar) - _b[l2]*_b[b1]/bofp *(lnexpbar-log(aofp))^2 )/w2bar -0 ) /// (e22u: (_b[g22] - (_b[b2] + 2*_b[l2]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a2]+_b[g21]*lnp1bar+_b[g22]*lnp2bar+_b[g23]*lnp3bar+_b[g24]*lnp4bar) - _b[l2]*_b[b2]/bofp *(lnexpbar-log(aofp))^2 )/w2bar -1 ) /// (e23u: (_b[g23] - (_b[b2] + 2*_b[l2]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a3]+_b[g31]*lnp1bar+_b[g32]*lnp2bar+_b[g33]*lnp3bar+_b[g34]*lnp4bar) - _b[l2]*_b[b3]/bofp *(lnexpbar-log(aofp))^2 )/w2bar -0 ) /// (e24u: (_b[g24] - (_b[b2] + 2*_b[l2]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a4]+_b[g41]*lnp1bar+_b[g42]*lnp2bar+_b[g43]*lnp3bar+_b[g44]*lnp4bar) - _b[l2]*_b[b4]/bofp *(lnexpbar-log(aofp))^2 )/w2bar -0 ) /// (e31u: (_b[g31] - (_b[b3] + 2*_b[l3]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a1]+_b[g11]*lnp1bar+_b[g12]*lnp2bar+_b[g13]*lnp3bar+_b[g14]*lnp4bar) - _b[l3]*_b[b1]/bofp *(lnexpbar-log(aofp))^2 )/w3bar -0 ) /// (e32u: (_b[g32] - (_b[b3] + 2*_b[l3]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a2]+_b[g21]*lnp1bar+_b[g22]*lnp2bar+_b[g23]*lnp3bar+_b[g24]*lnp4bar) - _b[l3]*_b[b2]/bofp *(lnexpbar-log(aofp))^2 )/w3bar -0 ) /// (e33u: (_b[g33] - (_b[b3] + 2*_b[l3]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a3]+_b[g31]*lnp1bar+_b[g32]*lnp2bar+_b[g33]*lnp3bar+_b[g34]*lnp4bar) - _b[l3]*_b[b3]/bofp *(lnexpbar-log(aofp))^2 )/w3bar -1 ) /// (e34u: (_b[g34] - (_b[b3] + 2*_b[l3]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a4]+_b[g41]*lnp1bar+_b[g42]*lnp2bar+_b[g43]*lnp3bar+_b[g44]*lnp4bar) - _b[l3]*_b[b4]/bofp *(lnexpbar-log(aofp))^2 )/w3bar -0 ) /// (e41u: (_b[g41] - (_b[b4] + 2*_b[l4]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a1]+_b[g11]*lnp1bar+_b[g12]*lnp2bar+_b[g13]*lnp3bar+_b[g14]*lnp4bar) - _b[l4]*_b[b1]/bofp *(lnexpbar-log(aofp))^2 )/w4bar -0 ) /// (e42u: (_b[g42] - (_b[b4] + 2*_b[l4]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a2]+_b[g21]*lnp1bar+_b[g22]*lnp2bar+_b[g23]*lnp3bar+_b[g24]*lnp4bar) - _b[l4]*_b[b2]/bofp *(lnexpbar-log(aofp))^2 )/w4bar -0 ) /// (e43u: (_b[g43] - (_b[b4] + 2*_b[l4]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a3]+_b[g31]*lnp1bar+_b[g32]*lnp2bar+_b[g33]*lnp3bar+_b[g34]*lnp4bar) - _b[l4]*_b[b3]/bofp *(lnexpbar-log(aofp))^2 )/w4bar -0 ) /// (e44u: (_b[g44] - (_b[b4] + 2*_b[l4]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a4]+_b[g41]*lnp1bar+_b[g42]*lnp2bar+_b[g43]*lnp3bar+_b[g44]*lnp4bar) - _b[l4]*_b[b4]/bofp *(lnexpbar-log(aofp))^2 )/w4bar -1 ) /// (e11c: w1bar*((_b[b1] + 2*_b[l1]/bofp * (lnexpbar-log(aofp)) )/w1bar +1) + ((_b[g11] - (_b[b1] + 2*_b[l1]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a1]+_b[g11]*lnp1bar+_b[g12]*lnp2bar+_b[g13]*lnp3bar+_b[g14]*lnp4bar) - _b[l1]*_b[b1]/bofp *(lnexpbar-log(aofp))^2 )/w1bar -1 )) /// (e12c: w2bar*((_b[b1] + 2*_b[l1]/bofp * (lnexpbar-log(aofp)) )/w1bar +1) + ((_b[g12] - (_b[b1] + 2*_b[l1]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a2]+_b[g21]*lnp1bar+_b[g22]*lnp2bar+_b[g23]*lnp3bar+_b[g24]*lnp4bar) - _b[l1]*_b[b2]/bofp *(lnexpbar-log(aofp))^2 )/w1bar -0 )) /// (e13c: w3bar*((_b[b1] + 2*_b[l1]/bofp * (lnexpbar-log(aofp)) )/w1bar +1) + ((_b[g13] - (_b[b1] + 2*_b[l1]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a3]+_b[g31]*lnp1bar+_b[g32]*lnp2bar+_b[g33]*lnp3bar+_b[g34]*lnp4bar) - _b[l1]*_b[b3]/bofp *(lnexpbar-log(aofp))^2 )/w1bar -0 )) /// (e14c: w4bar*((_b[b1] + 2*_b[l1]/bofp * (lnexpbar-log(aofp)) )/w1bar +1) + ((_b[g14] - (_b[b1] + 2*_b[l1]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a4]+_b[g41]*lnp1bar+_b[g42]*lnp2bar+_b[g43]*lnp3bar+_b[g44]*lnp4bar) - _b[l1]*_b[b4]/bofp *(lnexpbar-log(aofp))^2 )/w1bar -0 )) /// (e21c: w1bar*((_b[b2] + 2*_b[l2]/bofp * (lnexpbar-log(aofp)) )/w2bar +1) + ((_b[g21] - (_b[b2] + 2*_b[l2]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a1]+_b[g11]*lnp1bar+_b[g12]*lnp2bar+_b[g13]*lnp3bar+_b[g14]*lnp4bar) - _b[l2]*_b[b1]/bofp *(lnexpbar-log(aofp))^2 )/w2bar -0 )) /// (e22c: w2bar*((_b[b2] + 2*_b[l2]/bofp * (lnexpbar-log(aofp)) )/w2bar +1) + ((_b[g22] - (_b[b2] + 2*_b[l2]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a2]+_b[g21]*lnp1bar+_b[g22]*lnp2bar+_b[g23]*lnp3bar+_b[g24]*lnp4bar) - _b[l2]*_b[b2]/bofp *(lnexpbar-log(aofp))^2 )/w2bar -1 )) /// (e23c: w3bar*((_b[b2] + 2*_b[l2]/bofp * (lnexpbar-log(aofp)) )/w2bar +1) + ((_b[g23] - (_b[b2] + 2*_b[l2]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a3]+_b[g31]*lnp1bar+_b[g32]*lnp2bar+_b[g33]*lnp3bar+_b[g34]*lnp4bar) - _b[l2]*_b[b3]/bofp *(lnexpbar-log(aofp))^2 )/w2bar -0 )) /// (e24c: w4bar*((_b[b2] + 2*_b[l2]/bofp * (lnexpbar-log(aofp)) )/w2bar +1) + ((_b[g24] - (_b[b2] + 2*_b[l2]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a4]+_b[g41]*lnp1bar+_b[g42]*lnp2bar+_b[g43]*lnp3bar+_b[g44]*lnp4bar) - _b[l2]*_b[b4]/bofp *(lnexpbar-log(aofp))^2 )/w2bar -0 )) /// (e31c: w1bar*((_b[b3] + 2*_b[l3]/bofp * (lnexpbar-log(aofp)) )/w3bar +1) + ((_b[g31] - (_b[b3] + 2*_b[l3]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a1]+_b[g11]*lnp1bar+_b[g12]*lnp2bar+_b[g13]*lnp3bar+_b[g14]*lnp4bar) - _b[l3]*_b[b1]/bofp *(lnexpbar-log(aofp))^2 )/w3bar -0 )) /// (e32c: w2bar*((_b[b3] + 2*_b[l3]/bofp * (lnexpbar-log(aofp)) )/w3bar +1) + ((_b[g32] - (_b[b3] + 2*_b[l3]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a2]+_b[g21]*lnp1bar+_b[g22]*lnp2bar+_b[g23]*lnp3bar+_b[g24]*lnp4bar) - _b[l3]*_b[b2]/bofp *(lnexpbar-log(aofp))^2 )/w3bar -0 )) /// (e33c: w3bar*((_b[b3] + 2*_b[l3]/bofp * (lnexpbar-log(aofp)) )/w3bar +1) + ((_b[g33] - (_b[b3] + 2*_b[l3]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a3]+_b[g31]*lnp1bar+_b[g32]*lnp2bar+_b[g33]*lnp3bar+_b[g34]*lnp4bar) - _b[l3]*_b[b3]/bofp *(lnexpbar-log(aofp))^2 )/w3bar -1 )) /// (e34c: w4bar*((_b[b3] + 2*_b[l3]/bofp * (lnexpbar-log(aofp)) )/w3bar +1) + ((_b[g34] - (_b[b3] + 2*_b[l3]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a4]+_b[g41]*lnp1bar+_b[g42]*lnp2bar+_b[g43]*lnp3bar+_b[g44]*lnp4bar) - _b[l3]*_b[b4]/bofp *(lnexpbar-log(aofp))^2 )/w3bar -0 )) /// (e41c: w1bar*((_b[b4] + 2*_b[l4]/bofp * (lnexpbar-log(aofp)) )/w4bar +1) + ((_b[g41] - (_b[b4] + 2*_b[l4]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a1]+_b[g11]*lnp1bar+_b[g12]*lnp2bar+_b[g13]*lnp3bar+_b[g14]*lnp4bar) - _b[l4]*_b[b1]/bofp *(lnexpbar-log(aofp))^2 )/w4bar -0 )) /// (e42c: w2bar*((_b[b4] + 2*_b[l4]/bofp * (lnexpbar-log(aofp)) )/w4bar +1) + ((_b[g42] - (_b[b4] + 2*_b[l4]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a2]+_b[g21]*lnp1bar+_b[g22]*lnp2bar+_b[g23]*lnp3bar+_b[g24]*lnp4bar) - _b[l4]*_b[b2]/bofp *(lnexpbar-log(aofp))^2 )/w4bar -0 )) /// (e43c: w3bar*((_b[b4] + 2*_b[l4]/bofp * (lnexpbar-log(aofp)) )/w4bar +1) + ((_b[g43] - (_b[b4] + 2*_b[l4]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a3]+_b[g31]*lnp1bar+_b[g32]*lnp2bar+_b[g33]*lnp3bar+_b[g34]*lnp4bar) - _b[l4]*_b[b3]/bofp *(lnexpbar-log(aofp))^2 )/w4bar -0 )) /// (e44c: w4bar*((_b[b4] + 2*_b[l4]/bofp * (lnexpbar-log(aofp)) )/w4bar +1) + ((_b[g44] - (_b[b4] + 2*_b[l4]/bofp * (lnexpbar- log(aofp) ) ) * (_b[a4]+_b[g41]*lnp1bar+_b[g42]*lnp2bar+_b[g43]*lnp3bar+_b[g44]*lnp4bar) - _b[l4]*_b[b4]/bofp *(lnexpbar-log(aofp))^2 )/w4bar -1 ))
```

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