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


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: panel data-dropping all observations for the identifier when certain variable value is missing
Date   Wed, 6 Jul 2011 11:36:21 +0100

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 
[email protected] 

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: [email protected]
> To: [email protected]
>
> 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 <[email protected]> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index