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   Haluk Vahaboglu <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: Re: loop in variables labels
Date   Mon, 15 Jul 2013 12:36:43 +0000

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
>
> . set obs 1
> obs was 0, now 1
>
> .
> . foreach var of newlist _3_DAYS_X_X _6_DAYS_X_X _9_DAYS_X_X ///
>> _3_WEEKS_X_X _6_WEEKS_X_X _9_WEEKS_X_X {
> 2. generate float `var' = 0
> 3. }
>
> . list, noobs abbreviate(20)
>
>
> +-------------------------------------------------------------------------------
> -------+
> | _3_DAYS_X_X _6_DAYS_X_X _9_DAYS_X_X _3_WEEKS_X_X _6_WEEKS_X_X
> _9_WEEKS_X_X |
>
> |-------------------------------------------------------------------------------
> -------|
> | 0 0 0 0 0
> 0 |
>
> +-------------------------------------------------------------------------------
> -------+
>
> .
> .
> . *
> . * Begin here
> . *
> . rename (_*_DAYS* _*_WEEKS*) (DAYS_* WEEKS_*)
>
> .
> . list, noobs abbreviate(20)
>
> +--------------------------------------------------------+
> | DAYS_3 DAYS_6 DAYS_9 WEEKS_3 WEEKS_6 WEEKS_9 |
> |--------------------------------------------------------|
> | 0 0 0 0 0 0 |
> +--------------------------------------------------------+
>
> .
> . exit
>
> end of do-file
>
> *
> * 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/


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