Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: st: How to drop missing values by period?

 From Xixi Lin To statalist@hsphsun2.harvard.edu Subject Re: st: How to drop missing values by period? Date Mon, 11 Feb 2013 11:16:22 -0500

```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.
>
>
> . 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,
>>>
>>> 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/
```