If there is a need to create many related binary variables using JavaScript, **Use as Template for Replication** uses an existing JavaScript Variable as a template for creating a new variable. Each new numeric variable uses the same expression as the template, but replaces the original variable references with the next available variable in the same question. The variables' questions that are referred to in the template's expression must have the same number of variables (or, they may have just one variable, which is used as a constant).

## Method

To automatically construct a set of variables, you:

- Construct a single variable to serve as a template and press
**OK**. - Right-click on the variable and select
**Insert Ready-Made Formula(s) > Use as Template for Replication**. - The
**Template Replication**dialog box will appear, showing you how the variable is to be used as a template. The first column shows us the variables that will be created. Note that in the example below Q has correctly guessed the variable labels and has used the**Name**of the template variable as the base for constructing the new names. If the variable you have selected is not appropriate as a template, you will receive an error message. - Press
**OK**and a new question is created beneath the template variable. You can then delete the template variable and, in this case, delete the last three variables of the newly created question (i.e., the two “other” variables and the “don’t know” variable).

## Example

Consider two Number - Multi questions, `Hours spent` and `Minutes spent`, comprised of the following variables:

**Hours spent**

- q1a: Hours spent eating
- q1b: Hours spent watching TV
- q1c: Hours spent talking

**Minutes spent**

- q2a: Minutes spent eating
- q2b: Minutes spent watching TV
- q2c: Minutes spent talking

We wish to view the total time spent doing each task - a combination of Hours spent and Minutes spent - in hourly terms. So, we construct a numeric variable that does this for the first variable in both questions. We call it "Time spent eating." Its expression is:

`q1a + q2a/60`

We can now use this variable as a template to construct numeric variables that accomplish the same calculation for the remaining variables in both questions. We use the Template Replication feature on the `Time spent eating` variable, and finally end up with a new question, with three variables:

**Time**

- Time spent eating [
`q1a + q2a/60`] - Time spent watching TV [
`q1b + q2b/60`] - Time spent talking [
`q1c q2c/60`]

## Next