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]
Re: st: loop in variables labels
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: loop in variables labels
Date
Mon, 15 Jul 2013 22:31:28 +0100
This thread has already proved confusing given that the problem
description changed from this initial statement. That has led to some
very complicated code being suggested.
In addition, Haluk is not acting as recommended:
1. This thread was started by replying to a different thread, so
threading in the archives is messed up. As the FAQ indicates, you
should start a new thread with a new posting.
2. The heading here refers to variable labels, but the problem appears
to be about variable names.
3. The implication is that searching started with the FAQs or the
internet. Searching should generally start with -help- and the
manuals.
The irregularity in variable names implies that such irregularity
might be better ignored altogether. It appears that they keywords such
as "DAYS" and the numbers such as "3" are the only crucial elements.
That leads to this code sketch:
foreach v of var * {
local V : subinstr local v "_" " ", all
tokenize `V'
rename `v' `2'_`1'
}
If all underscores are replaced with blanks, what is left can be
parsed into tokens. The wanted names appear to be the second token, an
underscore and the first token.
Nick
[email protected]
On 15 July 2013 12:35, Haluk Vahaboglu <[email protected]> wrote:
> Dear listers,
>
> I have some a *.dta file that is imported from an *.xls with some 30 variables named as _3_DAYS_X_X; _6_DAYS_X_X; _9_DAYS_X_X;_3_WEEKS_X_X; _6_WEEKS_X_X; _9_WEEKS_X_X and so on.
> I want to rename all these var names using a foreach loop to DAYS_3; DAYS_6...;WEEKS_3... and so on.
> I could not find a help in FAQ or internet search.
> I would appreciate any help
>
> Regards
>
> Prof. Dr. Haluk Vahaboğlu
> Istanbul Medeniyet
> Üniversitesi,
> Göztepe Eğitim ve Araştırma Hastanesi
> Enfeksiyon Hastalıkları
> ve Klinik Mikrobiyoloji ABD
> Dr. Erkin Caddesi 34730
> Kadıköy / Istanbul TURKIYE
>
> *
> * 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/
*
* 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/