/* SPLINE REGRESSION AND TEST FOR CONSTANT SLOPE */ /* Load Data and Define Variables */ load path=c:\gauss35\classes\econ5340\data\; load x[1001,12]=cps88.asc; data = x[2:1001,.]; age = data[.,1]; age2 = age^2; grade = data[.,3]; lnwage = data[.,6]; married = data[.,5]; nobs = rows(data); constant = ones(nobs,1); /* Least Squares Estimation */ d12 = grade .> 12; d16 = grade .> 16; gradeless12 = d12.*(grade-12); gradeless16 = d16.*(grade-16); xmat = constant~age~age2~grade~gradeless12~gradeless16~married; k = cols(xmat); b = inv(xmat'*xmat)*(xmat'*lnwage); err2 = (lnwage - xmat*b)'*(lnwage - xmat*b); s2 = err2/(nobs-k); print "estimated coefficient vector = " b; /* Graph Spline Regression */ grade = seqa(8,0.02,nobs); d12 = grade .> 12; d16 = grade .> 16; gradeless12 = d12.*(grade-12); gradeless16 = d16.*(grade-16); age = 28*ones(nobs,1); age2 = (28^2)*ones(nobs,1); xmat1 = constant~age~age2~grade~gradeless12~gradeless16~constant; lnwagehat = xmat1*b; library pgraph; graphset; title("Spline Regression of lnwage--Evaluated at Age=28 and Married=1"); xlabel("Grade"); ylabel("lnwage"); xy(grade,lnwagehat); /*Hypothesis Test for Constant Slope */ R1 = {0 0 0 0 1 0 0}; R2 = {0 0 0 0 0 1 0}; R = R1|R2; q = {0,0}; F = (R*b - q)'*inv(R*inv(xmat'*xmat)*R')*(R*b - q)/(2*s2); print "F Statistic = " F;