Data editing > Data-mapped variables > Assigning values to data-mapped variables
 
Assigning values to data-mapped variables
One of the most powerful features of data-mapped variables is that you do not have to assign values to them. This is done automatically; as records are read, these variables are automatically initialized according to the data. All you have to do is to introduce the data-mapping file prior to reading data.
The data-mapping file will contain item definitions for fields contained in each data record. Where those item names match the name of a data-mapped variable, the variable is initialized as a data record is read. (Variables whose names do not correspond to any of the items in the map file will be cleared.) So, if you just want to analyze your data, introduce the map file at the beginning of your Quantum spec to define the variables, write your analysis specs using those variables, then introduce the map file again immediately before reading your data.
How it works
In the run file
In the data file
*usemap map_filename
*usemap map_filename
analysis specs
*include data_filename
If you have a second data file with a different mapping scheme, you would use:
In the run file
In the data file
*usemap map_filename1
*usemap map_filename1
analysis specs
*include data_filename1
 
*usemap map_filename2
 
*include data_filename2
You can see above how the Quantum run specifications do not change at all. You only need to introduce one of the maps in a Quantum specifications. This is because you are just using the map file to define the variables. If the same items exist in both files, you do not need to define them twice.
There are various reasons why you might explicitly assign values to data-mapped variables, so naturally you can set values into data-mapped variables. Below is a summary of how you can achieve this:
Assign a numerical value
You can assign the value of any numerical expression directly to a data-mapped variable as follows:
variable_name = arithmetic expression
For example:
q23 = t1 + 7
If the variable is either clear or already holds a numerical value, then the result of the arithmetic expression is stored as a numerical value.
If, however, the variable is already set to one or more categorical responses, then Quantum attempts to set the categorical response that corresponds to the result of the arithmetic expression. For example, if the result of the expression is 5, then Quantum sets the 5th categorical response and all other categorical responses are cleared. Looking at the categoric question:
Q.23 Which of these newspapers do you read regularly?
1. Times
2. Telegraph
3. Independent
4. Mail
5. Other
Y. Don't know
You then have a data-mapped variable called Q23. Typically, you would expect the variable to be tested for the exclusive response Mail as:
if (q23=$Mail$) ...
However, you can refer to it by its numeric value (that is, 4):
if (q23.eq.4) ...
So, if you wanted to explicitly set Q23 to be $Mail$, you can do it in one of two ways:
q23 = $Mail$
or
q23 = 4
However, since the variable is associated with a list of responses, the following gives a data error:
q23 = 7
This is because there is not a seventh response in the list. If, however, the variable were a true numeric type, this would be fine.
Assign a response
You can assign a specific response either by using the method for assigning a numerical value, or by using the following syntax:
variable_name = $response_text$
For example:
q1 = $Once a week$
If unique ID texts are defined for responses in the data-mapping file, you can assign a response using its unique ID text. The syntax for this is:
variable_name = $_(unique_ID_text)$
For example:
q1 = $_(Once a week)$
All previous responses assigned to the variable are cleared.
Copy the values from another data-mapped variable
You can assign the value(s) of one data-mapped variable to another data-mapped variable by specifying:
target_variable = source_variable
For example:
aware_copy = q23
If either the source variable or the target variable holds a numerical value, then the numerical value of the source variable is copied to the target variable. If this is not the case, then the categorical responses are copied.
Categorical responses are transferred by matching the text. This means that the target variable may not contain the same positional value for a response text as the source. For example, if the variable drank_most_recently contained the response texts:
$Coke$
$Pepsi$
then here the response text $Coke$ would be referenced as response number 1.
If, however, the variable drank_at_all contained the response texts:
$Pepsi$
$Coke$
then here, the response text $Coke$ could be referenced as response number 2. If a respondent had $Coke$ as the answer to drank_most_recently, then the statement:
drank_at_all = drank_most_recently
would result in both variables having the value $Coke$. This would, however, be response number 1 in drank_most_recently, but response number 2 in drank_at_all.
Collecting the logical OR of the responses from several data-mapped variables
If two or more variables contain categorical responses, then you use the OR function to assign the combination of all of the responses as follows:
target = OR(source1, source2 [, source3, ...])
For example:
all_tried = OR(tried_first, tried_second)
Responses are transferred over using the response text as described above. The following special responses are exclusive and can only appear in the absence of all other responses:
$_ref$
$_dk$
$_null$
$_na$
If an assignment results in a combination of any of these exclusive codes and one or more other responses, Quantum removes the exclusive special responses from the target variable. If an assignment results in more than one exclusive special response and no other responses, Quantum removes all but one of the exclusive special responses using a defined order of precedence. The order of precedence is $_ref$, $_dk$, $_null$, $_na$. So, if an assignment results in $_null$ and $_dk$, Quantum removes the $_null$ response and leaves the $_dk$.
Collecting the logical AND of the responses from several data-mapped variables
In a similar way to the OR function, you can use the AND function to collect only responses that appear on every one of the specified list of variables. You can assign the result to a variable as follows:
target = AND(source1, source2 [, source3, ...])
For example:
tried_both_times = AND(tried_first, tried_second)
As with the OR function, exclusive special responses are unset if they are not valid.
Collecting the logical XOR (exclusive OR) of the responses from several variables
Again, similar to the OR function, you can use XOR to collect responses that appear on only one variable of a specified list of variables. This means that if a response is not mentioned on any of the variables, it is not collected. In addition, if the same response is mentioned on two or more of the variables, that response will also not be collected. You can assign the result to a variable as follows:
target = XOR(source1, source2 [, source3, ...])
For example:
tried_once_only = XOR(tried_first, tried_second)
As with the OR function, exclusive special responses are unset if they are not valid.
See also
Data-mapped variables