LoopOverList

A loop creates multiple versions of a set of commands by iterating over a list of variables, numbers, or strings.

Properties

Name

Type

Description

Iterators

IteratorDescription

1..n

Describes one or more iteration processes in this loop.

Commands

CommandBase

1..n

Commands generated by the loop expanded by replacing tokens representing variables, numbers, or strings with their values.

Updated

boolean

0..1

When TRUE, the loop has been expanded into separate commands.

Properties Inherited from TransformBase

Name

Type

Description

ProducesDataframe

DataframeDescription

0..n

Signify the dataframe which this transform produces.

ConsumesDataframe

DataframeDescription

0..n

Signify the dataframe which this transform acts upon.

Properties Inherited from CommandBase

Name

Type

Description

Command

string

1..1

The type of command

SourceInformation

SourceInformation

0..n

Information about the source of the command.

MessageText

string

0..n

Adds a message that can be displayed with the command.

Item Type Hierarchy

Relationships

The following identified item types reference this type.

stub

Example_1_SPSS_LoopOverList

DO REPEAT existVar=firstVar TO var5
         /newVar=new1 TO new5
         /value=1 TO 5.
COMPUTE newVar=existVar*value.
END REPEAT.
{"Command": "LoopOverList",
      "sourceInformation": {
         "originalSourceText": "DO REPEAT existVar=firstVar TO var5
                                                     /newVar=new1 TO new5
                                                     /value=1 TO 5.
                                                     COMPUTE newVar=existVar*value.
                                                     END REPEAT."
                                                     },
"Iterators": [
    {"IteratorSymbolName": "existVar",
     "IteratorValues":
    {"$type":"VariableRangeExpression",
        "First": "firstVar",
        "Last": "var5"}
     },
    {"IteratorSymbolName": "newVar",
     "IteratorValues":
    {"$type": "VariableListExpression",
    "Variables": [
        {"$type":"VariableRangeExpression",
        "First": "new1",
        "Last": "new5"}
        ]
        }
    },
    {"IteratorSymbolName": "value",
     "IteratorValues":
    {"$type": "NumberListExpression",
    "Variables": [
        {"$type":"NumberRangeExpression",
        "From": "1",
        "To": "5",
        "By": "1"}
        ]
        }
    }
    ],
"IteratorCommands:" [
        {"Command": "compute",
        "VariableName":
                     {"$type": "IteratorSymbolExpression",  "IteratorSymbolName": "newVar"},
        "Expression":
             {"$type":"FunctionCallExpression",
                "Function": "Multiplication",
                "IsSDTLName":"True",
                "Arguments": [
                {"ArgumentName": "EXP1",
                "ArgumentValue":
                             {"$type": "IteratorSymbolExpression",
                             "IteratorSymbolName": "existVar"}
                             },
                {"ArgumentName": "EXP2",
                "ArgumentValue":
                             {"$type": "IteratorSymbolExpression",
                             "IteratorSymbolName": "value"}
                     }
                     ]
             }
             }
    ],
"Commands":[
********* Commands expanded in SDTL  here ************
     ]

}

Example_1_Stata_LoopOverList

foreach partyidk of varlist PARTYID1 PARTYID2 PARTYID3 {
    replace democrats=democrats+1 if `partyidk'==1
    }

{"Command": "LoopOverList",
      "sourceInformation": {
         "originalSourceText": "foreach partyidk of varlist PARTYID1 PARTYID2 PARTYID3 {
                                                             replace democrats=democrats+1 if `partyidk'==1 }"
                                                     },
"Iterators": [
             {"IteratorSymbolName": "partyidk",
             "IteratorValues":
                     {"$type": "VariableListExpression",
                     "Variables": [
                             {"$type":"VariableSymbolExpression", "VariableName": "PARTYID1" },
                             {"$type":"VariableSymbolExpression", "VariableName": "PARTYID2" },
                             {"$type":"VariableSymbolExpression", "VariableName": "PARTYID3" },
                             ]
                     }
     },
    ],
"IteratorCommands:" [
        {"Command": "compute",
        "VariableName":
                     {"$type": "VariableSymbolExpression",  "VariableName": "democrats"},
             "Expression":
             {"$type":"FunctionCallExpression",
                "Function": "Addition",
                "IsSDTLName":"True",
                "Arguments": [
                             {"ArgumentName": "EXP1",
                             "ArgumentValue":
                                     {"$type": "VariableSymbolExpression",  "VariableName": "democrats"}
                             },
                             {"ArgumentName": "EXP2",
                             "ArgumentValue":
                                             {"$type": "NumericConstantExpression", "Value": "1"}
                             }
                     ]
             },
             "Condition":
                     {"FunctionCallExpression":
                             {"$type":"FunctionCallExpression",
                "Function": "eq",
                "IsSDTLName":"True",
                "Arguments": [
                             {"ArgumentName": "EXP1",
                             "ArgumentValue":
                                     {"$type": "IteratorSymbolExpression",  "IteratorSymbolName": "partyidk"}
                             },
                             {"ArgumentName": "EXP2",
                             "ArgumentValue":
                                     {"$type": "NumericConstantExpression", "Value": "1"}
                             }
                     ]
             }
             }
    ],
"Commands":[
********* Commands expanded in SDTL  here ************
     ]
}

Example_2_SPSS_LoopOverList

LOOP #I=1 TO 5 IF (Y GT 10).
COMPUTE X=X+1.
END LOOP.

{"Command": "LoopOverList",
      "sourceInformation": {
         "originalSourceText": "LOOP #I=1 TO 5 IF (Y GT 10).
                                                             COMPUTE X=X+1.
                                                             END LOOP."
                                                     },
"Iterators": [
    {"IteratorSymbolName": "#I",
     "IteratorValues":
    {"$type": "NumberListExpression",
    "Values": [
        {"$type":"NumberRangeExpression",
        "From": "1",
        "To": "5",
        "By": "1"}
        ]
        }
    }
    ],
"IteratorCommands:" [
             {"Command": "DoIf",
             "Condition":
             {"$type":"FunctionCallExpression",
                "Function": "gt",
                "IsSDTLName":"True",
                "Arguments": [
                {"ArgumentName": "EXP1",
                "ArgumentValue":
                             {""$type": "VariableSymbolExpression",  "VariableName": "Y"}
                             },
                {"ArgumentName": "EXP2",
                "ArgumentValue":
                             {"$type": "NumericConstantExpression",
                             "Value": "10"}
                                     }
                                     ]
             "Commands": [

        {"Command": "compute",
        "VariableName":
                     {"$type": "VariableSymbolExpression",  "VariableName": "X"},
      "expression":
             {"$type":"FunctionCallExpression",
                "Function": "Addition",
                "IsSDTLName":"True",
                "Arguments": [
                {"ArgumentName": "EXP1",
                "ArgumentValue":
                             {""$type": "VariableSymbolExpression",  "VariableName": "X"}
                             },
                {"ArgumentName": "EXP2",
                "ArgumentValue":
                             {"$type": "NumericConstantExpression",
                             "Value": "1"}
                     }
                     ]
             }
             }
             ]

             ],
"Commands":[
********* Commands expanded in SDTL  here ************
     ]
}

Example_2_Stata_LoopOverList

forvalues k = 0/9  {
   replace idealfam=`k' if `k'==chldidel
    }

{"Command": "LoopOverList",
      "sourceInformation": {
         "originalSourceText": "forvalues k = 0/9  {
                                                             replace idealfam=`k' if `k'==chldidel }"
                                                     },
"Iterators": [
             {"IteratorSymbolName": "k",
             "IteratorValues":
                     {"$type": "NumberRangeExpression",
                             "From": "0",
                             "To": "9",
                             "By": "1"
                     }
     },
    ],
"IteratorCommands:" [
        {"Command": "compute",
        "VariableName":
                     {"$type": "VariableSymbolExpression",  "VariableName": "idealfam"},
             "Expression":
                     {"$type": "IteratorSymbolExpression",  "IteratorSymbolName": "k"}
             },
             "Condition":
                             {"$type":"FunctionCallExpression",
                             "Function": "eq",
                             "IsSDTLName":"True",
                             "Arguments": [
                                     {"ArgumentName": "EXP1",
                                     "ArgumentValue":
                                             {"$type": "VariableSymbolExpression",  "VariableName": "chldidel"}
                                     },
                                     {"ArgumentName": "EXP2",
                                     "ArgumentValue":
                                             {"$type": "IteratorSymbolExpression",  "IteratorSymbolName": "k"}
                                     }
                             ]
                             }

    ],
"Commands":[
********* Commands expanded in SDTL  here ************
     ]
}

Example_3_SPSS_LoopOverList

SET MXLOOPS 10
LOOP .
COMPUTE X=X+1.
END LOOP.

{"Command": "LoopOverList",
      "sourceInformation": {
         "originalSourceText": "SET MXLOOPS 10
                                                             LOOP .
                                                             COMPUTE X=X+1.
                                                             END LOOP."
                                                     },
"Iterators": [
    {"IteratorSymbolName": "",
     "IteratorValues":
    {"$type":"NumberRangeExpression",
        "From": "1",
        "To": "10",
        "By": "1"}
    }
    ],
"IteratorCommands:" [
        {"Command": "compute",
        "VariableName":
                     {"$type": "VariableSymbolExpression",  "VariableName": "X"},
      "expression":
             {"$type":"FunctionCallExpression",
                "Function": "Addition",
                "IsSDTLName":"True",
                "Arguments": [
                {"ArgumentName": "EXP1",
                "ArgumentValue":
                             {""$type": "VariableSymbolExpression",  "VariableName": "X"}
                             },
                {"ArgumentName": "EXP2",
                "ArgumentValue":
                             {"$type": "NumericConstantExpression",
                             "Value": "1"}
                     }
                     ]
             }
             }
             ],
"Commands":[
********* Commands expanded in SDTL  here ************
     ]
}