Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: A question concerning Stata logic


From   "Daniel Hoechle" <[email protected]>
To   <[email protected]>
Subject   st: A question concerning Stata logic
Date   Thu, 1 Dec 2005 10:15:35 +0100

Dear all

Consider the following three identical variables to start with:

var1    var2    var3
 .       .        .
 .       .        .
 .       .        .
 2       2        2
 3       3        3
 4       4        4
 .       .        .
 .       .        .
 .       .        .

Typing

. replace var2=var2[_n-1] if var2==. & _n>1
. replace var3=var3[_n+1] if var3==. & _n<_N

results in

var1    var2    var3
 .       .        .
 .       .        .
 .       .        2
 2       2        2
 3       3        3
 4       4        4
 .       4        .
 .       4        .
 .       4        .


Why does Stata replace all three missings in the first case but only the
first missing in the second case? Do I have to sort the dataset the
other way around in order to fill var3 in a similar way as var2 or is
there an easy workaround?

Thanks a lot.

Best,
Daniel

 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index