%Hendrik Wolff %ARE 213, January 18, 2006 % "%" is the symbol making a comment! % The following changes the Directory for Matlab: same as DOS commands % Exampe, this file is in ..../ARE213/Section/test.m cd .. % we go to ..../ARE213/ cd data % changes to ....ARE213/data/ load nls_2006.mat % Here we load data from the subfolder data cd .. % go back to ..../ARE213/ cd HWOutput diary diaryfortest % this automatically creates a diary, useful later analyzing output later and for debugging cd .. cd Section % ..../ARE213/Section/ Hence here the file OLS.m and the file test.m are located % For this problem set you will have to use the data set NLS 2006.MAT which is available % on the website for the course. There are 929 observations on nine variables in this data set, % luwe (log weekly wage), educ (years of education), exper (years of experience), age (age % in years), fed (father’s education in years), med (mothers education in years), kww (a test % score), iq (an iq score), and white (indicator for white). % 1. Report the minimum, maximum, mean and standard deviation for all variables. 'Problem 1' 'Report the minimum, maximum, mean and standard deviation for all variables: ' % ***commands ending with ";" surpress output, otherwise result will be printed on screen data = [luwe educ exper age fed med kww, iq white]; % data is a (N x K) Matrix mini = min(data) %min(data) goes columnwise over data and picks for each column the min, the result is a 1 x K vector 'In Columns: minimum maximum standard deviation ' 'In Rows: luwe educ exper age fed med kww iq white' sum = [mini', max(data)', std(data)'] % 2. Estimate a linear regression model for log wages on education, experience, and experience % squared. Report the estimates and standard errors. Also report the full % variance/covariance matrix for all parameters, that is both the regression parameters % as well as the residual variance. exper_sq = exper .* exper; % note .* , ./ are cell by cell operators instead of the usual matrix operators n = length (luwe); on=ones(n,1); X = [on educ exper exper_sq]; y = luwe; Beta = inv(X'*X)*X'*y eps = y - X * Beta; [n, k] = size(X); sig_sq = eps' * eps / (n-k); var = sig_sq * inv(X'*X); 'Standard Errors of Coefficients' se = sqrt(diag(var)) 'Variance Covariance Matrix for Coefficients' var 'Variance for residual' sig_sq 'Variance for variance ' 2*sig_sq*sig_sq/n %Variance-Covariance Matrix of the entire parameter vector of beta and %sigma2, see below % Here an useful alternnative to Problem 2: % We start with the self defined OLS function 'cross check results with above' [out,var,rsq,sigs]=ols(luwe,[on,educ,exper,exper.*exper]) % should be self-explanatory when looking at the function ols.m. 'compute an Confidence Interval for beta2' [out(2,1),out(2,1)-1.96*out(2,2),out(2,1)+1.96*out(2,2)] % 3. Predict the effect on average log earnings of decreasing everybody’s education level by % one year. diary off