I need to run two loops through my regression, one of them being the independent variable and the other is a suffix for the prediction I need to save with each round of independent variables. I can do either of these loops separately and it works fine but not when I combine them in the same regression. I think this has something to do with the loop mapping at the end of my regression after the %. I get the error code "TypeError: list indices must be integers, not str." But, that is because my Dependent variables are read as strings to get the values from SPSS data frame. Any way to map a for loop in a regression that includes string variables?
I have tried using the map() function, but I got the code that the iteration is not supported.
begin program.
import spss,spssaux
dependent = ['dv1', 'dv2', 'dv3', 'dv4', 'dv5']
spssSyntax = ''
depList = spssaux.VariableDict(caseless = True).expand(dependent)
varSuffix = [1,2,3,4,5]
for dep in depList:
for var in varSuffix:
spssSyntax += '''
REGRESSION
/MISSING LISTWISE
/STATISTICS COEFF OUTS R
/CRITERIA=PIN(.05) POUT(.10)
/NOORIGIN
/DEPENDENT %(dep)s
/METHOD=FORWARD iv1 iv2 iv3
/SAVE PRED(PRE_%(var)d).
'''%(depList[dep],varSuffix[var])
end program.
I get the error code 'TypeError: list indices must be integers, not str' with the code above. How do I map the loop while also including a string?