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**(-1/2)*(xs-xsb)`; t=us`; create sriv.uus var{y1 y2 y3 y4}; append from t; vv=(50/(50-1))**(1/2)*sp**(1/2)*s2**(-1/2)*(xv-xvb)`; tt=vv`; create sriv.vvv var{y1 y2 y3 y4}; append from tt; quit; %macro ran(k= ); %do n=1 %to &k; data rands&n; retain seed &n&n; do i=1 to 50; call rantbl(seed, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50,iid); output; end; data randv&n; retain seed &n&n&n; do i=1 to 50; call rantbl(seed, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50, 1/50,iid); output; end; run; /*Draw bootstrap samples from us and vv*/ proc iml; use rands&n; read all var{iid} into ids; use randv&n; read all var{iid} into idv; use sriv.uus; read all into us; use sriv.vvv; read all into vv; create sriv.us var{y1 y2 y3 y4}; do i=1 to 50; ustar=us[ids[i,],]; append from ustar; end; create sriv.vv var{y1 y2 y3 y4}; do i=1 to 50; vstar=vv[idv[i,],]; append from vstar; end; /* Calculate the pooled covariance */ use sriv.us; read all into us; use sriv.vv; read all into vv; ubstar=J(50,1,1)*J(1,50,1/50)*us; vbstar=J(50,1,1)*J(1,50,1/50)*vv; s1star=(us-ubstar)`*(us-ubstar)/49; s2star=(vv-vbstar)`*(vv-vbstar)/49; ub=J(1,50,1/50)*us; vb=J(1,50,1/50)*vv; spstar=((50-1)*s1star+(50-1)*s2star)/(50+50-2); /* Calculate T*^2 */ Tisq=(98-4+1)*50*50/((50+50)*98*4)*(ub-vb)* inv(spstar)*(ub-vb)`; edit sriv.tsq; append from Tisq; quit; %end; proc iml; use sriv.tsq; read all into tisq; ord=rank(tisq); do i=1 to 100; rr=ord[i,]; if rr=96 then T96=tisq[i,]; end; use sriv.t0sq; read all into t0sq; print T0sq T96; if T0sq>T96 then print "reject"; else print "accept"; quit; %mend ran; %ran(k=100)