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 on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: indexing for first non-missing value


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: indexing for first non-missing value
Date   Wed, 15 May 2013 17:02:32 +0100

Note also that there is an FAQ


FAQ     . . . . . . . . . . . . . . . . . .  Dropping spells of missing values
        . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox and G. Longton
        3/07    How can I drop spells of missing values at the
                beginning and end of panel data?
                http://www.stata.com/support/faqs/data-management/
                dropping-spells-of-missing-values/
Nick
njcoxstata@gmail.com


On 15 May 2013 13:13, James Bernard <jamesstatalist@gmail.com> wrote:
> Thanks Scott
>
> On Wed, May 15, 2013 at 7:52 PM, Scott Merryman
> <scott.merryman@gmail.com> wrote:
>> egen firstyear = min(year), by(id)
>>
>> Scott
>>
>> On Wed, May 15, 2013 at 6:46 AM, James Bernard <jamesstatalist@gmail.com> wrote:
>>> Hi all,
>>>
>>> I have been dealing with a dataset where I need to copy the value of
>>> the first non-missing value of one variable to create a new variable
>>> called first year observed:
>>>
>>> id             year                                 first year observed
>>> -------      ------------
>>> -----------------------------
>>> A              .                                               1996
>>> A              1996                                          1996
>>> A              1997                                          1996
>>> A              1998                                          1996
>>> A                 .                                             1996
>>> A                 .                                             1996
>>> B               1998                                         1998
>>> B               1999                                          1998
>>> B                   .                                            1998
>>> B                   .                                            1998
>>>
>>>
>>> Going through Stata discussions, I found out that one way is to use indexing
>>>
>>> bysort id: gen first_year_observed=year[1]
>>>
>>> where the bracket indicates the first non-missing value
>>>
>>> But this find only the first value, be it missing or non-missing. Is
>>> there any simple indexing way?
*
*   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