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   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: Replacing missing values only works one way?
Date   Wed, 28 Jul 2010 01:30:38 +0000

<>

Please provide an example of your data and the commands you're attempting--it's not clear from your description what "doesn't work" about these commands.   Both commands you provided do work:
********!
sysuse auto, clear
keep rep78
recode rep78 (1=.a)
clonevar rep79 = rep78
***
replace rep78 = rep78[_n-1] if rep78>=.
replace rep79 = rep79[_n+1] if rep79>=.
********!

What you might mean is that these commands don't always fill in all the missing values.  This is probably happening when you have a run of missings down a column.  So, in the example below, "x" won't be filled in because there are no previous non-missing observations and "y" won't be filled in until there the next value is non-missing:

**********!
clear
inp  x y  
. 1
. 2
2 .
3 .
4 .
5 6
end

replace x = x[_n-1] if mi(x)
replace y = y[_n+1] if mi(y)
***********!

~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754


On Jul 27, 2010, at 4:13 PM, 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.
> 
> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index