Search code examples
macrosspss

Comparing different results captured by OMS


Following up to a previous post Scale Building in SPSS, I'm trying to automate the scale building process using Cronbach's alpha and alpha-if-deleted. The manual process requires me to run a Reliability analysis, then check the alpha-if-deleted values to see which variables should be dropped from the scale. This can take several iterations, so I'm trying to automate it. Here's my syntax so far:

* Make sure output tables contain variable names only...

set onumbers values ovars names tnumbers values tvars names.

* OMS to capture the alpha coefficient

DATASET DECLARE  Alpha.
OMS
  /SELECT TABLES
  /IF COMMANDS=['Reliability'] SUBTYPES=['Reliability Statistics']
  /DESTINATION FORMAT=SAV NUMBERED=TableNumber_
   OUTFILE='Alpha' VIEWER=YES.

* OMS to capture the Item_totals.

DATASET DECLARE  Item_Totals.
OMS
  /SELECT TABLES
  /IF COMMANDS=['Reliability'] SUBTYPES=['Item Total Statistics']
  /DESTINATION FORMAT=SAV NUMBERED=TableNumber_
   OUTFILE='Item_Totals' VIEWER=YES.

* Running the reliability analysis

RELIABILITY
  /VARIABLES=Binary_12085 Binary_12213 Binary_18007 Binary_19829 Binary_19830 Binary_4451 
    Binary_4465 Binary_5140 Binary_5149 Binary_8513
  /SCALE('Original Scale') ALL
  /MODEL=ALPHA
  /SUMMARY=TOTAL. 

The next step is to compare the alpha value from the Alpha dataset (variable name: CronbachsAlpha) to the CronbachsAlphaifItemDeleted (in Item_Totals dataset), and select the values in Var1 (Item_Totals dataset) where CronbachsAlphaifItemDeleted <= CronbachsAlpha. Once I can capture that list from Var1, I hope to put it back into syntax to run the next Reliability analysis on those variables.


Solution

  • The following will create a macro which contains only the names of the variables that you specified.

    First, this will create some sample data and recreate the situation you described (using your syntax):

    data list free/Binary_12085 Binary_12213 Binary_18007 Binary_19829 Binary_19830 
        Binary_4451 Binary_4465 Binary_5140 Binary_5149 Binary_8513 (10f2).
    begin data
    1 0 1 0 1 1 1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 1 1 1 1 1 0 1 0 1 0 1 1 0 1 0 1 0
    end data.
    
    ***THE FOLLOWING IS A COPY OF THE SYNTAX IN THE ORIGINAL QUESTION.**
    
    * Make sure output tables contain variable names only...
    set onumbers values ovars names tnumbers values tvars names.
    * OMS to capture the alpha coefficient
    DATASET DECLARE  Alpha.
    OMS   /SELECT TABLES   /IF COMMANDS=['Reliability'] SUBTYPES=['Reliability Statistics']
      /DESTINATION FORMAT=SAV NUMBERED=TableNumber_    OUTFILE='Alpha' VIEWER=YES.
    * OMS to capture the Item_totals.
    DATASET DECLARE  Item_Totals.
    OMS   /SELECT TABLES   /IF COMMANDS=['Reliability'] SUBTYPES=['Item Total Statistics']
      /DESTINATION FORMAT=SAV NUMBERED=TableNumber_    OUTFILE='Item_Totals' VIEWER=YES.
    * Running the reliability analysis.
    RELIABILITY   /VARIABLES=Binary_12085 Binary_12213 Binary_18007 Binary_19829 Binary_19830 
    Binary_4451 Binary_4465 Binary_5140 Binary_5149 Binary_8513
      /SCALE('Original Scale') ALL   /MODEL=ALPHA  /SUMMARY=TOTAL. 
    omsend.
    

    Now we have two datasets with the two results. The following syntax matches them, selects the relevant variables to keep, and then creates a macro called !keepers that contains their names:

    match files/file=item_totals/table=alpha/by Command_ 
        /keep var1 CronbachsAlphaifItemDeleted CronbachsAlpha.
    select if CronbachsAlphaifItemDeleted <= CronbachsAlpha.
    flip newnames=var1.
    spssinc select variables macroname="!keepers"/PROPERTIES  PATTERN = "Binary_*".
    

    You can now use the variable list in your syntax, for example:

    frequency !keepers .