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

This example uses the Access All Data Rows feature to work out the most recent month in the data, and then computes the difference, in months, of all other observations from this most recent point. For example, observations in the same calendar month are assigned a score of 0, those from the previous calendar month are assigned a value of 1, and so on. To use this code:

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.MonthDif(date_var[i], highest_date);
result

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