Elan and Nick, thank you very much. It has been magic.
-----Mensaje original-----
De: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] En nombre de Nick Cox
Enviado el: lunes, 08 de abril de 2013 21:51
Para: statalist@hsphsun2.harvard.edu
Asunto: Re: st: RE: Dropping all subjects but those in the last period
As Elan implies, Stata is very good at such problems. There is certainly no
need for intricate choreography with files. Here is another solution:
bysort id (year) : drop if year[_N] < 2000
Nick
njcoxstata@gmail.com
On 8 April 2013 20:39, Cohen, Elan <cohened@upmc.edu> wrote:
> Let's assume 2010 is the "last year". Then:
>
> egen flag = total(year==2010), by(id)
> drop if !flag
Miguel Angel Duran
> My dataset includes observations for about 9000 companies per year in
> a twenty years period. To clean the dataset, I would like to drop all
> those companies that are not present in the last year (because the
> rest went bankrupt or were absorbed), but I do not know how to do it.
> Can this be done just by splitting the datasets by period and then
> merging them? Each company has the same id across years.
*
* 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/
*
* 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/