Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: replacing zero length strings with missing values


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: replacing zero length strings with missing values
Date   Tue, 4 Sep 2012 13:15:06 +0100

You tried to replace empty strings with numeric missing . --  but, as
you report here, that is a type mismatch.

There is nothing to do here: empty strings and missing strings are one
and the same in Stata. Consider

. di missing("")
1

. di missing(" ")
0

. di missing("frog")
0

A string value is missing if and only if it is empty. (That is, the
function -missing()- returns 1 for true if and only with string
arguments if and only if that string argument is empty.)

It is possible to replace "" with "." if you wish to show empty
strings explicitly, but that's all in the eye of the beholder: Stata
does not regard "." as denoting string missing: it's just a stop or
period character.

Nick

On Tue, Sep 4, 2012 at 12:54 PM,  <Robert.Shaw@dh.gsi.gov.uk> wrote:

> I have a large dataset in stata and one of the variables has a lot a
> observations that should be missing values but are instead zero length
> strings (ie. =="")
>
> I've tried
>
> foreach x of varlist myvariable {
> replace `x' = . if(`x' =="")
> }
>
> but this gives a type mismatch.
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index