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]
st: RE: Shortening variable names loop problem
From
Kieran McCaul <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: RE: Shortening variable names loop problem
Date
Thu, 19 Sep 2013 15:48:41 +0800
...
Try:
foreach var of varlist * {
local newvar = substr("`var'", 1, 30)
rename `var' `newvar'
}
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of George Murray
Sent: Thursday, 19 September 2013 3:40 PM
To: [email protected]
Subject: st: Shortening variable names loop problem
Dear Statalist,
I am trying to shorten all variables with 31 or 32 characters to 30 by
removing the last 1 or 2 characters. Does any one know why the
following command does not work (type mismatch):
foreach var of varlist * {
replace `var' = "substr("`var'",1,30)"'
}
Replacing the second line with -rename `var' "substr("`var'",1,30)"-
also doesn't work (parenthesis unbalanced).
Does anyone have a solution?
Thanks.
*
* 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/