choosing lag value based on minimum aic for multiple regressors
Posted: Sat Oct 27, 2018 5:55 am
matrix(3,28) pv
matrix(3,28) coefs
matrix(3,28) tstats
vector(28) r2s
vector(28) aic
vector(28) rbar
'create empty equation to be used inside the loop
equation eq
!rowcounter=1
'variable to store the minimum AIC. Initialise it to a large number
!aic = 99999999
'variable saying how many lags to go up to
!maxlags = 5
'Variable to store the "best" number of lags
!bestlag = 0
'set sample to be the !maxlag'th value onwards
smpl @first+!maxlags @last
for !j=1 TO 28
eq.ls y!j X!jA X!jB c
for !i=1 to !maxlags
eq.ls y!j X!jA(1TO -!i) X!jB(1 TO -!i) c 'run regression of Y on a constant and lagged values UPTO MAX LAG of X1A AND X1B BOTH to the iTH lag.
if eq.@aic < !aic then
!bestlag = !i 'if this lag specification has the best AIC, then store this lag as !bestlag.
!aic = eq.@aic
!j= !bestlag
endif
next
colplace(coefs, eq!j.@coefs, !j)
colplace(tstats, eq!j.@tstats, !j)
r2s(!rowcounter) = eq!j.@r2
aic(!rowcounter) = eq!j.@aic
rbar(!rowcounter) = eq!j.@rbar2
!rowcounter = !rowcounter+1
matrix pvalue = @transpose(pv)
matrix coef = @transpose(coefs)
matrix tstat = @transpose(tstats)
next
i am writing this program to calculate aic for each x! regressors of y! .however it gives error.
i want program to run loop regression for respective yi to check for minimum aic for four lags of all respective xi(independent variables) by trying all possible combinations. the program should select equation having minimum aic and run the regression for respective yi .Then the loop runs again to perform same for yi=28 i.e 28 times and output selected regression results
But i think i couldnot do it for multiple regerros ON X SIDE.i want somebody to suggest , should i do rolling or i can do wit this type or someone can correct this
matrix(3,28) coefs
matrix(3,28) tstats
vector(28) r2s
vector(28) aic
vector(28) rbar
'create empty equation to be used inside the loop
equation eq
!rowcounter=1
'variable to store the minimum AIC. Initialise it to a large number
!aic = 99999999
'variable saying how many lags to go up to
!maxlags = 5
'Variable to store the "best" number of lags
!bestlag = 0
'set sample to be the !maxlag'th value onwards
smpl @first+!maxlags @last
for !j=1 TO 28
eq.ls y!j X!jA X!jB c
for !i=1 to !maxlags
eq.ls y!j X!jA(1TO -!i) X!jB(1 TO -!i) c 'run regression of Y on a constant and lagged values UPTO MAX LAG of X1A AND X1B BOTH to the iTH lag.
if eq.@aic < !aic then
!bestlag = !i 'if this lag specification has the best AIC, then store this lag as !bestlag.
!aic = eq.@aic
!j= !bestlag
endif
next
colplace(coefs, eq!j.@coefs, !j)
colplace(tstats, eq!j.@tstats, !j)
r2s(!rowcounter) = eq!j.@r2
aic(!rowcounter) = eq!j.@aic
rbar(!rowcounter) = eq!j.@rbar2
!rowcounter = !rowcounter+1
matrix pvalue = @transpose(pv)
matrix coef = @transpose(coefs)
matrix tstat = @transpose(tstats)
next
i am writing this program to calculate aic for each x! regressors of y! .however it gives error.
i want program to run loop regression for respective yi to check for minimum aic for four lags of all respective xi(independent variables) by trying all possible combinations. the program should select equation having minimum aic and run the regression for respective yi .Then the loop runs again to perform same for yi=28 i.e 28 times and output selected regression results
But i think i couldnot do it for multiple regerros ON X SIDE.i want somebody to suggest , should i do rolling or i can do wit this type or someone can correct this