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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: copying data form _n


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/


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