STATISTICA







STATISTICA BASIC Program FillSpecial.stb

{ The purpose of this program is to fill a variable in a datafile with a series such as 1,2,3,4,1,2,3,4,1,2,3,4... or 1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3... This procedure might often be useful when filling in codes for an analysis of variance, for example. The program accepts three parameters from the user: a start value, an end value and the number of repetitions for each value. The variable selected by the user is then filled with a series consisting of each integer from the start value to the end value, with each integer repeated as many times as specified by the user

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


randomaccess;

{let's user specify the variable to fill}
if(SelectVariables1 ("Please select a variable", 1, 1, VarList1, Count1, ?Text1$)) =0 then stop;

{user specifies start value}
startvalue := 1;
if (DisplayNumericInputBox ('Please enter a start value', 'START VALUE', startvalue)=0) then stop;

{error checking:  start value cannot be less than 1}
if (startvalue < 1) then
	begin
            DisplayMessageBox (MB_IconExclamation, 'Out of range', 'Start value is less than one');
	stop;
	end;

{user specifies end value}
endvalue := 5;
if (DisplayNumericInputBox ('Please enter an end value', 'END VALUE', endvalue)=0) then stop;

{error checking:  start value cannot be larger than the end value}
if (startvalue >= endvalue) then
	begin
            DisplayMessageBox (MB_IconExclamation, 'Parameters out of range', 'Start value is greater than or equal to end
value');
	stop;
	end;

{user specifies the number of repetitions of each value
e.g., with the series 1,1,1,2,2,2,... the number of repetitions is 3}
repeat := 1;
if (DisplayNumericInputBox ('Number of times for each value to repeat', 'REPETITIONS', repeat)=0) then stop;

{calculates how big the specified series is}
howmany := repeat * (endvalue - startvalue+1);

{error checking:  warns if the number of values in the specified series
is larger than the number of cases in the data file}
to_add := howmany-NCases;
warning$ := "Warning:  Add "+str(to_add,trunc(log10(to_add))+1,0)+ " more case(s)";
if howmany > NCases then
	DisplayMessageBox (MB_IconExclamation, warning$, 'The datafile does not have enough cases for the array
specified');

{if the number of values in the series is smaller than the number of
cases in the datafile, the number of times to repeat the fill is calculated}
num_times := NCases/howmany;
if not(NCases mod howmany=0) then
	num_times := num_times +1;

{array holding one copy of the series is created and filled}
redim series(howmany);
counter :=0;
for i:=1 to (howmany) do
	begin
	counter := counter +1;
		for ii:=0 to (repeat-1) do
			series(i+ii) := startvalue -1 +counter;
	i:= i+repeat-1;
	end;

{array is declared and filled with enough repetitions
of the above series to fill the variable}
redim matrix(NCases);
counter2 := 0;
for j:=1 to num_times do
	begin
	for k:=1 to howmany do
		begin
		if (k=howmany and not(j=num_times)) then
			k:=1;
		if counter2 < NCases then
			begin
			counter2 := counter2 +1;
			matrix(counter2) := series(k);
			end;
		end;
	end;

{variable is filled}
for iii:=1 to NCases do
	Data(iii,varlist1):=matrix(iii);

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.