%ECON 671 Problem Set 1, Question 4. b) %Hayashi p. 74 (f) %Andrew McCallum, Jan. 28, 2008 %Clear memory, screen, and close all graphs before execution. clear all; clc; close all; %adds the path where I store my functions. addpath('U:\Public\html\files\matlab\functions'); %set the seed so we all get the same results rand('seed',1234); randn('seed',1234); %for some strange reason matlab is changing it's own seed for the uniform %draws. i don't know why this is happening. %Dimensions for the vectors and matrices. n = 100; k1 = 1; k2 = 1; %Generate x1 and x2 vectors. %constant vector x1 = ones(n,k1); %uniform distribution over [1,2] x2 = rand(n,1) + 1; %eplison errors drawn iid from N(0, 2) eps = normrnd(0,sqrt(2),n,1); %Data Generating Process (DGP) is: beta = [0.4; 0.9]; x = [x1, x2]; y = x*beta + eps; plot(y(1:100,1), 'DisplayName', 'y(1:100,1)', 'YDataSource', 'y(1:100,1)'); figure(gcf) %(f) %define a few matrices we'll need P1 = x1*inv(x1'*x1)*x1'; M1 = eye(n,n) - P1; x2tilda = M1*x2; ytilda = M1*y; %(1) regress ytilda on x1 %note i have multiple outputs from myols.m but i only want the first one. [reg1b, junk, junk2, junk3] = myols(ytilda,x1); SSR1 = (ytilda-x1*reg1b)'*(ytilda-x1*reg1b); temp1 = ytilda'*ytilda; %(2) regress ytilda on x2tilda reg2b = myols(ytilda,x2tilda); SSR2 = (ytilda-x2tilda*reg2b)'*(ytilda-x2tilda*reg2b); temp2 = ytilda'*ytilda - reg2b'*x2tilda'*x2tilda*reg2b; %(3) regress ytilda on x1 and x2 reg3b = myols(ytilda,x); SSR3 = (ytilda-x*reg3b)'*(ytilda-x*reg3b); Me = ytilda - x2tilda*reg3b(2,1); temp3 = (Me)'*(Me); %(4) regress ytilda on x2 reg4b = myols(ytilda,x2); SSR4 = (ytilda-x2*reg4b)'*(ytilda-x2*reg4b); temp4 = (Me)'*(Me);