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: recoding missing value on variable with nonmissing value on variable within groups


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: recoding missing value on variable with nonmissing value on variable within groups
Date   Wed, 20 Jun 2012 14:32:54 +0100

You have given me another reason to add to my quirky dislike of -recode-.

It looks as if you can get what you want by

egen wanted = max(jury_id), by(yearmonth)

but you need to check that there is at most one non-missing value for
each group.

That could be done by

gen touse = !missing(jury_id)

bysort touse yearmonth (jury_id) : gen same = jury_id[1] == jury_id[_N]

assert same

Nick

On Wed, Jun 20, 2012 at 11:45 AM, Erik Aadland <[email protected]> wrote:

> I am trying to recode the missing values on "jury_id" in example below with the nonmissing values for jury_id by yearmonth.
> Unfortunately, the "by" command is not allowed with the recode command.
>
> yearmonth    jury_id    WANTED RESULT
> 1            1          1
> 1            1          1
> 1            1          1
> 1            .          1
> 2            2          2
> 2            2          2
> 2            2          2
> 2            2          2
> 3            2          2
> 3            .          2
> 3            .          2
> 4            3          3
> 4            3          3
>
>
> Any input on this problem would be very much appreciated.

*
*   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