How do I calculate (transform) values of a variable?

Spreadsheet formulas

To perform data transformation and recoding operations on single variables using one formula (as opposed to a set of transformation formulas), you can use the data spreadsheet formulas.

Double-click on the variable name in a spreadsheet variable that you want to transform to display the Variable specifications dialog box where a data transformation or recoding formula can be entered directly into the Long name (label or formula with Functions) box.

Following the Windows spreadsheet formula conventions (e.g., Microsoft Excel), start the formula with an "=" sign (otherwise Statistica will not recognize that the text is to be interpreted as a formula). For example, enter =(v1+v2)/2. Variables can be referenced by their names (e.g., Income, profit, TEST1) or numbers (e.g., v1, v2, v3, ...); v0 is the case number. Logical operators can be used to define conditional transformation expressions (such as, = ScoreA + ScoreB).

Note: <, <=, >, >=, and <> can be used to specify logical conditions.

Variable names can include special characters (such as spaces, plus or minus signs). Variable names that include special characters must be enclosed in quotation marks (e.g., = 'Score A' + 'Score B' ). If a quotation mark itself occurs in the variable name, use double quotation marks instead (such as, = "A's Score" + "B's Score" ).

If double quotation marks are used in the name, then the variable name must be enclosed in single quotation marks.

Following the logic of the concept of missing data, the formula will evaluate to missing data if any variable used in the formula is missing. However, several functions are supported that calculate specific statistics for ranges and/or lists of data "adjusting" for missing values.

For example, the formula = mean (v1:v5, v7, sqrt(v9), TIME) will calculate the mean of variables v1, v2, v3, v4, v5, v7, square root of v9, and variable TIME, even if some of them may have missing values.

 

Click the Functions button in the Variable specifications dialog box to access the Functions Browser facility that can be used to select functions and other elements of the syntax (for the formulas) and insert them into the formula editor.

 

The Function Browser also is used to quickly access information on any of the functions and the complete on-line syntax documentation.

  1. Enter a formula
  2. Clicking the OK button in the Variable specifications dialog box
  3. You are given the option to recalculate the variable now.

If you choose not to recalculate at this time, you can do so later by:

  1. Select the Data tab.
  2. In the Transformations group, click Recalculate to display the Recalculate Spreadsheet Formulas dialog box.

Batch Transformation formulas

The same types of transformations described under Spreadsheet formulas can be applied in batch using the Batch Transformation Formulas dialog box. To access this dialog box:

  1. Select the Data tab. In the Transformations group.
  2. Click Transforms.

Use the options in the Batch Transformation Formulas dialog box to specify a list of transformation formulas involving any of the variables; these transformations are evaluated in sequence, one by one. These options are particularly well suited (optimized) for transforming large data sets, because 1) All transformation formulas are evaluated case by case in a single pass through the data, and 2) any variable names or references on the left sides of equations that cannot be matched with variable names in the current data file can automatically be created as the transformation formulas are evaluated.

Otherwise, the only differences in syntax between the Batch Transformation formulas and the Spreadsheet formulas is the support for multiple formulas in the Batch option, and also the fact that because the Batch formulas are not attached to any specific variable (in fact they can be freely copied from data file to data file), they cannot start with an equal sign, but must have a target variable (for example,, v1=... or Measure03=...) so that Statistica knows to which variable each formula should apply. There is also an option to distribute all Batch formulas into the respective variables in the spreadsheet and save them there with the data file, effectively replacing the Spreadsheet formulas (if there are any).

The Statistica Visual Basic programming language

If you need to write more complex data transformation programs than those that can be entered via spreadsheet formulas, the integrated programming language Statistica Visual Basic (SVB) can be used.

The industry standard Statistica Visual Basic language offers incomparably more than just a supplementary application programming language that can be used to write custom extensions. SVB takes full advantage of the object model architecture of Statistica and enables you to access programmatically every aspect and virtually every detail of the functionality of the program. SVB adds an arsenal of more than 11,000 new functions to the standard comprehensive syntax of Microsoft Visual Basic, thus comprising one of the largest and richest development environments available.

Statistica Visual Basic programs can be executed from within Statistica , but because of the industry standard compatibility of SVB, you can also execute its programs from any other compatible environment (such as MS Excel, MS Word, or a stand-alone Visual Basic language).

The Statistica Visual Basic environment includes a flexible program editor and powerful debugging tools.

To display the Statistica Visual Basic editor

  1. Select New from the File menu to display the Create New Document dialog box.
  2. Select the Macro (SVB) Program tab.
  3. Click the OK button.

When editing macro programs by typing in general Visual Basic commands or program commands specific to Statistica Visual Basic, the editor displays type-ahead help to illustrate the appropriate syntax.

Help on the members and functions for each class (object) is also provided in-line.

You can access examples and concise syntax summaries by pressing the F1 key. To learn more about a particular Visual Basic function

  1. Select the function in the Statistica Visual Basic editor.
  2. Press F1 on your keyboard.

This calla the Interactive Syntax Help Engine and displays the help for that keyword.

When executing a program, you can set breakpoints in the program, step through line by line, and observe and change the values of variables in the macro program as it is running.

To summarize, Statistica Visual Basic is not only a powerful programming language, but it represents a very powerful professional programming environment for developing simple macros as well as complex custom applications. For more information, refer to Statistica Visual Basic.