Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: substring of a variable name


From   Martin Rio <[email protected]>
To   [email protected]
Subject   st: substring of a variable name
Date   Thu, 30 Jun 2005 16:53:07 -0500

I have a dataset with several variables named:
datax1 datax2 datay1 datapt datafj

and I'd like to remove the 4 first characters of each to get variables
with names:
x1 x2 y1 pt fj

I tried:

foreach var of varlist data* {
 	local newname substr(`var', 4, length(`var')-2)
 	rename `var' `newname'
}

It seems that the standard string functions may not apply to macros. Any
ideas on how to do this? Are there string functions specific to macros? I
was looking at the documentation for macro extended functions but did not
find something that would seem to do it.

thanks in advance,
martin

-- 
Linux is user friendly. It's just very particular about who it's friends are.
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index