% crspstock. Loads crsp data and turns it into matlab % matrices. See crspreg.m for regressions that use this data % Data is converted from crspstock1.csv and crspstock2.csv. % variables are % >> permno = M(:,1); % >> permco = M(:,2); % >> date = M(:,3); % >> shrcd = M(:,4); % >> exchcd = M(:,5); % >> shrout = M(:,6); % >> prc = M(:,7); % >> ret = M(:,8); if 1; % convert text files to matlab disp('starting to read text file'); [permno, permco, dates, shrcd, exchcd, shrout, dlret, prc, ret, vwretd, sptrd ] = textread('crspstock1.csv','%f%f%f%f%f%f%s%s%s%f%f','delimiter',',','headerlines',1); disp('text file read'); % Old: Relpaced by str2double which gives element by element NAN % for i = 1:size(prc,1); % if strcmp(dlret(i),'')==1 % dlret(i)=cellstr('-99'); % elseif strcmp(dlret(i),'T')==1 % dlret(i)=cellstr('-99'); % elseif strcmp(dlret(i),'S')==1 % dlret(i)=cellstr('-99'); % elseif strcmp(dlret(i),'P')==1 % dlret(i)=cellstr('-99'); % end; disp('changing strings to numbers and saving...'); prc = str2double(prc); % string to numeric value ret = str2double(ret); dlret = str2double(dlret); save crspstock1; end; if 1; % convert text files to matlab disp('starting to read text file'); [permno2, permco2, dates2, shrcd2, exchcd2, shrout2, dlret2, prc2, ret2, vwretd2, sptrd2 ] = textread('crspstock2.csv','%f%f%f%f%f%f%s%s%s%f%f','delimiter',',','headerlines',1); disp('text file read'); disp('changing strings to numbers and saving...'); prc2 = str2double(prc2); % string to numeric value ret2 = str2double(ret2); dlret2 = str2double(dlret2); save crspstock2; end; %load crspstock; % good data: % shrcd = 10 or 11, % exchcode 1 NYSE 2 AMEX 3 NASDAQ, we want 3 ? % shrout check decent numbers % prc not 0, -99. Use abs negatives are ok.