Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: Delta Method after Quaids

 From Syed Basher To statalist@hsphsun2.harvard.edu Subject Re: st: Delta Method after Quaids Date Tue, 24 Dec 2013 07:11:43 +0300

```Hi Guilherme,

I am working on a similar issue. Have you looked at Brian Poi's recent
Stata Journal article (Vol 12 No 3, 2012, pp-433-446) on "quaids"? It
allows to calculate price elasticities without the need for any
programming. Hope you find it useful.

Syed Basher
Doha, Qatar.

On Tue, Dec 24, 2013 at 4:04 AM, Guilherme Travassos
<travassosgf@hotmail.com> wrote:
>
> Dear Statalisters,
>
> I'm using nlsur Quaids from Brian Poi (2008) to estimate a seven group demand system for meat products with some restrictions. After I estimate the model, I want to use delta method to calculate all coefficients and elasticities at the average values for budget shares, expenditure and prices. But I'm have some problemas wiht the delta method. After I run the codes, Stata give me this message: unknown function (). I don't know what it is.
> Could anyone help me?
> I'm sending delta method code.
> * Step 1: create averages (suffix "bar")
> qui summ lnp1
> scalar lnp1bar=r(mean)
> qui summ lnp2
> scalar lnp2bar=r(mean)
> qui summ lnp3
> scalar lnp3bar=r(mean)
> qui summ lnp4
> scalar lnp4bar=r(mean)
> qui summ lnp5
> scalar lnp5bar=r(mean)
> qui summ lnp6
> scalar lnp6bar=r(mean)
> qui summ lnp7
> scalar lnp7bar=r(mean)
>
> 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 w5
> scalar w5bar=r(mean)
> qui summ w6
> scalar w6bar=r(mean)
> qui summ w7
> scalar w7bar=r(mean)
>
> qui summ F1
> scalar F1bar=r(mean)
> qui summ F2
> scalar F2bar=r(mean)
> qui summ F3
> scalar F3bar=r(mean)
> qui summ F4
> scalar F4bar=r(mean)
> qui summ F5
> scalar F5bar=r(mean)
> qui summ F6
> scalar F6bar=r(mean)
> qui summ F7
> scalar F7bar=r(mean)
>
> qui summ lnexp
> scalar lnexpbar=r(mean)
>
> qui summ lnpindex
> scalar lnpindexbar=r(mean)
>
> * Step 2: use delta method to calculate all coefficients and with the "post" option these are kept in memory (and used later)
>
> nlcom (a1:_b[/b1])(a2:_b[/b2])(a3:_b[/b3])(a4:_b[/b4])(a5:_b[/b5])(a6:_b[/b6]) ///
> (a7:1-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]) ///
> (b1:_b[/b7])(b2:_b[/b8])(b3:_b[/b9])(b4:_b[/b10])(b5:_b[/b11])(b6:_b[/b12]) ///
> (b7:-_b[/b7]-_b[/b8]-_b[/b9]-_b[/b10]-_b[/b11]-_b[/b12]) ///
> (g11:_b[/b13])(g12:_b[/b14])(g13:_b[/b15])(g14:_b[/b16])(g15:_b[/b17])(g16:_b[/b18]) //
> (g21:_b[/b19])(g22:_b[/b20])(g23:_b[/b21])(g24:_b[/b22])(g25:_b[/b23])(g26:_b[/b24]) //
> (g31:_b[/b25])(g32:_b[/b26])(g33:_b[/b27])(g34:_b[/b28])(g35:_b[/b29])(g36:_b[/b30]) ///
> (g41:_b[/b31])(g42:_b[/b32])(g43:_b[/b33])(g44:_b[/b34])(g45:_b[/b35])(g46:_b[/b36]) ///
> (g51:_b[/b37])(g52:_b[/b38])(g53:_b[/b39])(g54:_b[/b40])(g55:_b[/b41])(g56:_b[/b42]) ///
> (g61:_b[/b43])(g62:_b[/b44])(g63:_b[/b45])(g64:_b[/b46])(g65:_b[/b47])(g66:_b[/b48]) (g67:_b[/49]) ///
> (g17:((_b[/b1]+_b[/b7])/(_b[/b6]+_b[/b12]))*(_b[/b49]+_b[/b6]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-_b[/b1]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6])) ///
> (g27:((_b[/b2]+_b[/b8])/(_b[/b6]+_b[/b12]))*(_b[/b49]+_b[/b6]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-_b[/b2]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6])) ///
> (g37:((_b[/b3]+_b[/b9])/(_b[/b6]+_b[/b12]))*(_b[/b49]+_b[/b6]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-_b[/b3]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6])) ///
> (g47:((_b[/b4]+_b[/b10])/(_b[/b6]+_b[/b12]))*(_b[/b49]+_b[/b6]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-_b[/b4]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6])) ///
> (g57:((_b[/b5]+_b[/b11])/(_b[/b6]+_b[/b12]))*(_b[/b49]+_b[/b6]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-_b[/b5]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6])) ///
> (g71:-_b[/b13]-_b[/b19]-_b[/b25]-_b[/b31]-_b[/b37]-_b[/b43]) ///
> (g72:-_b[/b14]-_b[/b20]-_b[/b26]-_b[/b32]-_b[/b38]-_b[/b44]) ///
> (g73:-_b[/b15]-_b[/b21]-_b[/b27]-_b[/b33]-_b[/b39]-_b[/b45]) ///
> (g74:-_b[/b16]-_b[/b22]-_b[/b28]-_b[/b34]-_b[/b40]-_b[/b46]) ///
> (g75:-_b[/b17]-_b[/b23]-_b[/b29]-_b[/b35]-_b[/b41]-_b[/b47]) ///
> (g76:-_b[/b18]-_b[/b24]-_b[/b30]-_b[/b36]-_b[/b42]-_b[/b48]) ///
> (g77:-((_b[/b1]+_b[/b7])/(_b[/b6]+_b[/b12]))*(_b[/b49]+_b[/b6]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-_b[/b1]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-(((_b[/b2]+_b[/b8])/(_b[/b6]+_b[/b12]))*(_b[/b49]+_b[/b6]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-_b[/b2]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-(((_b[/b3]+_b[/b9])/(_b[/b6]+_b[/b12]))*(_b[/b49]+_b[/b6]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-_b[/b3]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-(((_b[/b4]+_b[/b10])/(_b[/b6]+_b[/b12]))*(_b[/b49]+_b[/b6]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-_b[/b4]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-(((_b[/b5]+_b[/b11])/(_b[/b6]+_b[/b12]))*(_b[/b49]+_b[/b6]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-_b[/b5]*(-_b[/b1]-_b[/b2]-_b[/b3]-_b[/b4]-_b[/b5]-_b[/b6]))-_b[/49])) ///
> (l1:_b[/b50])(l2:_b[/b51])(l3:_b[/b52])(l4:_b[/b53])(l5:_b[/b54])(l6:_b[/b55]) ///
> (l7:-_b[/b50]-_b[/b51]-_b[/b52]-_b[/b53]-_b[/b54]-_b[/b55]), post iterate(999)
>
> scalar bofp = 0
> forvalues i = 1/7 {
> forvalues j = 1/7 {
> scalar bofp = bofp + lnp`i'bar*_b[b`i']
> }
> }
> scalar bofp = exp(bofp)
> di bofp
>
> scalar bofp = r(mean)
> di bofp
>
> scalar aofp = lnpindexbar
>
>
> * Finally, we calculate the elasticities at the average values for budget shares, expenditure and prices
>
> nlcom (e1: F1bar*((_b[b1]+2*_b[l1]/bofp*(lnexpbar-aofp)))/w1bar+1) ///
> (e2: F2bar*((_b[b2]+2*_b[l2]/bofp*(lnexpbar-aofp)))/w2bar+1) ///
> (e3: F3bar*((_b[b3]+2*_b[l3]/bofp*(lnexpbar-aofp)))/w3bar+1) ///
> (e4: F4bar*((_b[b4]+2*_b[l4]/bofp*(lnexpbar-aofp)))/w4bar+1) ///
> (e5: F5bar*((_b[b5]+2*_b[l5]/bofp*(lnexpbar-aofp)))/w5bar+1) ///
> (e6: F6bar*((_b[b6]+2*_b[l6]/bofp*(lnexpbar-aofp)))/w6bar+1) ///
> (e7: F7bar*((_b[b7]+2*_b[l7]/bofp*(lnexpbar-aofp)))/w7bar+1) ///
> (eu11:(F1bar*(_b[g11]-(_b[b1]+2*_b[l1]/bofp*(lnexpbar-aofp))*w1bar-_b[b1]*_b[l1]*(lnexpbar-aofp)^2/bofp)/w1bar)) ///
> (eu22:(F2bar*(_b[g22]-(_b[b2]+2*_b[l2]/bofp*(lnexpbar-aofp))*w2bar-_b[b2]*_b[l2]*(lnexpbar-aofp)^2/bofp)/w2bar)) ///
> (eu33:(F3bar*(_b[g33]-(_b[b3]+2*_b[l3]/bofp*(lnexpbar-aofp))*w3bar-_b[b3]*_b[l3]*(lnexpbar-aofp)^2/bofp)/w3bar)) ///
> (eu44:(F4bar*(_b[g44]-(_b[b4]+2*_b[l4]/bofp*(lnexpbar-aofp))*w4bar-_b[b4]*_b[l4]*(lnexpbar-aofp)^2/bofp)/w4bar)) ///
> (eu55:(F5bar*(_b[g55]-(_b[b5]+2*_b[l5]/bofp*(lnexpbar-aofp))*w5bar-_b[b5]*_b[l5]*(lnexpbar-aofp)^2/bofp)/w5bar)) ///
> (eu66:(F6bar*(_b[g66]-(_b[b6]+2*_b[l6]/bofp*(lnexpbar-aofp))*w6bar-_b[b6]*_b[l6]*(lnexpbar-aofp)^2/bofp)/w6bar)) ///
> (eu12:(F2bar*(_b[g12]-(_b[b1]+2*_b[l1]/bofp*(lnexpbar-aofp))*w2bar-_b[b2]*_b[l1]*(lnexpbar-aofp)^2/bofp)/w1bar)) ///
> (eu13:(F3bar*(_b[g13]-(_b[b1]+2*_b[l1]/bofp*(lnexpbar-aofp))*w3bar-_b[b3]*_b[l1]*(lnexpbar-aofp)^2/bofp)/w1bar)) ///
> (eu14:(F4bar*(_b[g14]-(_b[b1]+2*_b[l1]/bofp*(lnexpbar-aofp))*w4bar-_b[b4]*_b[l1]*(lnexpbar-aofp)^2/bofp)/w1bar)) ///
> (eu15:(F5bar*(_b[g15]-(_b[b1]+2*_b[l1]/bofp*(lnexpbar-aofp))*w5bar-_b[b5]*_b[l1]*(lnexpbar-aofp)^2/bofp)/w1bar)) ///
> (eu16:(F6bar*(_b[g16]-(_b[b1]+2*_b[l1]/bofp*(lnexpbar-aofp))*w6bar-_b[b6]*_b[l1]*(lnexpbar-aofp)^2/bofp)/w1bar)) ///
> (eu17:(F7bar*(_b[g17]-(_b[b1]+2*_b[l1]/bofp*(lnexpbar-aofp))*w7bar-_b[b7]*_b[l1]*(lnexpbar-aofp)^2/bofp)/w1bar)) ///
> (eu21:(F1bar*(_b[g21]-(_b[b2]+2*_b[l2]/bofp*(lnexpbar-aofp))*w1bar-_b[b1]*_b[l2]*(lnexpbar-aofp)^2/bofp)/w2bar)) ///
> (eu23:(F3bar*(_b[g23]-(_b[b2]+2*_b[l2]/bofp*(lnexpbar-aofp))*w3bar-_b[b3]*_b[l2]*(lnexpbar-aofp)^2/bofp)/w2bar)) ///
> (eu24:(F4bar*(_b[g24]-(_b[b2]+2*_b[l2]/bofp*(lnexpbar-aofp))*w4bar-_b[b4]*_b[l2]*(lnexpbar-aofp)^2/bofp)/w2bar)) ///
> (eu25:(F5bar*(_b[g25]-(_b[b2]+2*_b[l2]/bofp*(lnexpbar-aofp))*w5bar-_b[b5]*_b[l2]*(lnexpbar-aofp)^2/bofp)/w2bar)) ///
> (eu26:(F6bar*(_b[g26]-(_b[b2]+2*_b[l2]/bofp*(lnexpbar-aofp))*w6bar-_b[b6]*_b[l2]*(lnexpbar-aofp)^2/bofp)/w2bar)) ///
> (eu27:(F7bar*(_b[g27]-(_b[b2]+2*_b[l2]/bofp*(lnexpbar-aofp))*w7bar-_b[b7]*_b[l2]*(lnexpbar-aofp)^2/bofp)/w2bar)) ///
> (eu31:(F1bar*(_b[g31]-(_b[b3]+2*_b[l3]/bofp*(lnexpbar-aofp))*w1bar-_b[b1]*_b[l3]*(lnexpbar-aofp)^2/bofp)/w3bar)) ///
> (eu32:(F2bar*(_b[g32]-(_b[b3]+2*_b[l3]/bofp*(lnexpbar-aofp))*w2bar-_b[b2]*_b[l3]*(lnexpbar-aofp)^2/bofp)/w3bar)) ///
> (eu34:(F4bar*(_b[g34]-(_b[b3]+2*_b[l3]/bofp*(lnexpbar-aofp))*w4bar-_b[b4]*_b[l3]*(lnexpbar-aofp)^2/bofp)/w3bar)) ///
> (eu35:(F5bar*(_b[g35]-(_b[b3]+2*_b[l3]/bofp*(lnexpbar-aofp))*w5bar-_b[b5]*_b[l3]*(lnexpbar-aofp)^2/bofp)/w3bar)) ///
> (eu36:(F6bar*(_b[g36]-(_b[b3]+2*_b[l3]/bofp*(lnexpbar-aofp))*w6bar-_b[b6]*_b[l3]*(lnexpbar-aofp)^2/bofp)/w3bar)) ///
> (eu37:(F7bar*(_b[g37]-(_b[b3]+2*_b[l3]/bofp*(lnexpbar-aofp))*w7bar-_b[b7]*_b[l3]*(lnexpbar-aofp)^2/bofp)/w3bar)) ///
> (eu41:(F1bar*(_b[g41]-(_b[b4]+2*_b[l4]/bofp*(lnexpbar-aofp))*w1bar-_b[b1]*_b[l4]*(lnexpbar-aofp)^2/bofp)/w4bar)) ///
> (eu42:(F2bar*(_b[g42]-(_b[b4]+2*_b[l4]/bofp*(lnexpbar-aofp))*w2bar-_b[b2]*_b[l4]*(lnexpbar-aofp)^2/bofp)/w4bar)) ///
> (eu43:(F3bar*(_b[g43]-(_b[b4]+2*_b[l4]/bofp*(lnexpbar-aofp))*w3bar-_b[b3]*_b[l4]*(lnexpbar-aofp)^2/bofp)/w4bar)) ///
> (eu45:(F5bar*(_b[g45]-(_b[b4]+2*_b[l4]/bofp*(lnexpbar-aofp))*w5bar-_b[b5]*_b[l4]*(lnexpbar-aofp)^2/bofp)/w4bar)) ///
> (eu46:(F6bar*(_b[g46]-(_b[b4]+2*_b[l4]/bofp*(lnexpbar-aofp))*w6bar-_b[b6]*_b[l4]*(lnexpbar-aofp)^2/bofp)/w4bar)) ///
> (eu47:(F7bar*(_b[g47]-(_b[b4]+2*_b[l4]/bofp*(lnexpbar-aofp))*w7bar-_b[b7]*_b[l4]*(lnexpbar-aofp)^2/bofp)/w4bar)) ///
> (eu51:(F1bar*(_b[g51]-(_b[b5]+2*_b[l5]/bofp*(lnexpbar-aofp))*w1bar-_b[b1]*_b[l5]*(lnexpbar-aofp)^2/bofp)/w5bar)) ///
> (eu52:(F2bar*(_b[g52]-(_b[b5]+2*_b[l5]/bofp*(lnexpbar-aofp))*w2bar-_b[b2]*_b[l5]*(lnexpbar-aofp)^2/bofp)/w5bar)) ///
> (eu53:(F3bar*(_b[g53]-(_b[b5]+2*_b[l5]/bofp*(lnexpbar-aofp))*w3bar-_b[b3]*_b[l5]*(lnexpbar-aofp)^2/bofp)/w5bar)) ///
> (eu54:(F4bar*(_b[g54]-(_b[b5]+2*_b[l5]/bofp*(lnexpbar-aofp))*w4bar-_b[b4]*_b[l5]*(lnexpbar-aofp)^2/bofp)/w5bar)) ///
> (eu56:(F6bar*(_b[g56]-(_b[b5]+2*_b[l5]/bofp*(lnexpbar-aofp))*w6bar-_b[b6]*_b[l5]*(lnexpbar-aofp)^2/bofp)/w5bar)) ///
> (eu57:(F7bar*(_b[g57]-(_b[b5]+2*_b[l5]/bofp*(lnexpbar-aofp))*w7bar-_b[b7]*_b[l5]*(lnexpbar-aofp)^2/bofp)/w5bar)) ///
> (eu61:(F1bar*(_b[g61]-(_b[b6]+2*_b[l6]/bofp*(lnexpbar-aofp))*w1bar-_b[b1]*_b[l6]*(lnexpbar-aofp)^2/bofp)/w6bar)) ///
> (eu62:(F2bar*(_b[g62]-(_b[b6]+2*_b[l6]/bofp*(lnexpbar-aofp))*w2bar-_b[b2]*_b[l6]*(lnexpbar-aofp)^2/bofp)/w6bar)) ///
> (eu63:(F3bar*(_b[g63]-(_b[b6]+2*_b[l6]/bofp*(lnexpbar-aofp))*w3bar-_b[b3]*_b[l6]*(lnexpbar-aofp)^2/bofp)/w6bar)) ///
> (eu64:(F4bar*(_b[g64]-(_b[b6]+2*_b[l6]/bofp*(lnexpbar-aofp))*w4bar-_b[b4]*_b[l6]*(lnexpbar-aofp)^2/bofp)/w6bar)) ///
> (eu65:(F5bar*(_b[g65]-(_b[b6]+2*_b[l6]/bofp*(lnexpbar-aofp))*w5bar-_b[b5]*_b[l6]*(lnexpbar-aofp)^2/bofp)/w6bar)) ///
> (eu67:(F7bar*(_b[g67]-(_b[b6]+2*_b[l6]/bofp*(lnexpbar-aofp))*w7bar-_b[b7]*_b[l6]*(lnexpbar-aofp)^2/bofp)/w6bar)) ///
> (eu71:(F1bar*(_b[g71]-(_b[b7]+2*_b[l7]/bofp*(lnexpbar-aofp))*w1bar-_b[b1]*_b[l7]*(lnexpbar-aofp)^2/bofp)/w7bar)) ///
> (eu72:(F2bar*(_b[g72]-(_b[b7]+2*_b[l7]/bofp*(lnexpbar-aofp))*w2bar-_b[b2]*_b[l7]*(lnexpbar-aofp)^2/bofp)/w7bar)) ///
> (eu73:(F3bar*(_b[g73]-(_b[b7]+2*_b[l7]/bofp*(lnexpbar-aofp))*w3bar-_b[b3]*_b[l7]*(lnexpbar-aofp)^2/bofp)/w7bar)) ///
> (eu74:(F4bar*(_b[g74]-(_b[b7]+2*_b[l7]/bofp*(lnexpbar-aofp))*w4bar-_b[b4]*_b[l7]*(lnexpbar-aofp)^2/bofp)/w7bar)) ///
> (eu75:(F5bar*(_b[g75]-(_b[b7]+2*_b[l7]/bofp*(lnexpbar-aofp))*w5bar-_b[b5]*_b[l7]*(lnexpbar-aofp)^2/bofp)/w7bar)) ///
> (eu76:(F6bar*(_b[g76]-(_b[b7]+2*_b[l7]/bofp*(lnexpbar-aofp))*w6bar-_b[b6]*_b[l7]*(lnexpbar-aofp)^2/bofp)/w7bar)), post iterate (10)
>
> nlcom (eu77: -(w7bar+_b[eu17]*w1bar+_b[eu27]*w2bar+_b[eu37]*w3bar+_b[eu47]*w4bar+_b[eu57]*w5bar+_b[eu67]*w6bar)/w7bar)
>
> Thank you!
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```