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   Erik Aadland <[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 13:43:19 +0000

Thank you, Nick.
 
I found a rather coding intensive solution involving an additional dataset, -tag- and -joinby- that appear to work, but your solution is much simpler and more elegant.
 
Regards,
 
Erik.
 



> Date: Wed, 20 Jun 2012 14:32:54 +0100
> Subject: Re: st: recoding missing value on variable with nonmissing value on variable within groups
> From: [email protected]
> To: [email protected]
> 
> 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/ 		 	   		  
*
*   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