Statalist The Stata Listserver


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

st: Question using macro in loop


From   Tak-wai Chau <[email protected]>
To   [email protected]
Subject   st: Question using macro in loop
Date   Thu, 05 Apr 2007 20:35:21 -0400

Hi,

I would like to ask something about using macro in loops. I have tried to find it in the archive and FAQ for some time but I don't get it. Sorry if I have overlooked some obvious things.

I would like to update certain variables according to the value taking by a particular variable, and this value differs by observations. Then what I should do?

For example, if I want to transfer value of non-missing variables from V1-V10 to W1-W10. But I don't want to variables carrying missing value between. I use s to count the number of non-missing values I have covered at that point.

The following is what I think of but doesn't work.

s=1
forvalues i=1/10 {
local s1=s
replace w`s1'=v`i' if v`i'<.
replace s=s+1 if v`i'<.
}

I know the problem is at the local statement.

What should I do?

Thank you very much!

Tak Wai Chau
*
* 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