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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
<[email protected]> |

To |
<[email protected]> |

Subject |
AW: st: Code-problem - calculating demand elasticities with a QUAIDS |

Date |
Fri, 22 Nov 2013 13:45:47 +0000 |

```
I defined the "w"'s (in the same do-file) like this (at the beginning of my do-file):
gen w1 =x1 /x1_4 (x = expenditure)
gen w2 =x2 /x1_4
gen w3 =x3 /x1_4
gen w4 =x4 /x1_4
(x1 to x4 are included in the original dataset, and x1_4 is generated: gen x1_4 = x1 + x2 + x3 + x4)
and then the w's are mentioned again here:
program nlsuraids
version 12
syntax varlist(min=8 max=8) [if], at(name)
tokenize `varlist'
args w1 w2 w3 lnp1 lnp2 lnp3 lnp4 lnx1_4
(followed by "tempname"s and "scalar"s)
Maybe it is not suitable to use "gen"?
How would a macro for w`i'mean look like?
global w`i'mean "x`i' / x1_4" ?
global w`i'mean "mean(w`i')" ?
Thanks a lot!
Franziska
-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Nick Cox
Gesendet: Freitag, 22. November 2013 14:06
An: [email protected]
Betreff: Re: st: Code-problem - calculating demand elasticities with a QUAIDS
I like the word "Doktorandin".
Stata's reference to
wmean
implies that the local macro i is undefined in the locale in which you are working. From a glance at your code this is puzzling. Are you defining all the code in the same locale, where locale means the same interactive session OR program OR do-file OR do-file editor contents?
Note that "locale" is here my term borrowed from another language, and not one that you will find in the Stata documentation.
I suggest it as a useful word: the locale of a local macro is the space within which it is visible.
You can confirm what macros are visible at any point by peppering your code with
macro list
statements.
Nick
[email protected]
On 22 November 2013 12:25, <[email protected]> wrote:
> Dear Statalist-Users
>
> I am trying to calculate budget and price elasticities for four meat products with a QUAIDS-model (using Swiss household data) (according to the method of Banks 1997 "Quadratic Engel Curves and Consumer Demand") and I have a problem with my code.
>
> This is (part of) the code I am using:
>
> quietly {
> foreach x of varlist w* lnp* lnx1_4 {
> sum `x'
> scalar `x'mean=r(mean)
> }
>
> * Price indexes
> global asum "_b[a1] * lnp1mean"
> forv i=2(1)4 {
> global asum "${asum} + _b[a`i'] * lnp`i'mean"
> }
> global gsum ""
> forv i=1(1)4 {
> forv j=1(1)4 {
> global gsum "${gsum} + 0.5 * _b[g`i'_`j'] * lnp`i'mean * lnp`j'mean"
> }
> }
> global lnaofp "5 + ${asum} ${gsum}" /* price index: ln a(p)*/
>
> global bofp "lnp1mean*_b[b1]"
> forv i=2(1)4 {
> global bofp "${bofp} + lnp`i'mean*_b[b`i']"
> }
> global bofp "(exp(${bofp}))" /* Cobb-Douglas price aggregator b(p) */
>
> * My's (i: delta budget share/delta ln-expenditure and ij: delta
> budget sh./delta ln-price) forv i=1(1)4 { global my`i' "_b[b`i'] +
> ((2*_b[l`i'])/${bofp})*(lnx1_4mean - (${lnaofp}))"
> }
> forv j=1(1)4 {
> global gsum2`j' ""
> forv k=1(1)4 {
> global gsum2`j' "${gsum2`j'} + _b[g`j'_`k'] * lnp`k'mean"
> }
> }
>
> forv i=1(1)4 {
> forv j=1(1)4 {
> global delta=cond(`i'==`j',1,0) /* Kronecker delta */ global my`i'_`j'
> "_b[g`i'_`j'] - ${my`i'}*(_b[a`j']${gsum2`j'}) - ((_b[l`i']*_b[b`j'])/${bofp})*((lnx1_4mean - ${lnaofp})^2)"
> *}
> *}
>
> capture nlcom (elx`i': ${my`i'}/ w`i'mean + 1) (my`i'_`j':
> ${my`i'_`j'}), post noheader if _rc { qui nlcom (elx`i': ${my`i'} /
> w`i'mean + 1) (my`i'_`j'f: (1e+2)*(${my`i'_`j'})), post noheader qui
> nlcom (elx`i': _b[elx`i']) (my`i'_`j': _b[my`i'_`j'f]/(1e+2)), post
> noheader } } }
>
> * Uncompensated price elasticity
> nlcom (elx`i': _b[elx`i']) (elu`i'_`j': _b[my`i'_`j']/ w`i'mean - ${delta}), post noheader
> * Compensated price elasticity
> nlcom (elc`i'_`j': _b[elu`i'_`j'] + _b[elx`i']* w`j'mean), noheader
> qui est restore quaidsc
>
> }
> end
>
> The problem seems to be in the "capture nlcom (elx`i': ${my`i'}/ w`i'mean + 1) ."-line (not sure), because Stata gives me the result:
>
> . do ""
>
> . nlcom (elx`i': ${my`i'}/ w`i'mean + 1) (my`i'_`j': ${my`i'_`j'}),
> post noheader /wmean invalid name r(198);
>
> end of do-file
>
> r(198);
>
> I don't know, why it does not use the means of w1 to w4 (w1mean to w4mean) (w=budget share).
>
> It would be also interesting for me to know if there is another possibility to write the code for the calculation of "elx`i'".
>
> Thanks a lot,
> Franziska
>
>
> Franziska Götze, M. Sc.
> Doktorandin
>
> Eidgenössisches Departement für
> Wirtschaft, Bildung und Forschung WBF
> Forschungsanstalt Agroscope Reckenholz-Tänikon ART Sozioökonomie
>
> Tänikon, CH-8356 Ettenhausen
> Tel. +41 52 36 83225
> Fax +41 52 36 51190
> [email protected]
> www.agroscope.ch
>
>
> *
> * 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/
*
* 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/
```

**Follow-Ups**:

**References**:

- Prev by Date:
**Re: st: RE: Fitting distributions to right-sensored survival data** - Next by Date:
**st: Estimating Logit Price Response Function With Unknown Market Size** - Previous by thread:
**Re: st: Code-problem - calculating demand elasticities with a QUAIDS** - Next by thread:
**Re: st: Code-problem - calculating demand elasticities with a QUAIDS** - Index(es):