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 missing values only works one way?

From   Joseph McDonnell <>
Subject   Re: st: Replacing missing values only works one way?
Date   Wed, 28 Jul 2010 14:15:44 +0930


As Eric says, the commands do work. It's just your expectation doesn't
match what you get. Eric has probably identified the "problem", namely
a missing followed by one or more missings. Suppose rows 1 and 2 are
missing in myvar but row 3 isn't. The replace command tells Stata to
replace the value in row 1 with the value in row 2. But that's missing
as well, so row 1 doesn't change. Row 2 will be assigned row 3's value
and you'll need to do another replace to backwards propogate the value
to row 1.

You could use "assert" to check for missingness and loop until all
missings are filled..

. capture assert myvar<.
. while _rc {
. replace myvar=myvar[_n+1] if myvar>=.
. capture assert myvar<.
. }



On Wed, Jul 28, 2010 at 6:43 AM, Dana Chandler <> wrote:
> The command described here works fine when I go one way: replace myvar
> = myvar[_n-1] if myvar >= .
> However, when I try to replace in the other direction replace myvar =
> myvar[_n+1] if myvar >= ., it doesn't work and I have to repeat the
> command for each time I want it to copy... Does anyone have any
> suggestions?
> I've read the below, but it doesn't quite make sense.
> *
> *   For searches and help try:
> *
> *
> *

*   For searches and help try:

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