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]

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/

**Follow-Ups**:**Re: st: replacing task in a loop***From:*Phil Clayton <philclayton@internode.on.net>

- Prev by Date:
**Re: st: margeff and margins puzzle** - Next by Date:
**Fw: st: ROC question: STATA vs SPSS** - Previous by thread:
**st: Question on loop over variable** - Next by thread:
**Re: st: replacing task in a loop** - Index(es):