Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Question using macro in loop


From   Tak-wai Chau <[email protected]>
To   [email protected]
Subject   Re: st: Question using macro in loop
Date   Fri, 06 Apr 2007 18:32:33 -0400

Thanks! I think it works.

Actually I wonder if there is any direct reference method because I have to run it inside another loop. It seems a little stupid to loop these over and over again.

Thanks a lot!

Friedrich Huebler wrote:

Tak Wai,

You stated your problem clearly and here is the solution.

forvalues i = 1/10 {
  replace v`i' = y if w==`i'
}

Friedrich

--- Tak-wai Chau <[email protected]> wrote:
First forget about the specific example I used before.

Now we have variables V1, V2,..., V10.
We have another variable W contains integer values between 1 and 10
inclusively.
We also have another variable Y contain numerical values.
I want to set Vi=Y if W==i for that observation and let other Vs unchanged for that observations.

So what can I do in this case?

Hope this is clearer now.

Thanks a lot!

Friedrich Huebler wrote:

--- Tak-wai Chau <[email protected]> wrote:
The key question I have in mind is whether we can, within a
loop,
update one of the variables, and which variable to update is
according to the value taking by another variable. This value is
different across observations.
Yes, you can do that but your explanation is too vague. It is
difficult to help if you don't provide a clear rule for how
values
should be replaced.

Friedrich







____________________________________________________________________________________
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
http://answers.yahoo.com/dir/?link=list&sid=396546091
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index