STATISTICA







STATISTICA BASIC Program Value Stats.stb

{ This program was written to provide the unique values in a variable, any associated text values, and some basic descriptive statistics for that variable. It is similar to the Values/Stats option available from the Quick Stats Graphs flying menu, accessible by right-clicking in a data file.

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


randomaccess;

{variable selection}
if (SelectVariables1 ("Values of a variable", 1, 1, VarList1, Count1, "Please select a variable"))=0 then abort;


{array to hold the values of a variable}
redim values(NCases);

{read in the variables values into the above array}
for i:= 1 to NCases do
	Values(i) := Data(i,Varlist1);

{sort the values in the array}
VectorSort (values, sort_ascending);

{initialize array to hold unique values in variable}
redim results(1,2);

{counter to count how many unique values are in the variable}
howmany :=1;

{loop to check uniqueness of values in variable and if so put them into the results array}
for counter := 1 to Ncases do
begin
if counter =1 then
	begin
	results(counter,1) := values(counter);
	end;
if not(counter = 1) then
	begin
	if not(values(counter) = values(counter-1)) then
		begin
		howmany := howmany +1;
		redim results(howmany,2);
		results(howmany,1) := values(counter);
		end;
	end;
end;

{show the results}
header$ := "Unique values and text values of " + Varname(varlist1);
handle := NewScrollsheet (howmany, 2, results, header$, ?RowNames$, "Unique Values|Text Values");


{takes care of text values}

for j:=1 to howmany do
	ScrollsheetSetTextValue (Handle, j, 2, GetText(varlist1, results(j,1)));

{neatening up the scrollsheet}
ScrollsheetSetColumnName (Handle, 1, "Unique Values", Varname(varlist1));
ScrollsheetSetColumnName (Handle, 2, "Text values", Varname(varlist1));

{add some descriptives}
variable$ := varname(varlist1);
redim vector(NCases);
MatrixGetColumn (Data, varlist1, Vector);
countvalid := 0;
for a:=1 to NCases do
begin
	if valid(vector(a)) then
		countvalid := countvalid+1;
end;
ValMean (vector, 1, ?HowMany, mean);
ValStDeviation (vector, 1, ?HowMany, std);
ScrollsheetAppendRows (Handle, 3);
ScrollsheetSetValue (Handle, howmany+1, 1, mean);
ScrollsheetSetValue (Handle, howmany+2, 1, std);
ScrollsheetSetValue (Handle, howmany+3, 1, countvalid);
ScrollsheetSetRowNameWidth (Handle, 8);
ScrollsheetSetRowName (Handle, howmany+1, "Mean");
ScrollsheetSetRowName (Handle, howmany+2, "Std Dev");
ScrollsheetSetRowName (Handle, howmany+3, "Valid N");
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.