The following Expression computes penetration in c:\Program Files\Q\Examples\Panel.Q:
var brand = Q.GetValue('brand', 'Transactions.sav'); brand.length != 0
This is interpreted as follows:
- Q.GetValue('brand', 'Transactions.sav') gets, for each observation in the individual-level database, the data in the varable called brand in the situational database (i.e., Transactions.sav). As mentioned, this is an Array. For example, if the household had made four purchases, of brands 3, 2, 1 and 1, then [3,2,1,1] would be returned.
- var brand = assigns the array to a variable called brand. (A variable in this context is temporary and does not create a variable called brand in the Variables and Questions tab.)
- brand.length computes the length of the array stored in the variable called brand (i.e., the number of values separate by commas).
- brand.length != 0 returns a 1 if the length of the array contains at least one entry and a 0 otherwise (i.e., it is a logical expression and true is shown as 1 and false as 0).