Creating an index
How to create an index
An index is a class of variable used to identify a dimension of an array. The same index can identify the same dimension shared by many arrays. Sometimes, variables of other classes, such as a decision, can also be used as an index to identify a dimension of an array. For clarity, use an index variable whenever possible.
You create an index much like any other variable:
- Select the edit tool and open a Diagram window.
- Drag the parallelogram shape from the node palette to the diagram.
- Type a title into the new index node.
- Open the definition attribute for the new index:
- Press the expr menu above the definition field, to see these options.
(If the variable already has a definition, Analytica confirms that you wish to replace it. Click OK to replace the definition with a one-element list.)
- Select List (of numbers) or List of Labels according to whether you want to enter a list of numbers or text values. It will display a list with one item in the definition field.
- Click the cell to select it, and Type in a number for List or text for List of Labels.
- Press Enter or down-arrow to add a cell for the next item. Type in its value.
- Repeat until you have entered all the values you want.
Autofill a list: It gives the first cell of a list the default value of 1 (or the previous definition if it had one). When you press Enter or down-arrow, it adds a cell adding 1, or the increment between the two preceding cells, to the value of the preceding cell.
Expression view: You can display a list or list of labels as a list view, the default view showing as a column of cells, or as an expression view, showing it as a list of items between square brackets. Select from the toolbar to show the expression view. For example, here is a list of numbers in each view.
List of labels: In a list of labels, every value is text. In the expression view, each label is enclosed in single quotation marks.
To include a single quote (apostrophe) as part of the text in a label in expression view, insert two adjacent single quotes, or enclose in double quotes:
Mixing numbers and text: A list can include a mix of text and numbers. In both views the text is contained in single quotation marks as shown below.
If you attempt to mix numbers and text in a list of labels, all the values are treated as text, as shown below.
Editing a list
You can edit a list by changing, adding, or deleting cells (list items).
Insert a cell: To insert a cell anywhere other than at the end of the list, select a cell and choose Insert Rows (Control+i) from the Edit menu. The value in the selected cell is duplicated in the new cell.
To add a cell at the end of the list, select the last cell and press Enter or the down-arrow key.
To insert several contiguous cells in the middle of the list, select the number of cells you want to insert and choose Insert Rows (Control+i) from the Edit menu. It duplicates the value of the last selected cell as the default for the new cells.
Delete a cell: To delete one or more contiguous cells, select them and:
- Choose Delete Rows from the Edit menu.
- Or, just press Control+k or Backspace.
Navigating a list: Use the up and down-arrow keys to move the cursor up and down the list, or simply click the cell you want.
Defining an index as a sequence
After entering the Start, End, and Stepsize values, click OK; the definition field shows the Sequence button with its parameters.
To define an index as a sequence of successive integers, you can use the Sequence operator “..” in the expression view, for example:
Index Year := 2000 .. 2012
- Tutorial: Creating an index variable
- Tutorial: Arrays
- Local Indexes
- Expression Assist