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:19:08 +0000

Thank you Matt,
Sure it works but unfortunately my variable numbers 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]
> Date: Mon, 15 Jul 2013 13:01:43 +0100
> Subject: st: RE: loop in variables labels
> 
> Hello Haluk,
> 
> I would try:
> 
> foreach number in 3 6 9 {
>     rename _`number'_DAYS_X_X DAYS_`number'
> }
> foreach number in 3 6 9 and so on {
>     rename _`number'_WEEKS_X_X WEEKS_`number'
> }
> 
> You could do this in one nested loop, but that will become complicated if you have more WEEKS variables than DAYS variables. There might be a way to do this in one line using -renvars- (SSC), but even though I do this kind of rename frequently I think it's easier to write a quick loop than figure out the correct syntax.
> 
> Hope that helps,
> Matt
> 
> 
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Haluk Vahaboglu
> Sent: 15 July 2013 12:35
> To: [email protected]
> Subject: st: loop in variables labels
> 
> 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/
> 
> ********************************************************************************************************************
> 
> This message may contain confidential information. If you are not the intended recipient please inform the
> sender that you have received the message in error before deleting it.
> Please do not disclose, copy or distribute information in this e-mail or take any action in reliance on its contents:
> to do so is strictly prohibited and may be unlawful.
> 
> Thank you for your co-operation.
> 
> NHSmail is the secure email and directory service available for all NHS staff in England and Scotland
> NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and GSi recipients
> NHSmail provides an email address for your career in the NHS and can be accessed anywhere
> 
> ********************************************************************************************************************
> 
> *
> *   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