{ This Program is mainly used for survey analysis. Its purpose is to give a graphical representation of how a company performs for the specified factors in relation to a template graph. That is a template graph is created with the specified factors from the questionnaire and then this program calls the template graph and then overlays the respective company information retrieved from the questionnaire. This program should be used with the STATISTICA BASIC program, GraphTemp.stb, and the downloadable sample data file, surveyfactors.sta. You will first run GraphTemp.stb, then open surveyfactors.sta and run SurveyFactors.stb.
Program written, modified, or edited at StatSoft Pacific}
RandomAccess;
NoDataFileVariableNames;
{##################################################################
FUNCTIONS
###################################################################}
Recode MY_RECOD;
begin
1 = 7;
2 = 6;
3 = 5;
4 = 4;
5 = 3;
6 = 2;
7 = 1;
else missing;
end;
{###################################################################
PROGRAM
###################################################################}
DisplayMessageBox(MB_OK+MB_iconinformation,'Data Manipulation', 'This program will identify any values greater than 7
and then recode the dataset. It will calculate the normalised factors and then plot them on the template graph in a form of a
line plot with their respective ranges.');
ReDim x(Ncases,nvars);
ReDim xvar(Nvars);
Dim Results(1,8);
{Select the questions to be analysed}
if (SelectVariables1('Select Variables to Process', 3, NVars, xvar, Count1, 'Value')=0) then stop;
begin
{Filtering process, if the scale used does not contain a scale with maximum value 7, the
highlighted number should be replaced with the maximum value in your survey}
for i:=1 to ncases do
begin
for j:=1 to count1 do
begin
if data(i,j)>7 then
read(data(i,xvar(j)));
x(i,xvar(j)):=data(i,xvar(j));
end;
end;
{The recoding function is called here to recode the reversed scored questions in your
survey. These need to be adjusted to suit the users questionnaire. So for example if
recoding is required, use the format below.}
For i:=1 to ncases do
begin
x(i,6) := my_recod(x(i,6)); {q6}
x(i,18) := my_recod(x(i,18)); {q18}
x(i,21) := my_recod(x(i,21)); {q21}
x(i,36) := my_recod(x(i,36)); {q36}
x(i,14) := my_recod(x(i,14)); {q14}
x(i,10) := my_recod(x(i,10)); {q10}
x(i,22) := my_recod(x(i,22)); {q22}
x(i,25) := my_recod(x(i,25)); {q25}
x(i,37) := my_recod(x(i,37)); {q37}
x(i,40) := my_recod(x(i,40)); {q40}
x(i,46) := my_recod(x(i,46)); {q46}
end;
end;
{In this next section we replace the missing cells with the median value for a given
question}
ReDim p(Ncases,1);
ReDim q(Ncases,nvars);
redim mediansample(nvars,1);
a:=1;
for i:= 1 to nvars do
begin
for j:=1 to NCases do
begin
if SelectionConditions(j)=1 then
p(j,1):=x(j,i)
else
p(j,1):=Missing;
end;
valmedian(p,1,ncases,median);
for j:=1 to NCases do
begin
if not valid(p(j,1)) then
p(j,1):=median
else
p(j,1):=x(j,i);
end;
mediansample(a,1):=median;
for j:=1 to ncases do
begin
q(j,i):=p(j,1);
end;
a:=a+1;
end;
varname$:=varname(1);
for i:=2 to nvars do
varname$:=varname$+ '|' + varname(i);
{Scrollsheet given below is the recoded data with missing cells replaced}
scr1:=NewScrollsheet (-1,-1, q, 'Recoded Data', '',varname$);
for i:=1 to count1 do
begin
ScrollsheetSetColumnFormat(scr1,i,scf_decimal,1);
end;
FileName$:='c:\.sta'; {This file location needs to be changed}
If DisplayInputBox('Title of File','File Name:',FileName$) then
SaveScrollsheetAsDataFile (scr1, FileName$);
{###########################################################################
Calculates the normalised factors
###########################################################################}
{Groups the factors together for each response}
ReDim Factor(ncases,count1/3);
for i:=1 to ncases do
begin
for j:=1 to count1/3 do
begin
factor(i,j):=q(i,3*j-2)+q(i,3*j-1)+q(i,3*j); {factors are a grouping of three
successive questions}
end;
end;
{####################################################
Normalise the data so that it is of scale 10.
####################################################}
ReDim y(ncases,1);
begin
ReDim mse(count1/3,2);
a:=1;
for i:= 1 to Count1/3 do
begin
for j:=1 to NCases do
begin
if SelectionConditions(j)=1 then
y(j,1):=factor(j,i)
else
y(j,1):=Missing;
end;
for j:=1 to NCases do
begin
if y(j,1)>0 then
y(j,1):=y(j,1);
end;
valmean(y,1,ncases,mean1); {Calculate the mean for each factor}
ValStError (y, 1, ncases, se1); {Calculate the standard error for each factor}
mse(a,1):=mean1;
mse(a,2):=se1;
a:=a+1;
end;
end;
{The mean and standard errors of all factors are normalised and then placed into the
array normmse}
ReDim normmse(count1/3,4); {Normalised factors}
{Divide mean and s.e. by 2.1 to normalise the data to a 10 point scale. Therefore if different scales need to be used adjust
the following with respect to the 2.1 value below}
for i:=1 to count1/3 do
begin
normmse(i,1):=mse(i,1)/2.1; {NORMALISED MEAN}
normmse(i,2):=mse(i,2)/2.1; {NORMALISED S.E.}
normmse(i,3):=normmse(i,1)+normmse(i,2); {MEAN + S.E.}
normmse(i,4):=normmse(i,1)-normmse(i,2); {MEAN - S.E.}
end;
{Replace the FACTOR NAME by preferred factor}
Name1$:='FACTOR NAME1';
Name2$:='FACTOR NAME2';
Name3$:='FACTOR NAME3';
Name4$:='FACTOR NAME4';
Name5$:='FACTOR NAME5';
Name6$:='FACTOR NAME6';
Name7$:='FACTOR NAME7';
Name8$:='FACTOR NAME8';
Name9$:='FACTOR NAME9';
Name10$:='FACTOR NAME10';
Name11$:='FACTOR NAME11';
Name12$:='FACTOR NAME12';
Name13$:='FACTOR NAME13';
Name14$:='FACTOR NAME14';
Name15$:='FACTOR NAME15';
Name16$:='FACTOR NAME16';
Name17$:='FACTOR NAME17';
{The scrollsheet below gives the total factor score for each individual, this can be saved
so that further analysis can be performed}
fact:=NewScrollsheet(-1,-1,factor,'Factor Scores','','');
ScrollSheetSetColumnWidth(fact,30,-1);
for i:=1 to count1/3 do
begin
ScrollsheetSetColumnFormat(fact,i,scf_decimal,1);
end;
{Place factor names in the scrollsheet, replace the integer values below to place the text in the correct position}
ScrollsheetSetColumnName (fact,1,Name1$,'');
ScrollsheetSetColumnName (fact,2,Name2$,'');
ScrollsheetSetColumnName (fact,3,Name3$,'');
ScrollsheetSetColumnName (fact,4,Name4$,'');
ScrollsheetSetColumnName (fact,5,Name5$,'');
ScrollsheetSetColumnName (fact,6,Name6$,'');
ScrollsheetSetColumnName (fact,7,Name7$,'');
ScrollsheetSetColumnName (fact,8,Name8$,'');
ScrollsheetSetColumnName (fact,9,Name9$,'');
ScrollsheetSetColumnName (fact,10,Name10$,'');
ScrollsheetSetColumnName (fact,11,Name11$,'');
ScrollsheetSetColumnName (fact,12,Name12$,'');
ScrollsheetSetColumnName (fact,13,Name13$,'');
ScrollsheetSetColumnName (fact,14,Name14$,'');
ScrollsheetSetColumnName (fact,15,Name15$,'');
ScrollsheetSetColumnName (fact,16,Name16$,'');
ScrollsheetSetColumnName (fact,17,Name17$,'');
FileName10$:='c:\.sta'; {This file location needs to be changed}
If DisplayInputBox('Title of File','File Name:',FileName10$) then
SaveScrollsheetAsDataFile (fact, FileName10$);
{This scrollsheet gives the normalised means and s.e. with upper and lower limits}
dbl:=NewScrollsheet(-1,-1,normmse, 'Normalised Factors', '','Mean|SE|Upper|Lower');
ScrollSheetSetRowNameWidth(dbl,30);
{Places the factor name in each row for the above scrollsheet, replace integer value}
ScrollsheetSetRowName (dbl,1,Name1$);
ScrollsheetSetRowName (dbl,2,Name2$);
ScrollsheetSetRowName (dbl,3,Name3$);
ScrollsheetSetRowName (dbl,4,Name4$);
ScrollsheetSetRowName (dbl,5,Name5$);
ScrollsheetSetRowName (dbl,6,Name6$);
ScrollsheetSetRowName (dbl,7,Name7$);
ScrollsheetSetRowName (dbl,8,Name8$);
ScrollsheetSetRowName (dbl,9,Name9$);
ScrollsheetSetRowName (dbl,10,Name10$);
ScrollsheetSetRowName (dbl,11,Name11$);
ScrollsheetSetRowName (dbl,12,Name12$);
ScrollsheetSetRowName (dbl,13,Name13$);
ScrollsheetSetRowName (dbl,14,Name14$);
ScrollsheetSetRowName (dbl,15,Name15$);
ScrollsheetSetRowName (dbl,16,Name16$);
ScrollsheetSetRowName (dbl,17,Name17$);
FileName1$:='c:\.sta'; {This file location needs to be changed}
If DisplayInputBox('Title of File','File Name:',FileName1$) then
SaveScrollsheetAsDataFile (dbl, FileName1$);
{#######################################################
Arranging factors for the plot
#######################################################}
redim zdata(count1/3,1); {ARRAY OF NORMALIED MEAN VALUES OF FACTORS}
redim upper(count1/3,1); {ARRAY OF MEAN + S.E.}
redim lower(count1/3,1); {ARRAY OF MEAN - S.E.}
redim nofact(count1/3,1); {ARRAY OF NUMBER OF FACTORS}
{Group the factors into there respective categories, i.e., the first group contains factors
1,2,3 and 4, second group contains factors 5,6,7 and 8, third group contains factors
9,10,11,12 and 13 and the fourth group contains factors 14,15,16 and 17}
zdata(1,1):=normmse(1,1); {Changes are made after ':='}
zdata(2,1):=normmse(2,1);
zdata(3,1):=normmse(3,1);
zdata(4,1):=normmse(4,1);
zdata(5,1):=normmse(5,1);
zdata(6,1):=normmse(6,1);
zdata(7,1):=normmse(7,1);
zdata(8,1):=normmse(8,1);
zdata(9,1):=normmse(9,1);
zdata(10,1):=normmse(10,1);
zdata(11,1):=normmse(11,1);
zdata(12,1):=normmse(12,1);
zdata(13,1):=normmse(13,1);
zdata(14,1):=normmse(14,1);
zdata(15,1):=normmse(15,1);
zdata(16,1):=normmse(16,1);
zdata(17,1):=normmse(17,1);
{Repeat the same procedure as above for the upper and lower
variables}
upper(1,1):=normmse(1,3);
upper(2,1):=normmse(2,3);
upper(3,1):=normmse(3,3);
upper(4,1):=normmse(4,3);
upper(5,1):=normmse(5,3);
upper(6,1):=normmse(6,3);
upper(7,1):=normmse(7,3);
upper(8,1):=normmse(8,3);
upper(9,1):=normmse(9,3);
upper(10,1):=normmse(10,3);
upper(11,1):=normmse(11,3);
upper(12,1):=normmse(12,3);
upper(13,1):=normmse(13,3);
upper(14,1):=normmse(14,3);
upper(15,1):=normmse(15,3);
upper(16,1):=normmse(16,3);
upper(17,1):=normmse(17,3);
lower(1,1):=normmse(1,4);
lower(2,1):=normmse(2,4);
lower(3,1):=normmse(3,4);
lower(4,1):=normmse(4,4);
lower(5,1):=normmse(5,4);
lower(6,1):=normmse(6,4);
lower(7,1):=normmse(7,4);
lower(8,1):=normmse(8,4);
lower(9,1):=normmse(9,4);
lower(10,1):=normmse(10,4);
lower(11,1):=normmse(11,4);
lower(12,1):=normmse(12,4);
lower(13,1):=normmse(13,4);
lower(14,1):=normmse(14,4);
lower(15,1):=normmse(15,4);
lower(16,1):=normmse(16,4);
lower(17,1):=normmse(17,4);
for i:=1 to count1/3 do
begin
nofact(i,1):=i;
end;
{##############################################################################
# #
# Update the Template Graph with the company details by overlaying a range plot #
# of the company for each factor #
# #
##############################################################################}
DisplayInputBox('Title of Graph','New Title',out$);
GetDelimitedString(out$,1,title$);
{Calls up the template graph}
main:=OpenGraph ( 'c:\template.stg'); {This graph location needs to be changed}
{Specify title for the graph}
GraphSetTitle(main,Title_Top1,title$);
g:=GraphAddRangePlot (main, '', '',count1/3, nofact, zdata,upper,lower);
l:=GraphAddPlot(main,lineplot,'',count1/3,nofact,zdata);
GraphsetRangePlot2DLayout(main,g,datalabels_off,bar_whiskers,?BarWidth,?isrightaxis);
DisplayInputBox('Subject Name','Group Name',out1$);
{Specify name of group that you are analysing}
GetDelimitedString(out1$,1,test$);
line02$:='@l[1]'+'Most Effective'+'@l[2]'+ 'Least Effective' + '@l[5]'+Test$+ '@l[3]' + 'Mean and s.e.';
GraphSetTitle (main, 3, line02$);
GraphSetPlotPointStyle (main, l, ON, P_filled_diamond, 5, blue);
GraphSetPlotLineStyle (main, l, on, L_solid, ?Size,blue);
Gp$:='c:\.stg'; {This graph location needs to be changed}
If DisplayInputBox ('Enter Graph Name','Graph Name:',Gp$) then
SaveGraph(main,Gp$);
DisplayGraph(Main);
If DisplayMessageBox(MB_YESNO, 'Print', 'Print Graph?') = IDYES then
PrintGraph(Main);
| Back to List of Programs |
![[StatSoft]](../../../images/sssmall.gif)
2300 East 14th Street, Tulsa, OK 74104
Phone: (918) 749-1119; Fax: (918) 749-2217
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.