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

st: RE: truncating variable names


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: truncating variable names
Date   Thu, 5 Feb 2004 12:58:24 -0000

Truncating is easy: use -substr(varname,1,8)-. 

The problem often is that the 
first eight characters are not unique e.g. common 
naming practices often yield "argentinaimports66" 
"argentinaimports67" etc. 

I'd try something like this: 

1. use -abbrev(,)- to get an abbreviation. 
2. replace the "~" with "_". 
3. replace the "." with "_". 
4. check to see that there are no duplicates
in that list. Here no news is good news. 

There's no guarantee, so far as I know, that 
this will work. 

foreach v of var * { 
	local new = subinstr(abbrev("`v'", 8),"~","_",.) 
	local new = subinstr("`new'",".","_",.) 
	local newlist "`newlist'`new' " 
} 

di "`: list dups newlist'" 

For systematic renaming, one possibility is -renvars-
from STB-60. 

If all else fails, use something like 

d, s 
renvars \ v1-v`r(k)' 

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of atobias
> Sent: 05 February 2004 12:34
> To: [email protected]
> Subject: st: truncating variable names
> 
> 
> Dear Statalisters,
> 
> There is any way to truncate automatically a long variable name, like 
> those used in Stata 8, into the classical shorter way of only 8 
> characters?.
> 
> Cheers,
> 
> 
> 
> 
> *
> *   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/

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