STATISTICA







STATISTICA BASIC Program StatsAcrossColulmns.stb

{ This program will calculate the user-specified statistic across the user-specified variables and place the result in a user-specified result variable. Missing values are excluded from the calculations similar to Block Stats for Rows, but the variables do not need to be consecutive. This program was intended to fill the need for sum, average, etc. functions that are not currently available as spreadsheet formulas.

Program written, modified, or edited at StatSoft, Inc.}


RandomAccess;
ReDim temp(NCases, NVars);
ReDim VarList1(NVars);
{select the variables to be included in the calculations}
if SelectVariables1 ('Select variables', 1, NVars, VarList1, Count1, 'Variables:')=0 then STOP;
{choose the statistic to be calculated}
if DisplaySelectionBox ('Select Statistic', 'Mean|Median|Standard Deviation|Standard Error|Variance|Sum|Valid
N|Minimum|Maximum|25%|75%',selected, 1)=0 then STOP;
{select the variable where the resulting values will be placed}
if SelectVariables1 ('Select a variable to contain resulting statistic', 1, 1, VarList2, Count2, 'Variable:')=0 then STOP;
{copy the variables to be included in the calculations into a new matrix}
for i:=1 to Count1 do
  MatrixCopy (Data, 1, VarList1(i), NCases, 1, temp, 1, i);

ReDim temp(NCases,Count1);
ReDim mymatrix(Count1, NCases);
ReDim stats(NCases,11);
{transpose the new matrix}
MatrixTranspose (temp, mymatrix);
ReDim vector(Count1);
Dim Quart(3);
{begin main loop}
for i:=1 to NCases do begin
    {extract each column ino a vector}
    MatrixExtract (mymatrix, 1, i, Count1, 1,vector);
    {calculate all statistics for given vector}
    stats(i,7):=ValCount(vector,1,Count1);
    if stats(i,7)=0 then begin
       stats(i,1):=Missing;
       stats(i,2):=Missing;
       stats(i,3):=Missing;
       stats(i,4):=Missing;
       stats(i,5):=Missing;
       stats(i,6):=Missing;
       stats(i,8):=Missing;
       stats(i,9):=Missing;
       stats(i,10):=Missing;
       stats(i,11):=Missing;
    end;
    ValSum (vector, 1, Count1, stats(i,6));
    stats(i,1):=stats(i,6)/stats(i,7);
    ValMedian (vector, 1, Count1, stats(i,2));
    ValStDeviation (vector, 1, Count1, stats(i,3));
    ValStError (vector, 1, Count1, stats(i,4));
    ValVariance (vector, 1, Count1, stats(i,5));
    ValMin (vector, 1, Count1, stats(i,8));
    ValMax (vector, 1, Count1, stats(i,9));
    Quart(1):=Missing;
    Quart(2):=Missing;
    Quart(3):=Missing;
    ValQuartiles (vector, 1, Count1, Quart);
    stats(i,10):=Quart(1);
    stats(i,11):=Quart(3);
end;
{end main loop}
{fill in resulting values into the specified result variable}
for i:=1 to NCases do
   Data(i,VarList2):=stats(i,selected);
Stop;

Back to List of Programs



[StatSoft]
2300 East 14th Street, Tulsa, OK 74104
Phone: (918) 749-1119; Fax: (918) 749-2217

[StatSoft]e-mail: info@statsoft.com

©Copyright StatSoft, Inc., 1984-2004.
StatSoft, StatSoft logo, STATISTICA, SEWSS, SEDAS, Data Miner, SEPATH and GTrees are trademarks of StatSoft, Inc.