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: Dropping first 60 months of every Stock (Permno)


From   "Tim Streibel" <[email protected]>
To   [email protected]
Subject   Re: st: Dropping first 60 months of every Stock (Permno)
Date   Sat, 27 Oct 2012 13:36:36 +0200

Hey Sylvain,

your idea is very simple and it works perfectly! Thanks a lot!


-------- Original-Nachricht --------
> Datum: Sat, 27 Oct 2012 08:57:04 +0000
> Von: WEBER Sylvain <[email protected]>
> An: "<[email protected]>" <[email protected]>
> CC: "[email protected]" <[email protected]>
> Betreff: Re: st: Dropping first 60 months of every Stock (Permno)

> Hi Tim,
> 
> Looping over all observations is clearly inefficient. 
> Assuming you have a variable called "date" that contains the time period,
> and that you have no missing observations, something like this should work:
> 
> sort permno date
> by permno (date): drop if _n<60&mi(ipoyr)
> 
> 
> Hope this helps. 
> 
> Sylvain
> 
> Le 27 oct. 2012 à 01:37, "Tim Streibel" <[email protected]> a écrit :
> 
> > Hey all,
> > 
> > I am having some trouble with efficiently dropping the first 60 monthly
> observations of every stock (uniquely identified by the variable permno).
> > Just briefly explaining some steps in advance:
> > First if-clause helps me identifying that it's a new stock (and no
> ipo-stock), so that I should try to drop next 60 obs.
> > The three if-clauses below try to check, whether there are even 60 obs.
> of that stock (for example: To avoid dropping stocks form the next Permno) 
> > 
> > So my problem is that it's going really, really slow. The dataset
> comprises 3.3 mio observations. However I think It should be possible to do that
> quicker than in a few days ;)
> > I tried with an example dataset of 850 obs. and it looks like it's doing
> what I want it to do. However I cannot completely assure, that it's not
> somehow getting stuck in loop (but tried to think it through several times
> and I dont think so).
> > Thanks in advance for your advice
> > 
> > Here's my source code:
> > 
> > local i=1
> > local permno=permno[1]
> > while `i'<=_N{ // Dropps the first 5 years of CRSP data to assure that
> matching firms are mature companies
> >    if permno[`i']!=`permno' & ipoyr1==.{
> >        local up=`i'+59
> >            if `up'<=_N & permno[`i']==permno[`up']{
> >                local permno=permno[`i']
> >                qui:drop in `i'/`up'
> >            }
> >            else if `up'>_N {
> >                local y=`i'
> >                local permno=permno[`i']
> >                while `y'<=_N & `permno'==permno[`y']{
> >                    qui:drop in `y'
> >                }
> >            }
> >            else if permno[`i']!=permno[`up']{
> >                local x=0
> >                local permno=permno[`i']
> >                while `x'<=1{
> >                    local sum=`i'+`x'
> >                    if `permno'==permno[`sum']{
> >                        qui:drop in `sum'
> >                    }
> >                    else{
> >                        local x=`x'+1
> >                    }
> >                }
> >            }
> >        
> >    }
> >    else{
> >        local i=`i'+1
> >    }
> > }
> > 
> > *
> > *   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/
*
*   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/


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