Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: replacing task in a loop


From   Daniel Marcelino <dmsilv@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: replacing task in a loop
Date   Thu, 28 Jul 2011 21:42:22 -0400

Dear all,
I have a doubt on the looping process that might be simple to solve. I
have a sort of variables with the same scales 1 to 9 that I want to
recode their values to a different scale. However, when I do a loop
for replace these values I got some confusing values in particular for
 the value  1. To deal with this problem I using a not pretty
solution: I'm running  2 loops over the variables as follow.

foreach v of varlist q* pq* {
replace `v' = 0 if `v' ==1
replace `v' = 0.25 if `v' ==2
replace `v' = 0.50 if `v' ==9
replace `v' = 0.75 if `v' ==3
replace `v' = 0.9 if `v' == 4
  }

/* I'm loop again because I cannot transform 4==1 in the same previous
loop. Therefore, I replaced 4==0.9 and now 0.9 == 1


foreach v of varlist q35a* pq26a* {
replace `v' = 1 if `v' ==0.9
   }

My doubt is: there is a way to replace all values without the risk of
the new value be considered again in the loop?


Daniel

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index