Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Mirnezami, Oliver" <O.Y.Mirnezami@warwick.ac.uk> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: forval query |
Date | Fri, 5 Apr 2013 14:13:17 +0000 |
Thank you to Maarten and Billy for your quick and helpful replies. I wondered is it possible to alter the syntax so that this can be done in an automated way for many variables? I can repeat your set of commands for each variable e.g. forvalues i = 2/10 { local j = 1990 + (2*`i') rename r`i'mobila mobila_`j' ma drop j } forvalues i = 2/10 { local j = 1990 + (2*`i') rename r`i'lgmusa lgmusa_`j' ma drop j } Etc. However, I have do this for many variables so can you plug in a line with a list of these variables to avoid repeating the command over and over again? Thank you Kind regards Oliver -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Maarten Buis Sent: 05 April 2013 14:40 To: statalist@hsphsun2.harvard.edu Subject: Re: st: forval query On Fri, Apr 5, 2013 at 3:32 PM, Mirnezami, Oliver wrote: > Previously i've been renaming variables manually en masse using the following code: > > rename r2mobila mobila_1994 > rename r3mobila mobila_1996 > rename r4mobila mobila_1998 > .etc.. > rename r10mobila mobila_2010 > > i.e. '2' corresponds with '1994', '3' with '1996' etc. forvalues i = 2/10 { local y = 2*`i' +1990 rename r`i'mobila mobila_`y' } --------------------------------- Maarten L. Buis WZB Reichpietschufer 50 10785 Berlin Germany http://www.maartenbuis.nl --------------------------------- * * 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/