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: FW: How to keep only firms that have at least two consecutive years of data
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: FW: How to keep only firms that have at least two consecutive years of data
Date
Thu, 5 Jul 2012 16:06:58 +0100
In the light of this crucial detail my previous suggestion can be modified to
drop if missing(var1, var2, var3, var4, var5)
bysort id (year) : gen spacing = year - year[_n-1]
bysort id (spacing) : keep if spacing[1] == 1
On Thu, Jul 5, 2012 at 3:56 PM, umut senalp <[email protected]> wrote:
> Thank you for your reply, the thing is, all firms have 9 consecutive years of observation for the 5 variables but with missing. What I am trying to do is to keep only firms have observation for all the variables and have it at least two consecutive years. When I follow this
> xtset id year
>> bys id: gen nyear=[_N]
>> keep if nyear>1 , this does not drop any observation at all, since all id's have 9 years data for the variables.
From: [email protected]
>> 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 <[email protected]> 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/