/****This is just simulated data, 2 instruments, 1 endogenous variable, 3 controls****/ /****Tries to find the size of resampling fractional anderson rubin test in Berkowitz, Caner and Fang , Forthcoming 2011 , Journal of Econometrics, The Validity of Instruments Revisited****/ /***this is robust to weak instruments as well as local to zero violations of perfect exogeneity in instruments****/ /****will give a p-value *****/ /*****step 1: Generate data******/ cls; n=100;/****no of observations*****/ m=2; k=2; om=eye(m+k+1); coze=ones(m,1)*0.2; om[m+1, 1:m]=coze'; om[1:m,m+1]=coze; covuv=ones(k,1)*0.5; om[m+1,m+2:m+k+1]=covuv'; om[m+2:m+k+1,m+1]=covuv; /*om={1 0 0.2 0, 0 1 0.2 0, 0.2 0.2 1 0.5, 0 0 0.5 1}; */ /****om is the omega matrix, first 2 by 2 is the instrument block, 3rd is the structural error, and the last one are reduced form error****/ /***so the correlation between the instruments and the st. error is 0.2****/ /***the correlation between the equations are 0.5****/ /****k=2, m=2*****/ /***k is the number of endogenous variables, m is the number of instruments*****/ s=3;/***no of controls****/ dat=rndn(n,m+k+1); dat=dat*chol(om); u=dat[.,m+1];/***st error****/ v=dat[.,m+2:m+k+1];/*****red form errors****/ z=dat[.,1:m];/***instruments****/ w=rndn(n,s);/***controls****/ gamm={1,2,3}; /****coeffs on controls****/ pp=ones(m,k);/***red form matrix***/ x=z*pp+w*gamm+v; /***x is the endoge vraibles, here we have one***/ b0=ones(k,1);/***coeff on endo variable***/ sii={1,2,1};/***coeffs on controls in structural equation****/ y=x*b0+w*sii+u;/***structural equation****/ /***************data is generated*****/ {ry}=res(w,y); {rx}=res(w,x); {rz}=res(w,z); /*************projected out controls****/ /************Step 2: Create Anderson Rubin test: for H0: b0=1*****/ om1=rz.*(ry-rx*b0); om11=(om1'om1)/n; ar=((ry-rx*b0)'rz*inv(om11)*rz'*(ry-rx*b0))/n;/***heteroskedasticity robust anderson rubin test*****/ /*****Step 3: FAR c values****/ f=1/2-1.5/sqrt(n);/****fractionof the original sample to be resampled, acc to the paper*****/ b=ceil(n*f);/************** block size*****/ nb=100;/****number of resample iterations******/ arb=zeros(nb,1); i=1; do while i<=nb; kk4=zeros(b,1); ss=ceil(seqa(n,-1,b).*rndu(b,1))+seqa(0,1,b); xx=seqa(1,1,n); iii=0; do while iii