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 |
<franziska.goetze@agroscope.admin.ch> |

To |
<statalist@hsphsun2.harvard.edu> |

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

Date |
Wed, 4 Dec 2013 10:07:41 +0000 |

After a few tries now it finally worked. "did not work" means: Stata did not show any error code but did not generate w1 w2 w3 and w4. If I run: local product 1 2 3 4 and afterwards: foreach k in `product' { gen w`k' = x`k' /x14 replace w`k' = 0 if w`k'==. } it does not generate w1-w4; Only if I run the code altogether, w1-w4 are being generated. Does this mean I have to run a code that refers to an index, such as "k" here, always together with "local product 1 2 3 4"??? -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Nick Cox Gesendet: Mittwoch, 4. Dezember 2013 10:38 An: statalist@hsphsun2.harvard.edu Betreff: Re: st: Code-problem - calculating demand elasticities with a QUAIDS I can't see any problem with that code. I would rewrite local product 1 2 3 4 foreach k in `product' { gen w`k' = x`k' /x14 replace w`k' = 0 if w`k'==. } as forval k = 1/4 { gen w`k' = x`k' /x14 replace w`k' = 0 if w`k' == . } but that is just a matter of style. You have to tell us what "did not work" means. Nick njcoxstata@gmail.com On 4 December 2013 09:12, <franziska.goetze@agroscope.admin.ch> wrote: > Thanks for your help. The macro for "i" is indeed missing in my do-File, but I haven't figured out how to create such a macro. "i" should have values 1, 2, 3, 4 and so on. > I tried it like this: > > local product 1 2 3 4 > > and later wanted to refer to "product" (= i = k) > > foreach k in `product' { > > gen w`k' = x`k' /x14 > > replace w`k' = 0 if w`k'==. > > } > > Unfortunately it did not work. What did I do wrong? > * * 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**:**Re: st: Code-problem - calculating demand elasticities with a QUAIDS***From:*Nick Cox <njcoxstata@gmail.com>

**References**:**AW: st: Code-problem - calculating demand elasticities with a QUAIDS***From:*<franziska.goetze@agroscope.admin.ch>

**Re: st: Code-problem - calculating demand elasticities with a QUAIDS***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**st: Combining string and numeric variables** - Next by Date:
**Re: st: Code-problem - calculating demand elasticities with a QUAIDS** - 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):