load WAGE1.mat;
dd = WAGE1;
n=size(dd,1);

  %Obs:   526

  %1. wage                     average hourly earnings
  %2. educ                     years of education
  %3. exper                    years potential experience
  %4. tenure                   years with current employer
  %5. nonwhite                 =1 if nonwhite
  %6. female                   =1 if female
  %7. married                  =1 if married
  %8. numdep                   number of dependents
  %9. smsa                     =1 if live in SMSA
 %10. northcen                 =1 if live in north central U.S
 %11. south                    =1 if live in southern region
 %12. west                     =1 if live in western region
 %13. construc                 =1 if work in construc. indus.
 %14. ndurman                  =1 if in nondur. manuf. indus.
 %15. trcommpu                 =1 if in trans, commun, pub ut
 %16. trade                    =1 if in wholesale or retail
 %17. services                 =1 if in services indus.
 %18. profserv                 =1 if in prof. serv. indus.
 %19. profocc                  =1 if in profess. occupation
 %20. clerocc                  =1 if in clerical occupation
 %21. servocc                  =1 if in service occupation
 %22. lwage                    log(wage)
 %23. expersq                  exper^2
 %24. tenursq                  tenure^2
 
y = dd(:,22);
wage = dd(:,1);
x_1 = dd(:,2);
x_2 = dd(:,3);
x_3 = dd(:,4);
x_4 = dd(:,8);
one = ones(size(y,1),1);
alpha=.05;
[b, bint,r]=regress(y,[one x_1],alpha);

sigmahat2 = (1/(size(y,1)-2))*sum(r.^2);
b 
bint
sigmahat2

yhat = b(1)+b(2)*x_1;


Ew=exp(yhat).*exp(sigmahat2/2);

% Impact on one more year of education on expected wage

impact1 = (exp(b(2))-1)*exp(sigmahat2/2)*exp(yhat);

xf = [x_1 y yhat];
xf=sortrows(xf,1);

figure (1)
plot(xf(:,1),xf(:,2),'+',xf(:,1),xf(:,3),'black')
box off
grid on
xlabel('years of education')
ylabel('Estimated regression')
title('Regression plot')


xf2 = [x_1 exp(y) Ew impact1];
xf2=sortrows(xf2,1);

figure (2)
plot(xf2(:,1),xf2(:,2),'+',xf2(:,1),xf2(:,3),'black')
box off
grid on
xlabel('years of education')
ylabel('Estimated regression')
title('Regression plot')

figure (3)
plot(xf2(:,1),xf2(:,4),'blue')
box off
grid on
xlabel('years of education')
ylabel('Impact of one additional year of education')
title('Additional education')
