Bookmark and Share

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]

Re: st: Code-problem - calculating demand elasticities with a QUAIDS


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Code-problem - calculating demand elasticities with a QUAIDS
Date   Wed, 4 Dec 2013 09:38:13 +0000

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
[email protected]


On 4 December 2013 09:12,  <[email protected]> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index