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: Keeping specific observations


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Keeping specific observations
Date   Fri, 31 Aug 2012 18:29:46 +0100

Good. Thanks, Nick

On Fri, Aug 31, 2012 at 6:22 PM, Eleimon Gonis <[email protected]> wrote:
> Dear Nick,
>
> I humbly apologise! Your solution works a treat! My mistake!
>
> Eleimon
>
> From: [email protected] [[email protected]] On Behalf Of Nick Cox [[email protected]]
> Sent: 31 August 2012 18:19
> To: [email protected]
> Subject: Re: st: Keeping specific observations
>
> I don't accept that. Please look again at my code:
>
> bysort ID (v1) : drop if missing(v1[1])
>
> It's a vital detail that you must sort on -v1- within each group of
> -ID-. If, after sorting, the first value of -v1- is missing, then all
> are.
>
> Nick
>
> On Fri, Aug 31, 2012 at 6:11 PM, Eleimon Gonis <[email protected]> wrote:
>> Dear Nick, David and Elan,
>>
>> First of all, thank you very much for taking the time and helping out.
>>
>> Elan, it worked perfectly, thank you!
>>
>> Nick and David, your solutions are great, but I failed to mention that are some individuals in the dataset who might be missing v1 in the first year, but have values in consequent years. Your solutions drop these individuals too.
>>
>> Thanks,
>> Eleimon
>>
>>
>> From: [email protected] [[email protected]] On Behalf Of Nick Cox [[email protected]]
>> Sent: 31 August 2012 18:00
>> To: [email protected]
>> Subject: Re: st: Keeping specific observations
>>
>> observations. So, try
>>
>> bysort ID (v1) : drop if missing(v1[1])
>>
>> The logic here is that if all values are missing for an individual,
>> then after sorting the first value of -v1- will necessarily be missing
>> too, and that is a criterion for -drop-ing.
>>
>> Nick
>>
>> On Fri, Aug 31, 2012 at 5:46 PM, Afif Naeem <[email protected]> wrote:
>>
>>> Shouldnt "drop if v1 == . " work?
>>
>> From: [email protected]
>>
>>>> I would appreciate your help with the following conundrum. Assume I have a dataset that looks like this:
>>>>
>>>> Year         ID        v1
>>>> 2000         1          2
>>>> 2001         1          2
>>>> 2002         1          3
>>>> 2000         2          3
>>>> 2001         2          .
>>>> 2002         2          3
>>>> 2000         3          .
>>>> 2001         3          .
>>>> 2002         3          .
>>>>
>>>> What I want to achieve is to only keep those individuals that appear with any non-missing values for v1 for any of the years in the dataset.
>>>>
>>>> In other words, I don't think that a command: "keep if v1<." would do, because that would also take out the 2001 observation for the second individual (ID==2), which I'd like to remain in place.
>> *
>> *   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/
> *
> *   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/
*
*   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