%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This is practice script 2b for the Matlab tutorial% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% rand('state',37); % set arbitrary seed for uniform draws randn('state',37); % set arbitrary seed for normal draws tic; % start stop watch [fid]=fopen('c:\mlab_tut\mlab\logs\script2b.txt','w'); if fid==-1; warning('File could not be opened'); break else; disp('File opened successfully'); end; load c:\mlab_tut\from_stata.raw; data = from_stata; clear from_stata; y = data(:,3); X = data(:,4:end); n=length(y); k=size(X,2); [bols,se,t,s2] = ols3(y,X); out=[bols se t]; %combine bols, se, and t vectors into a single matrix fprintf(fid,'Output table for betas \n'); fprintf(fid,'coeff\t\tstd\t\tt-value\n'); fprintf(fid,'%6.3f\t%6.3f\t%6.3f\n',out'); fprintf(fid,'\n'); fprintf(fid,'Squared regression error=\t%6.3f \n',s2); fprintf(fid,'\n'); save c:\mlab_tut\mlab\worksp\script2_stuff y X bols; finish = toc; %this will show run time in seconds fprintf(fid,'Time elapsed in seconds \n\n'); fprintf(fid,'%6.3f\n',finish); st=fclose(fid); if st==0; disp('File closed successfully'); else; warning('Problem with closing file'); end;