1
$\begingroup$

I want to loop over a variable index to generate a regression model for each predictor. This is not possible with either loop or do repeat.

I have a set of predictors like var1_indep, var2_indep, var3_indep.and I would like to produce three regressions; one for each of the predictors.

loop # = 1 to 2.
regress /dependent my_dep_var /method=enter var_#_indep.
end loop.

However, the loop command is not valid for regression. Anyone knows if there is an alternative? Thanks in advance.

$\endgroup$
2
  • $\begingroup$ As the correct answer goes, you should use macro facility or (another option) python programmability. Loop command operates only on transformations of data cases, it cannot do cycling of procedures. $\endgroup$
    – ttnphns
    Aug 6 '20 at 21:28
  • $\begingroup$ To loop over prefixes in a macro, use !concat function within !do !v !in() cycle $\endgroup$
    – ttnphns
    Aug 6 '20 at 21:30
1
$\begingroup$

You can use a macro for this. See DEFINE in the documentation.

define regs()
    !do !i=1 !to 3.
        reg /dep my_dep_var /enter !concat('var_',!i,'_indep').
    !doend
!enddefine.

regs
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.