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: "Replace all" for a dataset

From   Phil Schumm <>
Subject   Re: st: "Replace all" for a dataset
Date   Wed, 28 Dec 2011 15:55:22 -0600

On Dec 28, 2011, at 3:14 PM, Jessica Kopsic wrote:
> (The variables are all string which I can't change until I change "missing" to missing values.  Aside from "missing" and "not available" the variables are numbers.)
> Or perhaps there is a third, easier way.

If you don't care about preserving the distinction between "missing" and "not available", then

    destring variable1-variable200, ignore("missingnotavailable") replace

is quickest.  Alternatively, if you want to preserve the distinction, try:

    ds variable1-variable200, has(type string)
    foreach var of varlist `r(varlist)' {
        replace `var' = ".a" if strpos(`var',"missing")
        replace `var' = ".b" if strpos(`var',"not available")
        destring `var', replace

-- Phil

*   For searches and help try:

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