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]
st: forvalues foreach or while loop for sequential variables
From
Robbie Katz <[email protected]>
To
[email protected]
Subject
st: forvalues foreach or while loop for sequential variables
Date
Thu, 31 Oct 2013 01:11:11 -0400
I have a wide format data with variables with same text and different
numbers attached to them. The variables look like this: hospital1
hospital2 hospital3...hospital15. I want only unique values across
these variable for any one observation. For instance if both hospital
15 and hospital14 have the same value say, 10, then I want to delete
10 and replace it with "." for hospital15. Please let me know how I
can run a loop to achieve this.
I tried the following but it didn't work:
forvalues num=2/15 {
replace hospital`num'=. if hospital`num'==hospital``num'-1'
}
Please help,
Thanks!
*
* 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/