Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Replacing missing values only works one way?


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

Dana

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<.
. }

Cheers

Joseph

On Wed, Jul 28, 2010 at 6:43 AM, Dana Chandler <[email protected]> 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.
>
> http://www.stata.com/support/faqs/data/missing.html
> *
> *   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/
>

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index