% hw1_1.m % Economics 696F, Spring 2007 % suggested solution to HW1, Question 1 % Data for this question: T=[zeros(10,1) ones(10,1)]; Y=[-1.1 -2.1 -0.7 -0.7 0.4 0.8 -0.1 1.8 0.1 1.1 -2.3 1.1 0.1 1.0 -0.6 -1.7 2.3 2.4 2.6 4.6]; % First calculate sample means yhat1 = mean(Y(T==1)) yhat0 = mean(Y(T==0)) tauhat = yhat1 - yhat0 % this yielded: tauhat=1 % Find p-value for hypothesis of no treatment effect J=500000; % number of simulations exceed = 0; % number of times a simulation exceeds observed tauhat for j=1:J, % first, create a hypothetical random treatment assignment R = randn(20,1); medR = median(R); T_j = R>medR; yhat1_j = mean(Y(T_j==1)); yhat0_j = mean(Y(T_j==0)); tauhat_j = yhat1_j - yhat0_j; if abs(tauhat_j)>abs(tauhat), exceed=exceed+1; end; end; pvalue_sim=exceed/J % this led to a p-value of 0.20366 % finally, calculate t-statistic s1squared = sum( (Y(T==1)-yhat1).^2)/9 s0squared = sum( (Y(T==0)-yhat0).^2)/9 t_stat = (yhat1-yhat0)/sqrt(s1squared/10+s0squared/10) % t-stat is 1.3087 % p-value (using normal approximation) is approximately .2 % end hw1_1.m