Computing A Variable Measuring Time Difference Since Last Interview

From Q
Jump to navigation Jump to search

This example uses the Access All Data Rows feature to work out the most recent date in the data, and then computes the difference, in days, of all other observations from this most recent point.

To run this example:

  1. Ensure that you have Access all data rows (advanced) selected.
  2. In the first line of the Expression, Replace CreatedOn_date with the name of the Date variable in your data file.
var date_var = CreatedOn_date;
// finding highest date
var highest_date = 0;
for (var i = 0; i < N; i++) {
  var cur_date = date_var[i];
  if(cur_date > highest_date)
      highest_date = cur_date; 
}
// Computing month difference
var result = new Array(N); //declaring an array to hold the results
for (var i = 0; i < N; i++)
    result[i] =  Q.DayDif(date_var[i], highest_date); 
result

The resulting question should be set to a Question Type of Pick One.

See also

Computing A Variable Measuring Time Difference in Calendar Months Since Last Interview