1

In my data set, I have several independent variables (here named "predictor1", "predictor2" etc.) and several dependent variables ("outcomeA", "outcomeB" etc). Furthermore, I have several covariates ("covariate1", "covariate2", etc.).

I want to do linear regression analysis, in which I

  • FIRST use predictor1 to predict all outcomes, while adjusting for covariate1.
  • THEN use predictor2 to predict all outcomes, while adjusting for covariate2.
  • THEN use predictor3 to predict all outcomes, while adjusting for covariate3. etc.

I know how to build a loop that will use predictor1 to predict all outcomes, then use predictor2 to predict all outcomes, etc. I also know how to add covariates that would be used for all models regardless of the predictor in question, but that's no use.

What I don't know is this: how to I "couple" covariates with predictors, so that when I predict the outcomes with predictor1, I will also adjust for covariate1? Then, when I predict the outcomes with predictor2, I will adjust for covariate2, etc.

Below here is my syntax for doing this so that all models include the same covariates. How do I change this so that SPSS will not use all these covariates for all models, but will choose them according to the independent variable? Can I build two lists for independent variables that the loop will go through (e.g. "!indepvars1" and "!indepvars2") or something similar, or what could I do?

Obviously, I have no experience in programming, and I just couldn't get it to work on my own. Perhaps the answer is obvious.

PRESERVE. 
SET TVARS NAMES. 
oms select tables
/destination format = sav 
               numbered = "Table_Number" 
               outfile = '\\ATKK\visit1_TEMP1.sav'
/if commands = ['regression'] 
               subtypes = ['Coefficients']
/tag = "reg".

*////////////////////.
DEFINE !regtest100 (indepvars=!charend ('/') /depvars=!CMDEND)
   !DO !depvar !IN (!depvars)
   !DO !indepvar !IN (!indepvars)
        regression 
 /STATISTICS COEFF OUTS CI(95) R ANOVA
           /dependent = !depvar
           /method = enter !indepvar covariate1 covariate2 covariate3.  
   !DOEND
   !DOEND
!ENDDEFINE.
*///////////////////

    !regtest100
     indepvars= predictor1 predictor2 predictor3.
   / depvars=   outcomeA outcomeB outcomeC.
    EXECUTE.
Peter O.
  • 32,158
  • 14
  • 82
  • 96
Sara S.
  • 23
  • 4

2 Answers2

1

There is multiple ways you can achieve this depending on how you expect your inputs to arrive.

Here below is one method, where both the regression and co-variate variables are provided as arguments to the macro parameters. The variable are paired together on their position. (You would expect the number of variables entered in the indepvars macro parameter and the covars parameter to be equal. I would build an explicit check for this to be thorough).

I've added notes in the macro body to explain some of the logic, which I hope may help.

*////////////////////.
define !RunJob1 (depvars=!charend ('/')  /indepvars=!charend ('/') /covars=!charend ('/'))

!do !dv !in (!depvars)
  !let !cv=!covars /* make copy of original list of variables */
  !do !iv !in (!indepvars)
      !let !cvhead=!head(!cv) /* retrieve first variable in list */
      !let !cv=!tail(!cv)     /* retrieve all but first variable in list */
      title !dv !iv !cvhead   /* print results as test */ .
  !doend
!doend

!enddefine.
*////////////////////.

!RunJob1 depvars=dv1 dv2 dv3 /indepvars=Apple Bananna Carrot /covars=A1 B2 C3.

Alternatively, if your input variables had a particular format where they had a predefined prefix stub followed by numeric suffix then you could approach this slightly differently which would also be somewhat easier to code. Again here is another example demonstrating this also:

*////////////////////.
define !RunJob2 (depvars=!charend ('/'))

!do !dv !in (!depvars)
  !let !cv=!covars
  !do !i = 1 !to 3
      title !dv !concat("iv", !i) !concat("cv",!i) .
  !doend
!doend

!enddefine.
*////////////////////.

!RunJob2 depvars=dv1 dv2 dv3.

Obviously many assumptions being made here. You'll have to assess your data to see what best suits your needs (if any or if something else may be more appropriate)

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jignesh Sutar
  • 2,909
  • 10
  • 13
1

With no experience in programming, it still took me a little while to apply the great advice, given here by Jignesh Sutar, into practice. Here's the final SPSS syntax, in case it helps others who really need script for dummies -type examples.

*////////////////////.
DEFINE 
    !regtest101 (depvars=!charend ('/')  /indepvars=!charend ('/') /covars=!charend ('/'))
    !DO !depvar !IN (!depvars)
    !let !cv=!covars 
    !DO !indepvar !IN (!indepvars)
    !let !cvhead=!head(!cv) 
    !let !cv=!tail(!cv)     
regression   
    /STATISTICS COEFF OUTS CI(95) R ANOVA
    /dependent = !depvar
    /method = enter !indepvar !cvhead extracovariateA extracovariateB. 
    !doend
!doend

!enddefine.
*////////////////////.

!regtest101
    depvars= outcomeA outcomeB outcomeC
    /indepvars= predictor1 predictor2 predictor3 
    /covars= covariate1 covariate2 covariate3.
EXECUTE.

The two extra covariates (extracovariateA, extracovariateB) are additional covariates that are included in all models, while covariate1, covariate2, and covariate3 are the ones that are added in consecutive models ("paired up" with predictor1, predictor2, predictor3).

Sara S.
  • 23
  • 4
  • Good to see you were able to adapt the code to your needs! Hope all the functions are clear but otherwise search them up in the documentation and study a few more example or simply put them to more use in future. Best way to learn! – Jignesh Sutar Jul 20 '15 at 09:54