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 on April 23, and its replacement, 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 <>
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("")

. di missing(" ")

. di missing("frog")

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.


On Tue, Sep 4, 2012 at 12:54 PM,  <> 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:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index