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: variable name with special character


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: variable name with special character
Date   Mon, 10 Feb 2014 16:08:51 -0500

It does the job, so I never thought to look elsewhere. But now I will.


On 2/10/2014 3:58 PM, Nick Cox wrote:
-renvars- is from SJ. Interesting that there is still life in the old
horse, even with the spectacular extension of -rename- in Stata 12.


Nick
[email protected]


On 10 February 2014 20:52, Jeph Herrin <[email protected]> wrote:
Thanks, that did the trick. It was char(160), of course, so

. renvars _all, substr("`=char(160)'" "")

did the trick. Interestingly, Stata even allowed things like:

. d q_71a*


               storage   display    value
variable name   type    format     label      variable label
--------------------------------------------------------------
q_71a           byte    %10.0g
q_71a           str63   %63s


cheers,
Jeph



On 2/10/2014 3:39 PM, Nick Cox wrote:

If you can get Stata to tell you what the character(s) is/are, you are
home and dry.

So, something like

foreach v of var * {
mata : st_local("chars", invtokens(strofreal(ascii("`v'"))))
di "`v'" "{col 20}" "`chars'"
}

This is how it works for auto.dta

make               109 97 107 101
price              112 114 105 99 101
mpg                109 112 103
rep78              114 101 112 55 56
headroom           104 101 97 100 114 111 111 109
trunk              116 114 117 110 107
weight             119 101 105 103 104 116
length             108 101 110 103 116 104
turn               116 117 114 110
displacement       100 105 115 112 108 97 99 101 109 101 110 116
gear_ratio         103 101 97 114 95 114 97 116 105 111
foreign            102 111 114 101 105 103 110

In your case, feeding A3* rather than * should be sufficient, and
you'll want to look for high values at the end of each string.

Nick
[email protected]


On 10 February 2014 20:22, Jeph Herrin <[email protected]> wrote:


All,

I used Stat/Transfer v12 to create a Stata dataset from an Excel file.
When
I open the file in Stata, I find that many of the variable names have
special characters (apparently), because Stata can't see them. Example:


   . d A3*

                 storage   display    value
   variable name   type    format     label      variable label
   ------------------------------------------------------------
   A3              str2    %2s
   A3a             str2    %2s
   A3b             str2    %2s
   A3c_1           str2    %2s
   A3c_2           str2    %2s
   A3c_3           str2    %2s
   A3c_4           str2    %2s
   A3c_5           str2    %2s
   A3c_6           str2    %2s
   A3c_7           str2    %2s


   . d A3
   A3 ambiguous abbreviation
   r(111);

So there seems to be a non-printing character trailing -A3-; I have
dozens
of these in the dataset. In the original excel file, all seems to be in
order. There are trailing blanks in the top row; however,

   . renvars _all, postsub(" " "")
   no renames necessary

Any thoughts on how I can identify and repair the problem with these
variable names?

thanks,
Jeph



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


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