* Computing p-values for sample correlation coefficients computed with * the STAT command. * * REFERENCE: Newbold, Statistics for Business and Economics, * 1995, 4th Edition, pp. 433-434; * 1991, 3rd Edition, pp. 464-465. * * To test the null hypothesis H0: rho=0 the test statistic is: * t=rho/sqrt((1-rho*rho)/(N-2)) * Under H0 the statistic has a t-distribution with (N-2) degrees for freedom. * The DISTRIB command can be used to compute the p-values. * ?demo * Use the STAT command to compute and save the correlation matrix. stat consume income price / pcor cor=cor * Set the degrees of freedom gen1 df=\$N-2 * Set the number of variables gen1 k=3 * Set the number of correlations to test gen1 kc=k*(k-1)/2 dim rho kc * * Stack the correlations into a vector RHO * set nodoecho set nooutput gen1 kk=k-1 gen1 n=0 do %=1,kk gen1 a=%+1 do #=a,k matrix c=cor(#,%) gen1 n=n+1 sample n n genr rho=c endo endo * * Calculate a test statistic * sample 1 kc genr test=rho/sqrt((1-rho*rho)/df) genr test=abs(test) * Now use the DISTRIB command to get a p-value distrib test / type=t df=df cdf=cdf * Get the p-value for a 2-sided test genr pvalue=2*(1-cdf) print rho test pvalue stop