Goto the Tip of the Month Archive Other interesting pages ... |
Lets say we have a dataset with variables A1, A2, A3, …., A20 and I want to find the average. We could write: avg=(a1+a2+a3+a4+…+a19+a20)/20; But this is inefficient and if any of the variables in the list are missing the variable AVG will be missing. We could then change it to: avg=MEAN(a1,a2,a3,a4,…,a19,a20); But writing out this list is tedious. Better is to use the OF statement and a list of the variables as shown below: avg=MEAN(OF a1-a20); Another way is to use an array, as the following example shows: array zaz{*} a1-20; avg=MEAN(OF zaz(*)); This example uses the MEAN function but the same idea of using the OF function can also be used for N, NMISS, STD, MIN, MAX, STDERR, MEDIAN, GEOMEAN, SUM, VAR, PCTL or the myriad of other descriptive statistic functions. Hope this was useful. |

________________________________ Updated July 2, 2015 |