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

st: re: extracting variable names for use as string lists


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: extracting variable names for use as string lists
Date   Thu, 14 Jul 2005 11:06:06 -0400

David said

I would like to rename multiple variables in a consistent way -- that is, to
abbreviate their names to 8 characters if they are any longer than this
(using 'abbrev'). I would like to use a structure something like:

foreach x in [list of variable names] {
if length(`x')>8 {
rename `x' abbrev(`x',8)
}
}



First of all you should use capture on the rename line to deal with the fact that some of these names may be invalid, in that you have mapped variable1 and variable2 into variable (or are trying to do so).

ds v*
local vvars `r(varlist)'
foreach v of local vvars {
...
}

will pick up the variables whose names start with v.

You may want to look at renvars (findit renvars) which will probably deal with the namespace collision problem.

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html

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