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: -destring- and missing values
From
Joe Canner <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: -destring- and missing values
Date
Wed, 2 Oct 2013 19:28:43 +0000
-sieve()- doesn't require knowing what the non-visible characters are, but you are right that with -charlist-, -destring , ignore()- is not so onerous and probably useful for avoiding gunk in the future.
________________________________________
From: [email protected] [[email protected]] on behalf of Nick Cox [[email protected]]
Sent: Wednesday, October 02, 2013 3:05 PM
To: [email protected]
Subject: Re: st: -destring- and missing values
Could be, but -destring, ignore()- is directly to the point.
Either way, you have to know what gunk you have to filter out, on
which I once more mention -charlist- (SSC).
(-egenmore- is also from SSC.)
Nick
[email protected]
On 2 October 2013 20:03, Joe Canner <[email protected]> wrote:
> Would the -egen sieve()- function from the -egenmore- package be of use here to create a variable that just has numbers that could then be destrung?
> ________________________________________
> From: [email protected] [[email protected]] on behalf of Nick Cox [[email protected]]
> Sent: Wednesday, October 02, 2013 2:55 PM
> To: [email protected]
> Subject: Re: st: -destring- and missing values
>
> As the original author of -destring-, I retain some prejudices about
> its use. The -force- option was added for the desperate and brutal
> when so inclined. What's perhaps even more crucial is that it isn't
> smart.
>
> . set obs 1
> obs was 0, now 1
>
> . gen foo = "1" + char(160)
>
> . destring foo, replace
> foo contains nonnumeric characters; no replace
>
> . destring foo, replace force
> foo contains nonnumeric characters; replaced as byte
> (1 missing value generated)
>
> Thus with stray char(160) Stata just goes ahead and doesn't do what
> you might want, ignore all non-numeric characters. It doesn't know any
> more what to do than without -force-.
>
> Nick
> [email protected]
>
>
> On 2 October 2013 19:46, Jeph Herrin <[email protected]> wrote:
>> Thanks. I my case, I have a few variables that are not numeric; I don't want
>> those converted to real. Nor do I want to sort out in advance which are
>> which - I want to -destring- exactly those variables with only numerical
>> values stored as strings.
>>
>>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of Steve Nakoneshny
>> Sent: Wednesday, October 02, 2013 12:13 PM
>> To: [email protected]
>> Subject: Re: st: -destring- and missing values
>>
>> Jeph,
>>
>> Can you not take advantage of the -force- option of -destring- here?
>>
>> Steve
>>
>> On 2013-10-02, at 10:07 AM, Jeph Herrin wrote:
>>
>>> All,
>>>
>>> I have hundreds of variables that look like this:
>>>
>>> . d q1
>>>
>>> storage display value
>>> variable name type format label variable label
>>> -------------------------------------------------------------
>>> q1 str2 %2s
>>>
>>> . tab q1, m
>>>
>>> q1 | Freq. Percent Cum.
>>> ------------+-----------------------------------
>>> | 2 0.89 0.89
>>> 1 | 216 96.00 96.89
>>> 2 | 7 3.11 100.00
>>> ------------+-----------------------------------
>>> Total | 225 100.00
>>>
>>> but when I try to use -destring-
>>>
>>> . destring q1, replace
>>> q1 contains nonnumeric characters; no replace
>>>
>>> According to the documentation,
>>>
>>> destring treats both empty strings "" and "." as indicating sysmiss
>>> (.)...
>>> destring also ignores any leading or trailing spaces so that, for
>>> example,
>>> " " is equivalent to "" and " . " is equivalent to ".".
>>>
>>> Why is -destring- not converting my variables to numeric? I think I
>>> must be missing something very obvious.
>>>
>>> I can get around this by
>>>
>>> replace q1 = "." if mi(q1)
>>>
>>> but I don't think I should have to.
> *
> * 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/