% TESTING LINEAR RESTRICTIONS % Load Data clc; M = importdata('matlabex11data.txt',' ',1); data = M.data; n = size(data,1); % Define Variables age = data(:,1); age2 = age.^2; grade = data(:,3); lnwage = data(:,6); potexp = data(:,9); married = data(:,5); union = data(:,10); constant = ones(n,1); xmat = [constant,age,age2,grade,married,union]; k = size(xmat,2); % Least Squares Estimation urb = inv(xmat'*xmat)*(xmat'*lnwage); rb = inv(constant'*constant)*(constant'*lnwage); urerr = lnwage - xmat*urb; rerr = lnwage - constant*rb; s2 = (urerr'*urerr)/(n - k); disp(['Unrestricted Coefficient Vector = ']); disp(num2str(urb)); disp(['Restricted Coefficient Vector = ' num2str(rb)]); % Testing Restriction #1 R1 = [0 0 0 1 0 0]; q1 = 0; F1 = (R1*urb - q1)'*inv(R1*inv(xmat'*xmat)*R1')*(R1*urb - q1)/s2; disp(['F statistic for Restriction #1 = ' num2str(F1)]); % Testing Restriction #2 J = k - 1; urerrsq = urerr'*urerr; rerrsq = rerr'*rerr; F2 = ((rerrsq - urerrsq)/J)/(urerrsq/(n - k)); disp(['F statistic for Restriction #2 = ' num2str(F2)]); % R2 r2 = 1 - (urerr'*urerr)/((lnwage-mean(lnwage))'*(lnwage-mean(lnwage))); disp(['R-squared = ' num2str(r2)]);