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: FW: How to keep only firms that have at least two consecutive years of data


From   Muhammad Anees <anees@aneconomist.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: FW: How to keep only firms that have at least two consecutive years of data
Date   Fri, 6 Jul 2012 09:18:22 +0500

Yes, I agree 100% with Nick, and Nick has suggested a similar solution
to me earlier which I partly copied from my do file for an analysis
but missed the next line. The next lines were the same as he suggest
here too. To keep the consecutive observations. Thanks Nick for
reminding me again.


Anees

On Thu, Jul 5, 2012 at 8:00 PM, Nick Cox <njcoxstata@gmail.com> wrote:
> Muhammad's code finds panels with two or more years of data. Nothing
> implies that they will all be consecutive.
> Best to omit the square brackets, by the way.
>
> A more general question has long been an FAQ
>
> FAQ     . . . . . . Identifying runs of consecutive observations in panel data
>         . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox and V. Wiggins
>         8/02    How do I identify runs of consecutive observations
>                 in panel data?
>                 http://www.stata.com/support/faqs/data/panel.html
>
> But something simpler may suffice here, say
>
> bysort id (year) : gen spacing = year - year[_n-1]
> bysort id (spacing) : keep if spacing[1] == 1
>
> because if there are at least two consecutive years, the smallest
> spacing will be 1 year.
>
> I am not clear whether "missing values" means what it says or refers
> to gaps in the data.
>
> Nick
>
> On Thu, Jul 5, 2012 at 3:13 PM, Muhammad Anees <anees@aneconomist.com> wrote:
>
>> Check this might help you.
>>
>> xtset id year
>> bys id: gen nyear=[_N]
>> keep if nyear>1
>
>  On Thu, Jul 5, 2012 at 7:04 PM, umut senalp <uerksan@hotmail.com> wrote:
>
>>> I have a panel of 1250 units (firms) and five variables (with missing values), for the time period of  2003 to 2011. I would like to keep only firms that have a minimum of 2 consecutive annual observations for all variables together. I would be glad if you could help me to write a code for it.
>
> *
> *   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/



-- 

Best
---------------------------
Muhammad Anees
Assistant Professor/Programme Coordinator
COMSATS Institute of Information Technology
Attock 43600, Pakistan
http://www.aneconomist.com

*
*   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