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]

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


From   <[email protected]>
To   <[email protected]>
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: [email protected] [mailto:[email protected]] Im Auftrag von Nick Cox
Gesendet: Mittwoch, 4. Dezember 2013 10:38
An: [email protected]
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
[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/

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