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: How to drop missing values by period?


From   Xixi Lin <winnielxx@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How to drop missing values by period?
Date   Mon, 11 Feb 2013 11:40:55 -0500

Hi Maarten,

Yes, it works. Thanks.

Best,
Xixi Lin

On Mon, Feb 11, 2013 at 11:25 AM, Maarten Buis <maartenlbuis@gmail.com> wrote:
> Did you actually try what Nick proposed? If you did than you would
> have seen that what you said is not true. If you drop the observation
> (row) "id 1, period 1" than the observation (row) "id 1, period 2"
> will still be there.
>
> *------------------ begin example ------------------
> drop _all
> input id      period  x1      x2
> 1       1       1       4
> 2       1       2       .
> 3       1       .       2
> 1       2       4       4
> 2       2       5       3
> 3       2       .       2
> end
>
> drop if missing(x1, x2)
>
> list
> *------------------- end example -------------------
> (For more on examples I sent to the Statalist see:
> http://www.maartenbuis.nl/example_faq )
>
> Hope this helps,
> Maarten
>
> On Mon, Feb 11, 2013 at 5:16 PM, Xixi Lin <winnielxx@gmail.com> wrote:
>> Hi Nick,
>>
>> I know what do you mean, if I, for instance, drop id 1, then in period
>> 2, id 1 is also gone. I am thinking is that possible only to drop id 1
>> in period 1, while in other periods, id 1 is still there. I am not
>> sure did I clearify this time?
>>
>> Best,
>> Xixi Lin
>>
>> On Mon, Feb 11, 2013 at 10:25 AM, Nick Cox <njcoxstata@gmail.com> wrote:
>>> Thanks for the example. Stata usually takes care of this for you in that
>>>
>>> 1. A command uses as many as observations as possible.
>>>
>>> 2. Most statistical commands ignore missing values.
>>>
>>> But in your example
>>>
>>> . drop if missing(x1, x2)
>>>
>>> will drop observations if either -x1- or -x2- is missing. It's not
>>> clear to me that you need to think of this period by period, as that
>>> makes no difference to the outcome.
>>>
>>> Nick
>>>
>>> On Mon, Feb 11, 2013 at 3:18 PM, Xixi Lin <winnielxx@gmail.com> wrote:
>>>> Hi Nick,
>>>>
>>>> Thanks for the instant reply. What I mean is like:
>>>> id      period  x1      x2
>>>> 1       1       1       4
>>>> 2       1       2       .
>>>> 3       1       .       2
>>>> 1       2       4       4
>>>> 2       2       5       3
>>>> 3       2       .       2
>>>>
>>>> In period 1, I want to keep id 1 because id 2 and id 3 have missing
>>>> values; in period 2, I want to keep id 1 &2, because id 3 has missing
>>>> values.
>>>>
>>>> I have time series data, but I wanna do a cross-sectional regressions
>>>> and wanna keep the maximum of observations. So I am wondering if it is
>>>> possible to drop obs only in one period while keeping it in  another
>>>> period.
>>>>
>>>> Thanks.
>>>> Xixi Lin
>>>>
>>>> On Mon, Feb 11, 2013 at 9:59 AM, Nick Cox <njcoxstata@gmail.com> wrote:
>>>>> This sounds to me as if you want -keep- and -drop- the same
>>>>> observations. That can't be done.
>>>>>
>>>>> Perhaps you should show what your data look like with variable names,
>>>>> and link your question to such an example.
>>>>>
>>>>> Nick
>>>>>
>>>>> On Mon, Feb 11, 2013 at 2:53 PM, Xixi Lin <winnielxx@gmail.com> wrote:
>>>>>
>>>>>> I tried to drop missing values period by period, in 120 periods. In other
>>>>>> words, in period 1, I want to drop the observations if dependent variables
>>>>>> have missing values only in period 1; while in period 2, drop the
>>>>>> observations if dependent variables have missing values only in period 2,
>>>>>> should keep those that missing in period 1 but not missing in period 2. For
>>>>>> instance:
>>>>>>
>>>>>> In period 1, I want to keep id 1; in period 2, I want to keep id 1 &2.
>>>>>>
>>>>>> Does anyone knows how to do that? Thanks a lot.
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
>
>
>
> --
> ---------------------------------
> Maarten L. Buis
> WZB
> Reichpietschufer 50
> 10785 Berlin
> Germany
>
> http://www.maartenbuis.nl
> ---------------------------------
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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