***************************************************************************** * PROGRAM: access1.f - Sample program to read crsp daily and monthly stock * files using random access programming * * DESCRIPTION: This program calculates beta in a given calender range * * All securities with data in the monthly and daily databases * * USAGE: Change udopen to umopen and udclose to umclose for monthly * data where specified. * * Add code for desired extraction or processing where * specified. See the "Stock File User's Guide" and "Stock * File Programmer's Guide" for assistance. * * Then, compile the program as follows: f77 -o access access1.f -I$CRSP_INCLUDE $CRSP_LIB/crsplib.a * * Then run the executable "access" generated from the compile * step by simply typing: access * **************************************************************************** program access include 'us.txt' integer kperm integer begdate,enddate,bind,eind c------------------------------------------------------------------------ c Required beginning dates and ending dates are initialized here data begdate,enddate /19500101, 19591231/ c----------------------------------------------------------------------------- c This statement opens the monthly index data call umcal(nyseamex) c This statement opens the monthly data file for NYSE and AMEX call umopen(nyseamex) c----------------------------------------------------------------------------- c----------------------------------------------------------------------------- c If you know the CRSP permanent id numbers "permno" use the following c lines of code to read the file. For every number "kperm" in the file, c the machine will look for the corresponding data on the disk (and c eliminate the "c" in the first column) c 100 read (10,1000,end=900) kperm c1000 format(i5) c call usgetper(1,kperm,infos+returns,*900) c If the machine could not find this number, go to the next one c if (kperm. ne . permno) goto 100 c---------------------------------------------------------------------------- c Otherwise, if you just want to go through all the data, use the c following 100 call usgetper(1,inext,none,*900) c Now check to see whether this security has data in the range you c are interested in -- if not, go back to 100 and get another one! if(caldt(enddat).lt.begdate.or.caldt(begdat).gt.enddate) goto 100 c We now have the required information available. Calculate beta! call usgetper(1,isame,infos+returns,*900) c--------------------------------------------------------------------------- c Now process the data (in this case, compute beta) call mysub(permno,compnm(numnam),ret,begret,endret,vwretd) c---------------------------------------------------------------------------- c now go get data for another company goto 100 c----------------------------------------------------------------------------- 900 call umclose c----------------------------------------------------------------------------- close(unit=10) close(unit=11) stop end subroutine mysub(permno,comp,ret,begret,endret,mkt) real ret(1),mkt(1) integer permno,begret,endret character*32 comp x=0 y=0 x2=0 y2=0 xy=0 t=0 do 23000 i = begret,endret if(.not.(ret(i) .ge. -1))goto 23002 if(.not.( i .gt. begret))goto 23004 if(.not.( ret(i-1) .ge. -1))goto 23006 t=t+1 x = x + mkt(i) y = y + ret(i) x2 = x2 + mkt(i) * mkt(i) y2 = y2 + ret(i) * ret(i) xy = xy + mkt(i) * ret(i) 23006 continue 23004 continue 23002 continue 23000 continue if(.not.(t .gt. 0 ))goto 23008 x = x/t y = y/t x2 = x2 - t*x*x xy = xy - t*x*y beta = xy/x2 goto 23009 c else 23008 continue beta = -999999 23009 continue write(6,*)permno,' ',comp,beta end