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]

st: "Replace all" for a dataset

From   "Jessica Kopsic" <>
Subject   st: "Replace all" for a dataset
Date   Wed, 28 Dec 2011 16:14:20 -0500

Hello list members,

I'm trying to do the equivalent of Excel's replace all in a Stata dataset,
changing the words "missing" and "not available" to a missing value for
all variables in the entire dataset. This works fine for one variable:
replace variable1 = "." if variable1 =="missing"
replace variable1 = "." if variable1 =="not available"

But I need to do the whole dataset. I tried using * in the above commands
but it did not work. (returned the message: * invalid name)

I also tried to write two loops, but got a type mismatch error:  foreach
var of varlist variable1-variable200 {
replace `var' = "." if `var' = "missing"
(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.

Thank you!

*   For searches and help try:

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