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: panel data-dropping all observations for the identifier when certain variable value is missing


From   Muhammad Anees <anees@aneconomist.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: panel data-dropping all observations for the identifier when certain variable value is missing
Date   Wed, 6 Jul 2011 16:53:24 +0500

Dear Nick!

What I understood now from this discussion is that Sabrina needed to
drop only observations where date is less than a date in 2008 or any
specific year, and I mistakenly advised to sue _drop xvar if_ or _keep
xvar if_    pair of commands which will drop some variables instead of
observations.

I would appreciate further any idea which might help to learn Stata
and to develop a hand on selecting specific command/code/progrmming
will be most suitable to use in such short times. My guess is to use
Stata intensively for data manipulations and note what is going on in
what circumstances on exemplary data.

Lastly my intent was not misleading the list member at all.

Anees

On Wed, Jul 6, 2011 at 3:36 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> The condition
>
> ... if offdate[_N] < 2008
>
> should be replaced by something like
>
> ... if offdate[_N] < mdy(1,1,2008)
>
> What you do with missings is up to you, but they would frustrate the code above.
>
> If any -offdate- were missing, it would be easier to go
>
> egen lastdate = max(offdate), by(firmid)
> drop if lastdate < mdy(1,1,2008)
>
> Nick
> n.j.cox@durham.ac.uk
>
> Sabrina Helmut
>
> thank you very much so far. There is only one thing I did probably not describe enough. There are observations for all firms/IDs for the years 2004-2010 irrespective of whether there is data for the certain observation (. if missing). How should I rearrange your commands then? Furthermore I do not only have years but complete dates like 31dec2008.
> Thanks
> -----------------------------------------
>> Date: Wed, 6 Jul 2011 08:28:27 +0100
>> Subject: Re: st: panel data-dropping all observations for the identifier when certain variable value is missing
>> From: njcoxstata@gmail.com
>> To: statalist@hsphsun2.harvard.edu
>>
>> bysort firmid (offdate) : drop if offdate[_N] < 2008
>>
>> bysort firmid (offdate) : gen byte islast = _n == _N
>>
>> list firmid offdate if islast
>>
>> See also
>>
>> SJ-2-1 pr0004 . . . . . . . . . . Speaking Stata: How to move step by: step
>> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
>> Q1/02 SJ 2(1):86--102 (no commands)
>> explains the use of the by varlist : construct to tackle
>> a variety of problems with group structure, ranging from
>> simple calculations for each of several groups to more
>> advanced manipulations that use the built-in _n and _N
>>
>> Nick
>>
>> On Wed, Jul 6, 2011 at 1:07 AM, Sabrina Helmut <vitamint@hotmail.de> wrote:
>>
>> > I have firm-year observations for the years 2003-2010. For cases where the last value for the variable <offdate>, which is a variable containing dates, is older than a
>> > date in 2008 (so date in 2007, 2006,...) then stata shall drop the firm/identifier at all, so for
>> > every year. Then, I want stata to show me for every firm/identifier the last entry for the variable <offdate>, which could then either be a date in 2008, 2009 or 2010. Which commands could help me doing this?
>
> *
> *   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/
>



-- 
Muhammad Anees
MSc & MS in Economics

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index