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]

st: Dropping first 60 months of every Stock (Permno)


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

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/


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