Computing A Variable Measuring Time Difference Since Last Interview
Jump to navigation
Jump to search
Pages with syntax highlighting errors
Q Technical Reference
Q Technical Reference
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Setting Up Data > Tracking Studies (Longitudinal Data Analysis)
Q Technical Reference > Updating and Automation > JavaScript
User Interface > JavaScript Variables > JavaScript Variables Examples Library
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:
- Ensure that you have Access all data rows (advanced) selected.
- 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
Pages with syntax highlighting errors
Q Technical Reference
Q Technical Reference
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Setting Up Data > Tracking Studies (Longitudinal Data Analysis)
Q Technical Reference > Updating and Automation > JavaScript
User Interface > JavaScript Variables > JavaScript Variables Examples Library