I would like to have help with modifying the code in ridgereg.prg (see the attached code) so that I can OBTAIN STANDARD ERRORS from the estimated slope coefficients in the ridge regression model. As it is now, the add-in only provides coefficient estimates.
Code: Select all
include .\ridgelib.prg
logmode +addin
%sample = @pagesmpl
%origsmpl = %sample
if @len(%args) then
%dep = @word(%args,1)
%regs = @wmid(%args,2)
%lambda = @equaloption("L")
if @len(%lambda)=0 then
%lambda = "0"
endif
else
%dep = ""
%regs = ""
%lambda = "0"
!result = @uidialog("caption", "Ridge Regression", "edit", %dep, "Enter a dependent variable", "edit", %regs, "Enter a list of regressors (a constant will be automatically added)",250, "edit", %lambda, "Enter a value for the biasing constant", "edit", %sample, "Sample")
if !result = -1 then
stop
endif
endif
'check valid value for lambda
!l = @val(%lambda)
if !l = NA then
@uiprompt("Invalid value for the constant")
stop
endif
'check valid series name for dep
if @len(%dep) = 0 then
@uiprompt("Please enter a series name for the dependent variable")
stop
endif
if @isobject(%dep) = 0 then
%msg = %dep + " is not a valid series in your workfile"
@uiprompt(%msg)
stop
endif
if {%dep}.@type <> "SERIES" then
%msg = %dep + " is not a valid series in your workfile"
@uiprompt(%msg)
stop
endif
'check valid regressors
if @len(%regs) = 0 then
@uiprompt("Please enter a list of regressors")
stop
endif
setmaxerrs 2
%gname = @getnextname("_g")
group {%gname} {%regs}
if @lasterrnum>0 then
d(noerr) {%gname}
@uiprompt( "Invalid list of regressors")
stop
endif
'check sample
smpl {%sample}
if @lasterrnum>0 then
d(noerr) {%gname}
@uiprompt( "Invalid sample")
smpl {%origsmpl}
stop
endif
%tab = "results"
if @isobject(%tab) then
%tab = @getnextname("results")
endif
table {%tab}
call ridgetab({%tab}, {%dep}, {%gname}, !l, %sample)
show {%tab}
smpl {%origsmpl}
d {%gname}
'on input tab should be the table to contain output. Y is the dependent variable, x is the group of regressors, lambda is the bias constant, and smplstr is the input text for the sample
subroutine local ridgetab(table tab, series y, group x, scalar !lambda, string %smplstr)
vector bcoef
vector bridge
!R2=0
vector vifs
series smplser = 1
call ridgereg(bcoef, bridge, vifs, !r2, y, x, !lambda, smplser)
%obs = @str(@obs(smplser))
!row=1
tab.setwidth(1) 19
tab.setwidth(2) 10
tab.setwidth(3:4) 11
%depstr = "Dependent Variable: " + @upper(y.@name)
tab(!row,1) = %depstr
tab.setjust(!row,1) left
!row = !row + 1
%title = "Ridge Regression"
tab(!row,1) = %title
tab.setjust(!row,1) left
!row = !row + 1
%datestring = "Date: " + @datestr(@now,"MM/DD/YY") + " Time: " + @datestr(@now,"HH:MI")
tab(!row,1) = %datestring
tab.setjust(!row,1) left
!row = !row + 1
%smpl = "Sample: " + %smplstr
tab(!row,1) = %smpl
tab.setjust(!row,1) left
!row = !row + 1
%ob = "Included observations: " + %obs
tab(!row,1) = %ob
tab.setjust(!row,1) left
!row = !row+1
%lambda = "Lambda: " + @str(!lambda)
tab(!row,1) = %lambda
tab.setjust(!row,1) left
!row = !row+1
tab.setlines(!row, a, !row, e) +d
!row = !row+1
tab(!row,1) = "Variable"
tab(!row,2) = "Raw Ridge"
tab(!row,3) = "Std. Ridge"
tab(!row,4) = "V.I.F"
!row = !row+1
tab.setlines(!row, a, !row, e) +d
!row = !row+1
for !i=2 to x.@count
%n = x.@seriesname(!i)
tab(!row,1) = %n
tab(!row,2) = bcoef(!i)
tab(!row,3) = bridge(!i-1)
tab(!row,4) = vifs(!i-1)
!row = !row+1
next
tab.setlines(!row, a, !row, e) +d
!row = !row+1
tab(!row,1) = "R-squared:"
tab.setjust(!row,1) left
tab(!row,2) = !r2
endsub