Bookmark and Share

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: Re: loop in variables labels


From   Robert Picard <[email protected]>
To   [email protected]
Subject   Re: st: Re: loop in variables labels
Date   Mon, 15 Jul 2013 09:29:41 -0400

I think that, as Joseph said, -rename- can do this without a loop. It
doesn't help that you are changing your description of how variables
are named. "_3_DAYS_X_X" does not follow a
"_anynumberanyword_anyword_anyword" pattern. Try the following:

* -------------- begin example ----------------------------
clear
gen _3_DAYS_X1_X2 = 1
gen _6_DAYS_Xx_Xy = 2
gen _19_DAYS_XY_XZ = 3
gen _3_WEEKS_12_23 = 4
gen _6_WEEKS_34_56 = 5
gen _A_WEEKS_34_56 = 5

rename _#_*_*_* *[2]_#[1]

clear
gen _3DAYS_X1_X2 = 1
gen _6DAYS_Xx_Xy = 2
gen _19DAYS_XY_XZ = 3
gen _3WEEKS_12_23 = 4
gen _6WEEKS_34_56 = 5
gen _AWEEKS_34_56 = 5

rename _#*_*_* *[2]_#[1]
* -------------- end example ------------------------------


On Mon, Jul 15, 2013 at 8:36 AM, Haluk Vahaboglu <[email protected]> wrote:
> Thank you Joseph,
> "rename group" do not solve my problem.
> Same as I replied to Matt. There are various words and numbers in my var names. It is like _anynumberanyword_anyword_anyword. I want it to be changed to anyword(first one)_anynumber(firstone).
>
>
> Thank you Matt,
> Sure it works but unfortunately my variable names are not in a discipline as given in the example.
> In my variable names there are leading "_" s followed by a "number" and "word" "_" "word"....
> Here I want to take the first "number" and put it after the first "word" to get a sequence of "word""_""number" and do this by means of a loop. Do whatever my number or word is.
> Thanks again. Have to wait some more help..
>
>
>
> 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
>
>
>
>
> ----------------------------------------
>> From: [email protected]
>> To: [email protected]
>> Subject: st: Re: loop in variables labels
>> Date: Mon, 15 Jul 2013 21:19:26 +0900
>>
>> Haluk Vahaboglu wrote:
>>
>> 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
>>
>> --------------------------------------------------------------------------------
>>
>> If you're using Stata Release 12 or 13, then you can accomplish what you want in
>> a single line of code.
>>
>> Type
>>
>> help rename group
>>
>> at the Stata command line for more information.
>>
>> Joseph Coveney

*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index