Lee C Adkins
1.01
2015-07-07
Computes the Belsley, Kuh, Welch table of collinearity diagnostics for linear and nonlinear models
C10
Inputs: cc = variance-covariance from an estimated model
vn = a string with the names of variables (linear model) or names of table's columns for the model estimated.
Output: bb = matrix containing the BKW diagnostics table
Usage: matrix bb = bkw(cc, vn)
Notes: The diagnostics include condition numbers and variance decompositions based on scaled, but not centered, inverse variance-covariance matrix. See http://learneconometrics.com/pdf/Collin/index.html for details.
For a linear model estimated using a variable list, one can easily populate the column label string using the varname command:
list xlist = (list of variables in model)
string vn = varname(xlist)
Otherwise, you can estimate the nonlinear model, look at the output, and code the column names as in the example script using suitable parameter names. In the four outcome ordered probit example that has three regressors (educ, exper, and age) and three cutoff parameters:
string vn = " educ exper age cut1 cut2 cut3 "
See http://learneconometrics.com/pdf/Collin/collin_gretl.pdf for details.
```
matrix co = scale_cov(co)
matrix V U
matrix L = svd(co, &U , &V)
matrix VD = bkw_var_decomp(L, V)
matrix cond_n = cond_num(co)
matrix bkw = bkw_table(cond_n,VD, vn)
return bkw
```

```
string lall = null
loop for i=1..k
sprintf l "l%d",i
string ls = "@l "
string lall += ls
endloop
return lall
```

```
scalar k = cols(V)
#Variance Decomposition
matrix u2 = (V.^2)' .* (1/L ** ones(k,1))
matrix vard = sumr(u2)
matrix p = u2 ./ (vard ** ones(1,k))
matrix p = p'
return p
```

```
matrix vc = inv(vc)
matrix xs = 1/sqrt(diag(vc))
matrix S=I(cols(vc))
matrix S[diag] = xs
matrix scaled_cov = qform(S,vc)
return scaled_cov
```

```
matrix lambda = svd(vc)
scalar ll = max(lambda)
matrix condnumber = sqrt(ll./lambda)
matrix rc = rcond(vc)
# printf "Relative condition number \n%10.4e\n\n",rc
# printf "Condition numbers based on normalized covariance \n%10.0f\n",condnumber
return condnumber
```

```
string lnames = lam_names(nelem(l))
string lname = strsub(lnames, ",", " ")
string vname = strsub(vn, ",", " ")
matrix p = l'~p
colnames(p, " cond @vname " )
rownames(p, " @lname ")
printf "\nThe BKW variance decomposition \n%10.3f\n ",p
return p
```

include bkw.gfn
open mroz87
list xlist = const WE AX WA
probit KL6 xlist
string vn = "educ exper age cut1 cut2 cut3"
matrix co = $vcv
matrix bb = bkw(co, vn)