Guest User

Untitled

a guest
Jan 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. clear; close; clc;
  2. %Define the population parameters
  3. alpha=0.5;
  4. beta=0.9;
  5. % Sample size n
  6. n=10000;
  7. % Number of samples m
  8. m=1000;
  9. % Store the estimated beta in a vector
  10. beta_hat=zeros(m,1);
  11. %by hand
  12. for i=1:m
  13. %Generate independent variable randomly
  14. x= randn(n,1);
  15. %Generate errors in the population
  16. e=randn(n,1);
  17. %Generate the dependent variable
  18. y=alpha+beta*x+e;
  19. %Generate the LS estimates of alpha and beta using matrix formulation
  20. X=[ones(n,1) x];
  21. beta_hatvec=(inv((X'*X)))*X'*y;
  22. %define the residuals
  23. resid = y-(X*beta_hatvec);
  24. %estimate of sigma_2
  25. sigma2_hat=(resid'*resid) / (size(X,1)-size(X,2));
  26. %estimate of Vhat
  27. vcov_beta_hat = (sigma2_hat*inv((X.'*X)));
  28. stderror_hatvec = sqrt(diag(vcov_beta_hat));
  29. % Pull out only the second component - the estimate of beta
  30. beta_hat(i)=beta_hatvec(2);
  31. std_error(i)=stderror_hatvec(2);
  32. end
  33. t_stat=(beta_hat)./std_error.';
  34. sort_t_stat=sort(t_stat);
  35.  
  36. crit10_actual=sort_t_stat(900);
  37. crit5_actual=sort_t_stat(950);
  38. crit1_actual=sort_t_stat(995);
  39.  
  40. critical = [crit1_actual crit5_actual crit10_actual]
Add Comment
Please, Sign In to add comment