Adding or Changing Data

There are three tools that can be used to add or change data:

  • The Recode Data dialog that can be opened from the Table/Recode data menu item, and allows new columns to be added to the data table and the values in existing columns to be changed. This tool is described below.

  • The dialog that can be opened from the Table/Add unique row ID menu item. That dialog adds a column with a unique identifier for every row of the data table.

  • The dialog that can be opened from the Table/Add coordinate key menu item. That dialog adds a column with a unique identifier for every unique combination of latitude and longitude values.

The Table/Recode data menu item opens the following dialog.

The prompt for information needed to recode data

This dialog allows new values to be added in a new column or existing values to be changed. The changes can be applied to all data rows, only selected data rows, or only un-selected data rows. In addition, the changes may be applied only when the existing value is either missing or non-missing.

New values can be literal text or expressions that reference other columns in the table and that use SQL operators and functions.

The following items must be specified:

Data type

The type of expression result must be identified. It may be either a text string, a real (floating-point) number, or an integer. This choice is used to determine which existing columns may be selected, and is also used to check the validity of the expression that is used.

New or existing column name

Either an existing column name can be selected from the drop-down box, or a new column name can be entered. If an existing column name is used, values in that column will be replaced, and if a new column name is entered, that column will be added to the right-hand end of the table.

Values to replace

The two sets of three options determine which rows will have their value replaced. One set of options is used to specify whether, and how, previously selected (highlighted) rows in the table will determine which values are replaced. The other set of option is used to used to specify whether, and how, the replacements may be restricted to missing or non-missing values.

Expression

The expression to use to populate the column should be typed into the text area. The expression must be valid SQL. The expression may include column names, literal values, operators, and functions. Column names should contain only alphanumeric characters and underscores; any other character should be replaced with an underscore. String literals must be enclosed in single quotation marks. Operators and functions must be consistent with the SQLite dialect of SQL. The buttons to the left of the text entry area can be used to erase an existing expression, to read an expression from a file, to save the expression to a file, and to edit the expression if an external editor has been specified (with the File/Set editor menu command or in a configuration file).

After the desired specifications have been entered and the OK button pressed, the expression will be evaluated. If the expression is invalid, a warning message will be displayed and no data will be changed. If the expression is valid, the data table will be updated. Some specifications may be valid but result in no changes to data–for example, if the changes are to be made to empty rows only, and there are no empty rows, then nothing will be changed.

If a valid expression is used, then it will be saved and used to initialize the text entry area when this dialog is next opened. This provides some consistency when a sequence of similar changes are to be made.

A modified data table can be saved with the Table/Export selected and Table/Export all menu items.