Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: copying data form _n |
Date | Wed, 27 Apr 2011 09:58:37 +0100 |
The precise answer depends on what else is true but 1. bysort whatever (flag) : replace y = y[1] if _n == 2 & flag == 2 & missing(y) & flag == 1 or 2. egen replacement_value = mean(y / flag == 1) , by(whatever) bysort whatever : replace y = replacement_value if flag == 2 & missing(y) should give you some flavour. See also FAQ FAQ . . . . . . . . . . . . . . . . . . . . . . . Replacing missing values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox 2/03 How can I replace missing values with previous or following nonmissing values? http://www.stata.com/support/faqs/data/missing.html Nick On Wed, Apr 27, 2011 at 9:26 AM, Daniel Marcelino <dmsilva.br@gmail.com> wrote: > > I need to replace values of variables from observation flagged==1 to > observation flagged==2 if the last has missing values. > * * 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/