Hi!
I’m new to gretl programming. Please, can anyone tell me why my code doesn’t recognize my
double loop. I don’t understand.
# a 14 de mayo de 2016
# función que genera la contribución de Shapley
include drop_majo.inp
include R2_majo.inp
function matrix shapley(matrix X "Variables explicativas",
matrix y "Variable dependiente")
scalar T=rows(X) #número de observaciones
scalar N=cols(X) #número de variables explicativas
scalar M=2^N #número de regresiones factibles
scalar M2=M-1
scalar N2=N-1
matrix Z = zeros(M,1)
matrix C = zeros(1,N)
loop k=0..M2
matrix Xs=X
loop for (i=N; i=1;i-=1)
if floor((k%(2^i))/2^(i-1))==0
matrix Xs=dropcol(Xs,i)
endif
endloop
matrix Z[k+1]=R2(Xs,y)
endloop
print Z
loop j=1..N
loop m=0..M2
if floor(m%(2^j)/2^(j-1))==0
matrix C[j]=C[j]+Z[m+1]
else
matrix C[j]=C[j]-Z[m+1]
endif
endloop
matrix C[j]=C[j]/(2^(N-1))
endloop
print C
end
Also, sometimes the console freezes. It doesn’t respond to anything I write, so I have to
constantly close Gretl.
Thanks!
María José
Enviado desde Correo para Windows 10