Access All Data Rows

From Q
Jump to navigation Jump to search

When Access All Data Rows is accessed in the JavaScript Variables dialog box all variables in the Variables and Questions tab are treated as Arrays. For example, when the option is not selected, a new JavaScript Variable containing the value of 1 would be created with the expression:


whereas when the option is checked the following expression is required:

var result = new Array();
for (var i = 0; i < N; i ++)
  result[i] = i;

Note that:

  • The first line creates a variable called result and assigns an empty array to it.
  • N is a reserved variable containing the number of observations in the data.
  • A Loop is being used to iterate through all the N values.
  • The final line returns the array that will become the the JavaScript Variable.

Similarly, if adding two variables, q3 and q4, rather than write q3 + q4 we need to write:

var result = new Array();
for (var i = 0; i < N; i ++)
  result[i] = q3[i] + q4[i];

See also

Computing A Variable Measuring Time Difference Since Last Interview