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: Batch renaming variables


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: Batch renaming variables
Date   Thu, 18 Oct 2012 16:28:27 +0200

On Thu, Oct 18, 2012 at 4:03 PM, Wameq Raza wrote:
> The variables I have start from v0915 and continue to v1005 and I need
> to rename every 5th variable in this list starting from v0917. The
> variables to be renamed to are: cost_a, cost_b....cost_n.

*--------------------------- begin example --------------------------
// create some example data
clear
set obs 10
forvalues i = 915/1005 {
	gen v`:display %04.0f `i'' = runiform()
}
	
// start renaming
local j = 0
forvalues i = 917(5)1005 {
	local j = `j' + 1
	mata: st_local("letter", strlower(numtobase26(strtoreal(st_local("j")))))
	rename v`:display %04.0f `i'' cost_`letter'
}
*---------------------------- end example ---------------------------

Hope this helps,
Maarten

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


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