Bookmark and Share

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: Renaming variable to its label which includes spaces or colons or semi colons


From   Duha Altindag <[email protected]>
To   [email protected]
Subject   Re: st: RE: Renaming variable to its label which includes spaces or colons or semi colons
Date   Thu, 22 Apr 2010 20:23:09 -0500

Thank you

On Thu, Apr 22, 2010 at 5:28 PM, Martin Weiss <[email protected]> wrote:
>
> <>
>
> -strtoname- needs quotation marks around its argument:
>
> *******
>
> clear*
> set obs 1
> gen var1=1
> la var var1 "3 This is the most dubious label"
> gen var2=2
> la var var2 "2even:more dubious"
>
> foreach v of varlist _all{
>   local x : variable label `v'
>   local q_`v'  =strtoname("`x'")
>   ren `v' `q_`v''
>   label variable `q_`v'' "`v'"
> }
>
> desc
> *******
>
>
> HTH
> Martin
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Duha Altindag
> Sent: Freitag, 23. April 2010 00:02
> To: [email protected]
> Subject: st: Renaming variable to its label which includes spaces or colons
> or semi colons
>
> Hi,
>
> I want to rename a variable name to its label. A related topic was
> discussed before and solution was provided conditional on the labels
> are in "proper form" and unique.
> My labels are not in proper form but unique. Specifically they start
> with a number and they include improper characters such as ":".
> There is actually a string function called -strtoname- that transforms
> improper strings into proper ones. However I cannot get use that
> command while defining a -local-
> My code looks like the following:
>
> foreach v of varlist `VARIABLES' {
>   local x : variable label `v'
>   local q_`v'  strtoname(`x')
>   ren `v' `q_`v''
>   label variable `q_`v'' "`v'"
> }
>
>
> And this is the message I receive:
>
> ( not allowed
> r(101);
>
> If I can define my macro q_`v' above such that it denotes the proper
> name obtained from -strtoname- I guess I will be fine.
> Any ideas?
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/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/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index