new; cls; /***** Step 1: DGP *****/ b1=1; b2=5; b3=4; sig2=2; Tru_b=b1|b2|b3; @ True parameters @ T=200; @ # of observations @ k=3; @ # of regressors @ x2=rndu(T,1)*2; x3=rndu(T,1)*2; emat=rndn(T,1)*sqrt(sig2); @ Error term @ ymat=b1+x2*b2+x3*b3+emat; /***** Step 2: Estimation(OLS) *****/ X=ones(T,1)~x2~x3; @ T by 3, Independent variables @ Y=ymat; @ T by 1 @ b_hat=inv(X'*X)*X'*Y; @ 3 by 1, Estimates for b1 and b2 @ Y_hat=X*b_hat; @ T by 1, fitted data @ e_hat=Y-Y_hat; @ T by 1, residuals @ sig2_hat=e_hat'e_hat/(T-k); @ Estimates of variance @ /***** Step 3: Simple Hypothesis Test *****/ cov=sig2_hat*inv(X'*X); @ 3 by 3, variance-covariance matrix @ stde=sqrt(diag(cov)); @ 3 by 1, standard deviation @ t_val=b_hat./stde; @ t values @ /***** Step 4: Joint Hypothesis Test *****/ /* Test 1: b1=b2=b3=0 */ R1=1~0~0|0~1~0|0~0~1; L1=3; @ # of Restrictions @ gam1=0|0|0; F1=(R1*b_hat- gam1)'inv(R1*inv(X'X)*R1')*(R1*b_hat-gam1)/(L1*sig2_hat); @ F statistic @ /* Test 2: b1+b2=1 and b2=b3 */ R2=1~1~0|0~1~-1; L2=2; @ # of Restrictions @ gam2=1|0; F2=(R2*b_hat - gam2)'inv(R2*inv(X'X)*R2')*(R2*b_hat-gam2)/(L2*sig2_hat); @ F statistic @ "----------------------------------------------"; " True values Estimates "; Tru_b~b_hat; "----------------------------------------------"; "----------------------------------------------"; " Ho t value "; "b1=0";;t_val[1]; "b2=0";;t_val[2]; "b3=0";;t_val[3]; "----------------------------------------------"; "----------------------------------------------"; " Ho F value "; "b1=b2=b3=0 ";;F1; "b1+b2=1 and b2=b3 ";;F2; "----------------------------------------------"; end;