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: RE: Shortening variable names loop problem
From
George Murray <[email protected]>
To
[email protected]
Subject
Re: st: RE: Shortening variable names loop problem
Date
Thu, 19 Sep 2013 18:04:24 +1000
Perfect! Thank you!
On Thu, Sep 19, 2013 at 5:48 PM, Kieran McCaul <[email protected]> wrote:
> ...
>
>
> 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/
*
* 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/