I am writing an extension command for a custom dialog in Python. However I have troubles capturing the input variables from the UI of the CDB. The input variables are as following:
1. %%dep_variable%%
This is a single variable option for the dependent variable
2.%%indep_variable%%
This is a multiple variable option for the independent variables
This is the code for now. I'm printing the regression coefficients for the independent variables. However I am running into two problems:
1. The lines performing logistic regression cannot read %%dep_var%% or %%indep_var%%. Also not when I created variables(dep_var and indep_var_list) and put %%dep_var%% or %%indep_var%% between quotation marks. What am I doing wrong?
2. I am not able to iterate over %%indep_var%%, how should I transform %%indep_var%% so it is a list of the independent variables that I can iterate over?
BEGIN PROGRAM.
import spss,spssaux
dep_var="%%dep_var%%"
indep_var_list="%%indep_var%%"
cmd="LOGISTIC REGRESSION VARIABLES dep_var\
/METHOD=ENTER indep_var_list\
/CRITERIA=PIN(.05) POUT(.10) ITERATE(20) CUT(.5)."
handle,failcode=spssaux.CreateXMLOutput(
cmd,
omsid="LOGISTIC REGRESSION",
visible=False)
for i in indep_var_list:
result=spssaux.GetValuesFromXMLWorkspace(
handle,
tableSubtype="Variables in the Equation",
rowCategory= indep_var_list[i],
colCategory="B",
cellAttrib="text")
print "The coefficient is: ", result[0]
END PROGRAM
.
First, your cmd variable is inserting the literal names dep_var and indep_var_list. You need the values of those variables, so in the syntax they should be written as %%dep_var%% etc or the command should be written to use variable substitution, e.g.,
"""LOGISTIC ... VARIABLES %s ...""" % (dep_var ...)
Second, your indep_var_list variable is a single string, not a list. You would need to convert it first, e.g.,
indep_var_list = indep_var_list.split()