*
* @RegPartCorr
*
* This is a regression post-processor which computes and prints the partial
* correlations between the regressors and the dependent variable. This makes
* extensive use of the %sweep function. It must be used after a LINREG instruction.
*
* Revision Schedule
*  01/2003 Written by Tom Doan, Estima
*  01/2005 Revised to use REPORT and include the standardized coefficients
*
proc RegPartCorr
*
local rect ss zz
local integer i
local vect[strings] rlabels
local real pcorr
*
* Compute the correlation matrix of the regressors and the dependent
* variable. Copy into a RECT matrix, since that's what %SWEEP needs.
*
compute rlabels=%eqnreglabels(0)
cmom(corr,lastreg,depvar)
compute ss=%cmom
*
* Sweep on all the regressors to get the (standardized) regression.
*
do i=1,%nreg
   compute ss=%sweep(ss,i)
end do i
*
* Now sweep ss on each regressor to back it out of the regression. The (i,i) and
* (%nreg+1,%nreg+1) diagonal elements will give (1-R**2) for the regressions of
* regressor i on the others and the depvar on the others. (i,%nreg+1) is the
* covariance between the residuals.
*
disp
disp "Partial Correlations and Standardized Coefficients"
report(action=define,hlabel=||"Label","Partial R**2","Std. Coefficient"||)
do i=1,%nreg
   compute zz=%sweep(ss,i)
   compute pcorr=zz(i,%nreg+1)/sqrt(zz(i,i)*zz(%nreg+1,%nreg+1))
   if .not.%valid(pcorr)
      compute pcorr=%na
   report(atrow=i,atcol=1) rlabels(i) pcorr ss(i,%nreg+1)
end do i
report(action=format,width=8,atcol=2,tocol=3)
report(action=show)
end

