I'm currently working on creating a program which essentially will provide me with a way of doing a stepwise elimination of insignificant variables in a system of equations. This system of equations is in turn generated from a VAR model, so what I want in the end is a restricted VAR. The problem I have is how to code the actual elimination part. I found a great code for stepwise regression in a guide on this board and implemented it in my analysis, but I can't seem to figure this bit out. The code looks like this:
Code: Select all
'lag for endogenous variables
!i = 4
'lag for exogenous variables
!j = 3
'define the t-value cut-off point (absolute value)
!tstop=1.6449
!stop=0
'estimate VAR(!i,!j)
var var_e.ls 1 !i dr ldkpi tbill @ c usatbill(-1 to -!j)
'make a system of the estimated VAR
var_e.makesystem(n=sys_e)
'estimate system
sys_e.ls
'create a variable to store the smallest t-value in
!mint=10000
'create a variable to store the id of the variable showing the smallest t-value
!removedvar=0
'create a while condition
while !stop=0
'create loop from C(1) to C(LAST)
for !i=1 to sys_e.@ncoefs
!currentt = @abs(sys_e.@tstats(!i)) '!currentt is the absolute value of the t-statistic for coefficient i
if !currentt < !mint then
!mint = !currentt
!removedvar=!i
endif 'if the absolute t-value for coefficient i is smaller than the current smallest t-value the coefficient id is stored in !removedvar
next
if !mint>!tstop then 'when the smallest t-value is larger than the cut-off point this assigns 1 to !stop, which will terminate the while loop
!stop=1
else
sys_e.@coefs(!removedvar)=0 '!removedvar is equal to the coefficient, which currently has the lowest t-value and this statement should drop it from the system equation
endif
wend
Thanks in advance!
