Trouble with DEFINE command in published macro for reliability

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Trouble with DEFINE command in published macro for reliability

Reggie
Hi,

I've come across an interesting method to estimate internal consistency reliability for composite scores based on dichotomous items in the following paper.

Sun, W., Chou, C. P., Stacy, A. W., Ma, H., Unger, J., & Gallaher, P. (2007). SAS and SPSS macros to calculate standardized Cronbach’s alpha using the upper bound of the phi coefficient for dichotomous items. Behavior Research Methods, 39(1), 71-81.

The paper includes the macro, with example data, in the Appendix. I've copied the example macro/data into a SPSS syntax file, but, when I run it, I invariably get an error on line 151: 'Unrecognized text appears on the command where a variable name was expected.' I believe the DEFINE command has specified the value of 3 on line 37, which is the number of variables in the data, but it doesn't seem to register throughout the macro for some reason. Any ideas?

DATA LIST LIST /v1 v2 v3 .
BEGIN DATA
1 1 1
1 0 0
1 1 0
1 1 1
1 0 1
1 0 1
1 1 1
1 0 0
0 1 0
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
0 1 0
1 1 1
0 1 0
1 1 1
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
1 1 1
1 0 1
1 0 0
1 1 1
0 0 0
1 1 1
1 1 1
END DATA.
save outfile 'c:\temp\t1.sav'.
* to DEFINE the number of variables.
DEFINE varNumber()
3
!ENDDEFINE.

*Note:1) The name of input data set should be t1.
* 2) All dichotomous variables should be defined as v plus a number, such as v1, v2, v3, etc.
* 3) The global macro, varNumber, should be assigned an integer.
* 4) The folder, c:\temp, exists.
SET PRINTBACK=off MPRINT=off .
DATA LIST LIST /c.
BEGIN DATA
1
END DATA.
save outfile 'c:\temp\c1.sav'.
DEFINE mp(nbvar=!tokens(1))
* macro 1 --------------- .
!do !cnt=1 !to !nbvar
!if (!cnt = 1) !then
write outfile 'c:\temp\temp.sps' /''*to get percent.''/''aggregate outfile 'c:\temp\t2.sav'''/'' /break =
const''/!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,')')).
!ifend.
!if (!cnt = !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,').')).
!ifend.
!if (!cnt <> 1 & !cnt <> !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,')')).
!ifend.
!doend
exe.
!ENDDEFINE.

* macro 2 --------------- .
DEFINE upb_phi(var1=!tokens(1)/
var2=!tokens(1)/
var3=!tokens(1)).
do if (!var1 gt !var2).
+ compute !var3=sqrt(!var2*(1-!var1)/(!var1*(1-!var2))).
else if (!var1 le !var2).
+ compute !var3=sqrt(!var1*(1-!var2)/(!var2*(1-!var1))).
end if.
!ENDDEFINE.

* macro 3 --------------- .
DEFINE upb_phi1(nbvar=!tokens(1))
!let !const1=1.
!do !cnt=1 !to !nbvar
!let !cnt1= !length(!concat(!blanks(!cnt), !blanks(!const1))).
!do !cntt=!cnt1 !to !nbvar
!let !vt1=!concat('pv',!cnt).
!let !vt2=!concat('pv',!cntt).
!let !vt3=!concat('pv',!cnt,'_',!cntt).
write outfile 'c:\temp\temp.sps' /!quote(!concat('upb_phi var1=',!vt1, ' var2=',!vt2, ' var3=',!vt3,'.')).
!doend
!doend
exe.
!ENDDEFINE.

* macro 4 --------------- .
DEFINE M_alphaUP(nbvar=!tokens(1))
!let !ttt=!concat(' ').
!do !cnt=1 !to !nbvar
!do !cnt1=2 !to !nbvar
!if (!cnt = 1 & !cnt1=2) !then
!let !ttt= !concat('0 ').
!ifend
!if (!cnt < !cnt1 ) !then
!let !ttt= !concat(!ttt,'+pv',!cnt,'_',!cnt1).
!ifend
!doend
!doend
compute totr=!ttt.
compute totn=!nbvar*(!nbvar-1)/2.
compute avgr=totr/totn.
compute salpha_up=!nbvar*avgr/(1+(!nbvar-1)*avgr).
exe.
!ENDDEFINE.

* macro 5 --------------- .
DEFINE Mcorr(nbvar=!tokens(1))
!let !ttt= !concat('v', !nbvar).
reliability variables = v1 to !ttt
/model=alpha
/matrix=out ('c:\temp\corr.sav') noprint.
!ENDDEFINE.

* macro 6 --------------- .
DEFINE Msum(nbvar=!tokens(1))
!do !cnt=1 !to !nbvar
!if (!cnt = 1) !then
write outfile 'c:\temp\temp.sps' /''*to get percent.''/''aggregate outfile 'c:\temp\t2.sav'''/'' /break =
const''/!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,')')).
!ifend.
!if (!cnt = !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,').')).
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /n=sum(const).')).
!ifend.
!if (!cnt <> 1 & !cnt <> !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,')')).
!ifend.
!doend
exe.
!ENDDEFINE.

* macro 7 --------------- .
DEFINE Malpha(nbvar=!tokens(1))
!let !ttt=!concat('sv1').
!do !cnt=2 !to !nbvar
!let !ttt= !concat(!ttt,'+sv',!cnt).
!doend
compute totr=(!ttt-!nbvar)/2.
compute totn=!nbvar*(!nbvar-1)/2.
compute avgr=totr/totn.
compute salpha=!nbvar*avgr/(1+(!nbvar-1)*avgr).
!ENDDEFINE.
get file 'c:\temp\c1.sav'.
mp nbvar=varnumber.
get file='c:\temp\t1.sav'.
compute const = 1.
execute.
*list.
include 'c:\temp\temp.sps'.
get file 'c:\temp\c1.sav'.
upb_phi1 nbvar=varnumber.
get file 'c:\temp\t2.sav'.
include 'c:\temp\temp.sps'.
save outfile 'c:\temp\salpha_phi.sav'.
*list.
get file 'c:\temp\salpha_phi.sav'.
M_alphaUP nbvar=varnumber.
save outfile 'c:\temp\salpha_phi.sav'
/keep salpha_up.
*list.
get file 'c:\temp\t1.sav'.
Mcorr nbvar=varnumber.
get file 'c:\temp\corr.sav'.
select if (rowtype_='CORR').
save outfile 'c:\temp\corr1.sav'
/drop rowtype_ varname_.
get file 'c:\temp\corr1.sav'.
compute const = 1.
execute.
*list.
get file 'c:\temp\c1.sav'.
Msum nbvar=varnumber.
get file 'c:\temp\corr1.sav'.
compute const = 1.
execute.
*list.
include 'c:\temp\temp.sps'.
get file 'c:\temp\t2.sav'.
Malpha nbvar=varnumber.
save outfile 'c:\temp\salpha.sav'
/keep salpha.
*list.
match files file='c:\temp\salpha_phi.sav'
/file='c:\temp\salpha.sav'.
variable labels
salpha_up ''Standardized Cronbach's alpha from Upper Bound phi Coefficient''
salpha ''Standardized Cronbach's alpha''.
save outfile 'c:\temp\alpha.sav'.
set header=no printback=no.
formats salpha_up(F5.3) salpha(F5.3).
variable labels
salpha_up ''Cronbach's alpha from UB phi''
salpha ''Standardized Cronbach's alpha''.
display labels.
list.
erase file='c:\temp\t2.sav'.
erase file='c:\temp\corr.sav'.
erase file='c:\temp\temp.sps '.
erase file='c:\temp\salpha_phi.sav'.
erase file='c:\temp\salpha.sav '.
erase file='c:\temp\corr1.sav '.
erase file='c:\temp\c1.sav '.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with DEFINE command in published macro for reliability

David Marso
Administrator
OK, maybe a bit of debugging lessons for you.  
Please consider using SET MPRINT ON PRINTBACK ON for starters.
See also !EVAL operator in the FM and search for it on this list.
You posted 7 macros but don't bother to thin out the possible culprits.
Just eyeballing the macros they appear to be incredibly sloppy, poorly designed and ineptly implemented.
Assumes I have a C:\TEMP?, Uses WRITE to generate syntax for INCLUDE.  
We call that technique the 'horrible hack'.
I am sure this hideous mess could be very easily rewritten using the MATRIX language.
--
Reggie wrote
Hi,

I've come across an interesting method to estimate internal consistency reliability for composite scores based on dichotomous items in the following paper.

Sun, W., Chou, C. P., Stacy, A. W., Ma, H., Unger, J., & Gallaher, P. (2007). SAS and SPSS macros to calculate standardized Cronbach’s alpha using the upper bound of the phi coefficient for dichotomous items. Behavior Research Methods, 39(1), 71-81.

The paper includes the macro, with example data, in the Appendix. I've copied the example macro/data into a SPSS syntax file, but, when I run it, I invariably get an error on line 151: 'Unrecognized text appears on the command where a variable name was expected.' I believe the DEFINE command has specified the value of 3 on line 37, which is the number of variables in the data, but it doesn't seem to register throughout the macro for some reason. Any ideas?

DATA LIST LIST /v1 v2 v3 .
BEGIN DATA
1 1 1
1 0 0
1 1 0
1 1 1
1 0 1
1 0 1
1 1 1
1 0 0
0 1 0
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
0 1 0
1 1 1
0 1 0
1 1 1
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
1 1 1
1 0 1
1 0 0
1 1 1
0 0 0
1 1 1
1 1 1
END DATA.
save outfile 'c:\temp\t1.sav'.
* to DEFINE the number of variables.
DEFINE varNumber()
3
!ENDDEFINE.

*Note:1) The name of input data set should be t1.
* 2) All dichotomous variables should be defined as v plus a number, such as v1, v2, v3, etc.
* 3) The global macro, varNumber, should be assigned an integer.
* 4) The folder, c:\temp, exists.
SET PRINTBACK=off MPRINT=off .
DATA LIST LIST /c.
BEGIN DATA
1
END DATA.
save outfile 'c:\temp\c1.sav'.
DEFINE mp(nbvar=!tokens(1))
* macro 1 --------------- .
!do !cnt=1 !to !nbvar
!if (!cnt = 1) !then
write outfile 'c:\temp\temp.sps' /''*to get percent.''/''aggregate outfile 'c:\temp\t2.sav'''/'' /break =
const''/!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,')')).
!ifend.
!if (!cnt = !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,').')).
!ifend.
!if (!cnt <> 1 & !cnt <> !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,')')).
!ifend.
!doend
exe.
!ENDDEFINE.

* macro 2 --------------- .
DEFINE upb_phi(var1=!tokens(1)/
var2=!tokens(1)/
var3=!tokens(1)).
do if (!var1 gt !var2).
+ compute !var3=sqrt(!var2*(1-!var1)/(!var1*(1-!var2))).
else if (!var1 le !var2).
+ compute !var3=sqrt(!var1*(1-!var2)/(!var2*(1-!var1))).
end if.
!ENDDEFINE.

* macro 3 --------------- .
DEFINE upb_phi1(nbvar=!tokens(1))
!let !const1=1.
!do !cnt=1 !to !nbvar
!let !cnt1= !length(!concat(!blanks(!cnt), !blanks(!const1))).
!do !cntt=!cnt1 !to !nbvar
!let !vt1=!concat('pv',!cnt).
!let !vt2=!concat('pv',!cntt).
!let !vt3=!concat('pv',!cnt,'_',!cntt).
write outfile 'c:\temp\temp.sps' /!quote(!concat('upb_phi var1=',!vt1, ' var2=',!vt2, ' var3=',!vt3,'.')).
!doend
!doend
exe.
!ENDDEFINE.

* macro 4 --------------- .
DEFINE M_alphaUP(nbvar=!tokens(1))
!let !ttt=!concat(' ').
!do !cnt=1 !to !nbvar
!do !cnt1=2 !to !nbvar
!if (!cnt = 1 & !cnt1=2) !then
!let !ttt= !concat('0 ').
!ifend
!if (!cnt < !cnt1 ) !then
!let !ttt= !concat(!ttt,'+pv',!cnt,'_',!cnt1).
!ifend
!doend
!doend
compute totr=!ttt.
compute totn=!nbvar*(!nbvar-1)/2.
compute avgr=totr/totn.
compute salpha_up=!nbvar*avgr/(1+(!nbvar-1)*avgr).
exe.
!ENDDEFINE.

* macro 5 --------------- .
DEFINE Mcorr(nbvar=!tokens(1))
!let !ttt= !concat('v', !nbvar).
reliability variables = v1 to !ttt
/model=alpha
/matrix=out ('c:\temp\corr.sav') noprint.
!ENDDEFINE.

* macro 6 --------------- .
DEFINE Msum(nbvar=!tokens(1))
!do !cnt=1 !to !nbvar
!if (!cnt = 1) !then
write outfile 'c:\temp\temp.sps' /''*to get percent.''/''aggregate outfile 'c:\temp\t2.sav'''/'' /break =
const''/!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,')')).
!ifend.
!if (!cnt = !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,').')).
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /n=sum(const).')).
!ifend.
!if (!cnt <> 1 & !cnt <> !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,')')).
!ifend.
!doend
exe.
!ENDDEFINE.

* macro 7 --------------- .
DEFINE Malpha(nbvar=!tokens(1))
!let !ttt=!concat('sv1').
!do !cnt=2 !to !nbvar
!let !ttt= !concat(!ttt,'+sv',!cnt).
!doend
compute totr=(!ttt-!nbvar)/2.
compute totn=!nbvar*(!nbvar-1)/2.
compute avgr=totr/totn.
compute salpha=!nbvar*avgr/(1+(!nbvar-1)*avgr).
!ENDDEFINE.
get file 'c:\temp\c1.sav'.
mp nbvar=varnumber.
get file='c:\temp\t1.sav'.
compute const = 1.
execute.
*list.
include 'c:\temp\temp.sps'.
get file 'c:\temp\c1.sav'.
upb_phi1 nbvar=varnumber.
get file 'c:\temp\t2.sav'.
include 'c:\temp\temp.sps'.
save outfile 'c:\temp\salpha_phi.sav'.
*list.
get file 'c:\temp\salpha_phi.sav'.
M_alphaUP nbvar=varnumber.
save outfile 'c:\temp\salpha_phi.sav'
/keep salpha_up.
*list.
get file 'c:\temp\t1.sav'.
Mcorr nbvar=varnumber.
get file 'c:\temp\corr.sav'.
select if (rowtype_='CORR').
save outfile 'c:\temp\corr1.sav'
/drop rowtype_ varname_.
get file 'c:\temp\corr1.sav'.
compute const = 1.
execute.
*list.
get file 'c:\temp\c1.sav'.
Msum nbvar=varnumber.
get file 'c:\temp\corr1.sav'.
compute const = 1.
execute.
*list.
include 'c:\temp\temp.sps'.
get file 'c:\temp\t2.sav'.
Malpha nbvar=varnumber.
save outfile 'c:\temp\salpha.sav'
/keep salpha.
*list.
match files file='c:\temp\salpha_phi.sav'
/file='c:\temp\salpha.sav'.
variable labels
salpha_up ''Standardized Cronbach's alpha from Upper Bound phi Coefficient''
salpha ''Standardized Cronbach's alpha''.
save outfile 'c:\temp\alpha.sav'.
set header=no printback=no.
formats salpha_up(F5.3) salpha(F5.3).
variable labels
salpha_up ''Cronbach's alpha from UB phi''
salpha ''Standardized Cronbach's alpha''.
display labels.
list.
erase file='c:\temp\t2.sav'.
erase file='c:\temp\corr.sav'.
erase file='c:\temp\temp.sps '.
erase file='c:\temp\salpha_phi.sav'.
erase file='c:\temp\salpha.sav '.
erase file='c:\temp\corr1.sav '.
erase file='c:\temp\c1.sav '.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with DEFINE command in published macro for reliability

David Marso
Administrator
And it took 6 people to come up with that can of worms?
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with DEFINE command in published macro for reliability

Bruce Weaver
Administrator
In reply to this post by Reggie
After poking around a bit*, I conclude that your main problem is this:  When you copied the SPSS syntax from the article http://link.springer.com/article/10.3758%2FBF03192845#/page-1), one or more carriage returns were introduced that made things go awry in one or more of the WRITE OUTFILE commands.  In particular, get rid of the carriage return in the first WRITE OUTFILE command in the mp macro definition, and try again.  

It also looks to me as though double-quotes in the PDF for the article (") are being converted into a pair of single quotes when you copy and paste into a text editor (or syntax editor) -- i.e., " is being converted to ''.  That may also be causing problems.  If the authors have the syntax files available for download somewhere, try that syntax rather than syntax copied and pasted from the article PDF.

HTH.


* Yes, I know, David.  It's a rabbit hole!  What can I say?  ;-)


Reggie wrote
Hi,

I've come across an interesting method to estimate internal consistency reliability for composite scores based on dichotomous items in the following paper.

Sun, W., Chou, C. P., Stacy, A. W., Ma, H., Unger, J., & Gallaher, P. (2007). SAS and SPSS macros to calculate standardized Cronbach’s alpha using the upper bound of the phi coefficient for dichotomous items. Behavior Research Methods, 39(1), 71-81.

The paper includes the macro, with example data, in the Appendix. I've copied the example macro/data into a SPSS syntax file, but, when I run it, I invariably get an error on line 151: 'Unrecognized text appears on the command where a variable name was expected.' I believe the DEFINE command has specified the value of 3 on line 37, which is the number of variables in the data, but it doesn't seem to register throughout the macro for some reason. Any ideas?

DATA LIST LIST /v1 v2 v3 .
BEGIN DATA
1 1 1
1 0 0
1 1 0
1 1 1
1 0 1
1 0 1
1 1 1
1 0 0
0 1 0
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
0 1 0
1 1 1
0 1 0
1 1 1
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
1 1 1
1 0 1
1 0 0
1 1 1
0 0 0
1 1 1
1 1 1
END DATA.
save outfile 'c:\temp\t1.sav'.
* to DEFINE the number of variables.
DEFINE varNumber()
3
!ENDDEFINE.

*Note:1) The name of input data set should be t1.
* 2) All dichotomous variables should be defined as v plus a number, such as v1, v2, v3, etc.
* 3) The global macro, varNumber, should be assigned an integer.
* 4) The folder, c:\temp, exists.
SET PRINTBACK=off MPRINT=off .
DATA LIST LIST /c.
BEGIN DATA
1
END DATA.
save outfile 'c:\temp\c1.sav'.
DEFINE mp(nbvar=!tokens(1))
* macro 1 --------------- .
!do !cnt=1 !to !nbvar
!if (!cnt = 1) !then
write outfile 'c:\temp\temp.sps' /''*to get percent.''/''aggregate outfile 'c:\temp\t2.sav'''/'' /break =
const''/!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,')')).
!ifend.
!if (!cnt = !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,').')).
!ifend.
!if (!cnt <> 1 & !cnt <> !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,')')).
!ifend.
!doend
exe.
!ENDDEFINE.

* macro 2 --------------- .
DEFINE upb_phi(var1=!tokens(1)/
var2=!tokens(1)/
var3=!tokens(1)).
do if (!var1 gt !var2).
+ compute !var3=sqrt(!var2*(1-!var1)/(!var1*(1-!var2))).
else if (!var1 le !var2).
+ compute !var3=sqrt(!var1*(1-!var2)/(!var2*(1-!var1))).
end if.
!ENDDEFINE.

* macro 3 --------------- .
DEFINE upb_phi1(nbvar=!tokens(1))
!let !const1=1.
!do !cnt=1 !to !nbvar
!let !cnt1= !length(!concat(!blanks(!cnt), !blanks(!const1))).
!do !cntt=!cnt1 !to !nbvar
!let !vt1=!concat('pv',!cnt).
!let !vt2=!concat('pv',!cntt).
!let !vt3=!concat('pv',!cnt,'_',!cntt).
write outfile 'c:\temp\temp.sps' /!quote(!concat('upb_phi var1=',!vt1, ' var2=',!vt2, ' var3=',!vt3,'.')).
!doend
!doend
exe.
!ENDDEFINE.

* macro 4 --------------- .
DEFINE M_alphaUP(nbvar=!tokens(1))
!let !ttt=!concat(' ').
!do !cnt=1 !to !nbvar
!do !cnt1=2 !to !nbvar
!if (!cnt = 1 & !cnt1=2) !then
!let !ttt= !concat('0 ').
!ifend
!if (!cnt < !cnt1 ) !then
!let !ttt= !concat(!ttt,'+pv',!cnt,'_',!cnt1).
!ifend
!doend
!doend
compute totr=!ttt.
compute totn=!nbvar*(!nbvar-1)/2.
compute avgr=totr/totn.
compute salpha_up=!nbvar*avgr/(1+(!nbvar-1)*avgr).
exe.
!ENDDEFINE.

* macro 5 --------------- .
DEFINE Mcorr(nbvar=!tokens(1))
!let !ttt= !concat('v', !nbvar).
reliability variables = v1 to !ttt
/model=alpha
/matrix=out ('c:\temp\corr.sav') noprint.
!ENDDEFINE.

* macro 6 --------------- .
DEFINE Msum(nbvar=!tokens(1))
!do !cnt=1 !to !nbvar
!if (!cnt = 1) !then
write outfile 'c:\temp\temp.sps' /''*to get percent.''/''aggregate outfile 'c:\temp\t2.sav'''/'' /break =
const''/!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,')')).
!ifend.
!if (!cnt = !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,').')).
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /n=sum(const).')).
!ifend.
!if (!cnt <> 1 & !cnt <> !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,')')).
!ifend.
!doend
exe.
!ENDDEFINE.

* macro 7 --------------- .
DEFINE Malpha(nbvar=!tokens(1))
!let !ttt=!concat('sv1').
!do !cnt=2 !to !nbvar
!let !ttt= !concat(!ttt,'+sv',!cnt).
!doend
compute totr=(!ttt-!nbvar)/2.
compute totn=!nbvar*(!nbvar-1)/2.
compute avgr=totr/totn.
compute salpha=!nbvar*avgr/(1+(!nbvar-1)*avgr).
!ENDDEFINE.
get file 'c:\temp\c1.sav'.
mp nbvar=varnumber.
get file='c:\temp\t1.sav'.
compute const = 1.
execute.
*list.
include 'c:\temp\temp.sps'.
get file 'c:\temp\c1.sav'.
upb_phi1 nbvar=varnumber.
get file 'c:\temp\t2.sav'.
include 'c:\temp\temp.sps'.
save outfile 'c:\temp\salpha_phi.sav'.
*list.
get file 'c:\temp\salpha_phi.sav'.
M_alphaUP nbvar=varnumber.
save outfile 'c:\temp\salpha_phi.sav'
/keep salpha_up.
*list.
get file 'c:\temp\t1.sav'.
Mcorr nbvar=varnumber.
get file 'c:\temp\corr.sav'.
select if (rowtype_='CORR').
save outfile 'c:\temp\corr1.sav'
/drop rowtype_ varname_.
get file 'c:\temp\corr1.sav'.
compute const = 1.
execute.
*list.
get file 'c:\temp\c1.sav'.
Msum nbvar=varnumber.
get file 'c:\temp\corr1.sav'.
compute const = 1.
execute.
*list.
include 'c:\temp\temp.sps'.
get file 'c:\temp\t2.sav'.
Malpha nbvar=varnumber.
save outfile 'c:\temp\salpha.sav'
/keep salpha.
*list.
match files file='c:\temp\salpha_phi.sav'
/file='c:\temp\salpha.sav'.
variable labels
salpha_up ''Standardized Cronbach's alpha from Upper Bound phi Coefficient''
salpha ''Standardized Cronbach's alpha''.
save outfile 'c:\temp\alpha.sav'.
set header=no printback=no.
formats salpha_up(F5.3) salpha(F5.3).
variable labels
salpha_up ''Cronbach's alpha from UB phi''
salpha ''Standardized Cronbach's alpha''.
display labels.
list.
erase file='c:\temp\t2.sav'.
erase file='c:\temp\corr.sav'.
erase file='c:\temp\temp.sps '.
erase file='c:\temp\salpha_phi.sav'.
erase file='c:\temp\salpha.sav '.
erase file='c:\temp\corr1.sav '.
erase file='c:\temp\c1.sav '.
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with DEFINE command in published macro for reliability

David Marso
Administrator
Whatever you do, don't accept mushrooms from strangers or talk to any funny looking caterpillars.
One would do much better to figure out what the macro is actually trying to do and rewrite it using something resembling a sane methodology.  If I had any deep interest in the substantive content I would give it a go (but I don't).
--
Bruce Weaver wrote
After poking around a bit*, I conclude that your main problem is this:  When you copied the SPSS syntax from the article http://link.springer.com/article/10.3758%2FBF03192845#/page-1), one or more carriage returns were introduced that made things go awry in one or more of the WRITE OUTFILE commands.  In particular, get rid of the carriage return in the first WRITE OUTFILE command in the mp macro definition, and try again.  

It also looks to me as though double-quotes in the PDF for the article (") are being converted into a pair of single quotes when you copy and paste into a text editor (or syntax editor) -- i.e., " is being converted to ''.  That may also be causing problems.  If the authors have the syntax files available for download somewhere, try that syntax rather than syntax copied and pasted from the article PDF.

HTH.


* Yes, I know, David.  It's a rabbit hole!  What can I say?  ;-)


Reggie wrote
Hi,

I've come across an interesting method to estimate internal consistency reliability for composite scores based on dichotomous items in the following paper.

Sun, W., Chou, C. P., Stacy, A. W., Ma, H., Unger, J., & Gallaher, P. (2007). SAS and SPSS macros to calculate standardized Cronbach’s alpha using the upper bound of the phi coefficient for dichotomous items. Behavior Research Methods, 39(1), 71-81.

The paper includes the macro, with example data, in the Appendix. I've copied the example macro/data into a SPSS syntax file, but, when I run it, I invariably get an error on line 151: 'Unrecognized text appears on the command where a variable name was expected.' I believe the DEFINE command has specified the value of 3 on line 37, which is the number of variables in the data, but it doesn't seem to register throughout the macro for some reason. Any ideas?

DATA LIST LIST /v1 v2 v3 .
BEGIN DATA
1 1 1
1 0 0
1 1 0
1 1 1
1 0 1
1 0 1
1 1 1
1 0 0
0 1 0
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
0 1 0
1 1 1
0 1 0
1 1 1
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
1 1 1
1 0 1
1 0 0
1 1 1
0 0 0
1 1 1
1 1 1
END DATA.
save outfile 'c:\temp\t1.sav'.
* to DEFINE the number of variables.
DEFINE varNumber()
3
!ENDDEFINE.

*Note:1) The name of input data set should be t1.
* 2) All dichotomous variables should be defined as v plus a number, such as v1, v2, v3, etc.
* 3) The global macro, varNumber, should be assigned an integer.
* 4) The folder, c:\temp, exists.
SET PRINTBACK=off MPRINT=off .
DATA LIST LIST /c.
BEGIN DATA
1
END DATA.
save outfile 'c:\temp\c1.sav'.
DEFINE mp(nbvar=!tokens(1))
* macro 1 --------------- .
!do !cnt=1 !to !nbvar
!if (!cnt = 1) !then
write outfile 'c:\temp\temp.sps' /''*to get percent.''/''aggregate outfile 'c:\temp\t2.sav'''/'' /break =
const''/!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,')')).
!ifend.
!if (!cnt = !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,').')).
!ifend.
!if (!cnt <> 1 & !cnt <> !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,')')).
!ifend.
!doend
exe.
!ENDDEFINE.

* macro 2 --------------- .
DEFINE upb_phi(var1=!tokens(1)/
var2=!tokens(1)/
var3=!tokens(1)).
do if (!var1 gt !var2).
+ compute !var3=sqrt(!var2*(1-!var1)/(!var1*(1-!var2))).
else if (!var1 le !var2).
+ compute !var3=sqrt(!var1*(1-!var2)/(!var2*(1-!var1))).
end if.
!ENDDEFINE.

* macro 3 --------------- .
DEFINE upb_phi1(nbvar=!tokens(1))
!let !const1=1.
!do !cnt=1 !to !nbvar
!let !cnt1= !length(!concat(!blanks(!cnt), !blanks(!const1))).
!do !cntt=!cnt1 !to !nbvar
!let !vt1=!concat('pv',!cnt).
!let !vt2=!concat('pv',!cntt).
!let !vt3=!concat('pv',!cnt,'_',!cntt).
write outfile 'c:\temp\temp.sps' /!quote(!concat('upb_phi var1=',!vt1, ' var2=',!vt2, ' var3=',!vt3,'.')).
!doend
!doend
exe.
!ENDDEFINE.

* macro 4 --------------- .
DEFINE M_alphaUP(nbvar=!tokens(1))
!let !ttt=!concat(' ').
!do !cnt=1 !to !nbvar
!do !cnt1=2 !to !nbvar
!if (!cnt = 1 & !cnt1=2) !then
!let !ttt= !concat('0 ').
!ifend
!if (!cnt < !cnt1 ) !then
!let !ttt= !concat(!ttt,'+pv',!cnt,'_',!cnt1).
!ifend
!doend
!doend
compute totr=!ttt.
compute totn=!nbvar*(!nbvar-1)/2.
compute avgr=totr/totn.
compute salpha_up=!nbvar*avgr/(1+(!nbvar-1)*avgr).
exe.
!ENDDEFINE.

* macro 5 --------------- .
DEFINE Mcorr(nbvar=!tokens(1))
!let !ttt= !concat('v', !nbvar).
reliability variables = v1 to !ttt
/model=alpha
/matrix=out ('c:\temp\corr.sav') noprint.
!ENDDEFINE.

* macro 6 --------------- .
DEFINE Msum(nbvar=!tokens(1))
!do !cnt=1 !to !nbvar
!if (!cnt = 1) !then
write outfile 'c:\temp\temp.sps' /''*to get percent.''/''aggregate outfile 'c:\temp\t2.sav'''/'' /break =
const''/!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,')')).
!ifend.
!if (!cnt = !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,').')).
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /n=sum(const).')).
!ifend.
!if (!cnt <> 1 & !cnt <> !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,')')).
!ifend.
!doend
exe.
!ENDDEFINE.

* macro 7 --------------- .
DEFINE Malpha(nbvar=!tokens(1))
!let !ttt=!concat('sv1').
!do !cnt=2 !to !nbvar
!let !ttt= !concat(!ttt,'+sv',!cnt).
!doend
compute totr=(!ttt-!nbvar)/2.
compute totn=!nbvar*(!nbvar-1)/2.
compute avgr=totr/totn.
compute salpha=!nbvar*avgr/(1+(!nbvar-1)*avgr).
!ENDDEFINE.
get file 'c:\temp\c1.sav'.
mp nbvar=varnumber.
get file='c:\temp\t1.sav'.
compute const = 1.
execute.
*list.
include 'c:\temp\temp.sps'.
get file 'c:\temp\c1.sav'.
upb_phi1 nbvar=varnumber.
get file 'c:\temp\t2.sav'.
include 'c:\temp\temp.sps'.
save outfile 'c:\temp\salpha_phi.sav'.
*list.
get file 'c:\temp\salpha_phi.sav'.
M_alphaUP nbvar=varnumber.
save outfile 'c:\temp\salpha_phi.sav'
/keep salpha_up.
*list.
get file 'c:\temp\t1.sav'.
Mcorr nbvar=varnumber.
get file 'c:\temp\corr.sav'.
select if (rowtype_='CORR').
save outfile 'c:\temp\corr1.sav'
/drop rowtype_ varname_.
get file 'c:\temp\corr1.sav'.
compute const = 1.
execute.
*list.
get file 'c:\temp\c1.sav'.
Msum nbvar=varnumber.
get file 'c:\temp\corr1.sav'.
compute const = 1.
execute.
*list.
include 'c:\temp\temp.sps'.
get file 'c:\temp\t2.sav'.
Malpha nbvar=varnumber.
save outfile 'c:\temp\salpha.sav'
/keep salpha.
*list.
match files file='c:\temp\salpha_phi.sav'
/file='c:\temp\salpha.sav'.
variable labels
salpha_up ''Standardized Cronbach's alpha from Upper Bound phi Coefficient''
salpha ''Standardized Cronbach's alpha''.
save outfile 'c:\temp\alpha.sav'.
set header=no printback=no.
formats salpha_up(F5.3) salpha(F5.3).
variable labels
salpha_up ''Cronbach's alpha from UB phi''
salpha ''Standardized Cronbach's alpha''.
display labels.
list.
erase file='c:\temp\t2.sav'.
erase file='c:\temp\corr.sav'.
erase file='c:\temp\temp.sps '.
erase file='c:\temp\salpha_phi.sav'.
erase file='c:\temp\salpha.sav '.
erase file='c:\temp\corr1.sav '.
erase file='c:\temp\c1.sav '.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with DEFINE command in published macro for reliability

David Marso
Administrator
In reply to this post by Bruce Weaver
Another reason I take issue with such ludicrous, inept stabs at SPSS 'macro programming' is that they engender a bad reputation for SPSS among curious neophyte onlookers.  An otherwise bright but unfamiliar reader might encounter this code and conclude quite incorrectly that SPSS is a festering pile of unusable, rube Goldbergian, indirect,  nasty,  impossible to code garbage.  If such abominations were truly necessary this onlooker would be correct.  They however lack the evidence to the contrary but nonetheless tell all their friends.

On Fri, Nov 20, 2015 at 2:40 PM, Bruce Weaver [via SPSSX Discussion] <[hidden email]> wrote:
After poking around a bit*, I conclude that your main problem is this:  When you copied the SPSS syntax from the article http://link.springer.com/article/10.3758%2FBF03192845#/page-1), one or more carriage returns were introduced that made things go awry in one or more of the WRITE OUTFILE commands.  In particular, get rid of the carriage return in the first WRITE OUTFILE command in the mp macro definition, and try again.  

It also looks to me as though double-quotes in the PDF for the article (") are being converted into a pair of single quotes when you copy and paste into a text editor (or syntax editor) -- i.e., " is being converted to ''.  That may also be causing problems.  If the authors have the syntax files available for download somewhere, try that syntax rather than syntax copied and pasted from the article PDF.

HTH.


* Yes, I know, David.  It's a rabbit hole!  What can I say?  ;-)


Reggie wrote
Hi,

I've come across an interesting method to estimate internal consistency reliability for composite scores based on dichotomous items in the following paper.

Sun, W., Chou, C. P., Stacy, A. W., Ma, H., Unger, J., & Gallaher, P. (2007). SAS and SPSS macros to calculate standardized Cronbach’s alpha using the upper bound of the phi coefficient for dichotomous items. Behavior Research Methods, 39(1), 71-81.

The paper includes the macro, with example data, in the Appendix. I've copied the example macro/data into a SPSS syntax file, but, when I run it, I invariably get an error on line 151: 'Unrecognized text appears on the command where a variable name was expected.' I believe the DEFINE command has specified the value of 3 on line 37, which is the number of variables in the data, but it doesn't seem to register throughout the macro for some reason. Any ideas?

DATA LIST LIST /v1 v2 v3 .
BEGIN DATA
1 1 1
1 0 0
1 1 0
1 1 1
1 0 1
1 0 1
1 1 1
1 0 0
0 1 0
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
0 1 0
1 1 1
0 1 0
1 1 1
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
1 1 1
1 0 1
1 0 0
1 1 1
0 0 0
1 1 1
1 1 1
END DATA.
save outfile 'c:\temp\t1.sav'.
* to DEFINE the number of variables.
DEFINE varNumber()
3
!ENDDEFINE.

*Note:1) The name of input data set should be t1.
* 2) All dichotomous variables should be defined as v plus a number, such as v1, v2, v3, etc.
* 3) The global macro, varNumber, should be assigned an integer.
* 4) The folder, c:\temp, exists.
SET PRINTBACK=off MPRINT=off .
DATA LIST LIST /c.
BEGIN DATA
1
END DATA.
save outfile 'c:\temp\c1.sav'.
DEFINE mp(nbvar=!tokens(1))
* macro 1 --------------- .
!do !cnt=1 !to !nbvar
!if (!cnt = 1) !then
write outfile 'c:\temp\temp.sps' /''*to get percent.''/''aggregate outfile 'c:\temp\t2.sav'''/'' /break =
const''/!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,')')).
!ifend.
!if (!cnt = !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,').')).
!ifend.
!if (!cnt <> 1 & !cnt <> !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,')')).
!ifend.
!doend
exe.
!ENDDEFINE.

* macro 2 --------------- .
DEFINE upb_phi(var1=!tokens(1)/
var2=!tokens(1)/
var3=!tokens(1)).
do if (!var1 gt !var2).
+ compute !var3=sqrt(!var2*(1-!var1)/(!var1*(1-!var2))).
else if (!var1 le !var2).
+ compute !var3=sqrt(!var1*(1-!var2)/(!var2*(1-!var1))).
end if.
!ENDDEFINE.

* macro 3 --------------- .
DEFINE upb_phi1(nbvar=!tokens(1))
!let !const1=1.
!do !cnt=1 !to !nbvar
!let !cnt1= !length(!concat(!blanks(!cnt), !blanks(!const1))).
!do !cntt=!cnt1 !to !nbvar
!let !vt1=!concat('pv',!cnt).
!let !vt2=!concat('pv',!cntt).
!let !vt3=!concat('pv',!cnt,'_',!cntt).
write outfile 'c:\temp\temp.sps' /!quote(!concat('upb_phi var1=',!vt1, ' var2=',!vt2, ' var3=',!vt3,'.')).
!doend
!doend
exe.
!ENDDEFINE.

* macro 4 --------------- .
DEFINE M_alphaUP(nbvar=!tokens(1))
!let !ttt=!concat(' ').
!do !cnt=1 !to !nbvar
!do !cnt1=2 !to !nbvar
!if (!cnt = 1 & !cnt1=2) !then
!let !ttt= !concat('0 ').
!ifend
!if (!cnt < !cnt1 ) !then
!let !ttt= !concat(!ttt,'+pv',!cnt,'_',!cnt1).
!ifend
!doend
!doend
compute totr=!ttt.
compute totn=!nbvar*(!nbvar-1)/2.
compute avgr=totr/totn.
compute salpha_up=!nbvar*avgr/(1+(!nbvar-1)*avgr).
exe.
!ENDDEFINE.

* macro 5 --------------- .
DEFINE Mcorr(nbvar=!tokens(1))
!let !ttt= !concat('v', !nbvar).
reliability variables = v1 to !ttt
/model=alpha
/matrix=out ('c:\temp\corr.sav') noprint.
!ENDDEFINE.

* macro 6 --------------- .
DEFINE Msum(nbvar=!tokens(1))
!do !cnt=1 !to !nbvar
!if (!cnt = 1) !then
write outfile 'c:\temp\temp.sps' /''*to get percent.''/''aggregate outfile 'c:\temp\t2.sav'''/'' /break =
const''/!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,')')).
!ifend.
!if (!cnt = !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,').')).
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /n=sum(const).')).
!ifend.
!if (!cnt <> 1 & !cnt <> !nbvar) !then
write outfile 'c:\temp\temp.sps' /!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,')')).
!ifend.
!doend
exe.
!ENDDEFINE.

* macro 7 --------------- .
DEFINE Malpha(nbvar=!tokens(1))
!let !ttt=!concat('sv1').
!do !cnt=2 !to !nbvar
!let !ttt= !concat(!ttt,'+sv',!cnt).
!doend
compute totr=(!ttt-!nbvar)/2.
compute totn=!nbvar*(!nbvar-1)/2.
compute avgr=totr/totn.
compute salpha=!nbvar*avgr/(1+(!nbvar-1)*avgr).
!ENDDEFINE.
get file 'c:\temp\c1.sav'.
mp nbvar=varnumber.
get file='c:\temp\t1.sav'.
compute const = 1.
execute.
*list.
include 'c:\temp\temp.sps'.
get file 'c:\temp\c1.sav'.
upb_phi1 nbvar=varnumber.
get file 'c:\temp\t2.sav'.
include 'c:\temp\temp.sps'.
save outfile 'c:\temp\salpha_phi.sav'.
*list.
get file 'c:\temp\salpha_phi.sav'.
M_alphaUP nbvar=varnumber.
save outfile 'c:\temp\salpha_phi.sav'
/keep salpha_up.
*list.
get file 'c:\temp\t1.sav'.
Mcorr nbvar=varnumber.
get file 'c:\temp\corr.sav'.
select if (rowtype_='CORR').
save outfile 'c:\temp\corr1.sav'
/drop rowtype_ varname_.
get file 'c:\temp\corr1.sav'.
compute const = 1.
execute.
*list.
get file 'c:\temp\c1.sav'.
Msum nbvar=varnumber.
get file 'c:\temp\corr1.sav'.
compute const = 1.
execute.
*list.
include 'c:\temp\temp.sps'.
get file 'c:\temp\t2.sav'.
Malpha nbvar=varnumber.
save outfile 'c:\temp\salpha.sav'
/keep salpha.
*list.
match files file='c:\temp\salpha_phi.sav'
/file='c:\temp\salpha.sav'.
variable labels
salpha_up ''Standardized Cronbach's alpha from Upper Bound phi Coefficient''
salpha ''Standardized Cronbach's alpha''.
save outfile 'c:\temp\alpha.sav'.
set header=no printback=no.
formats salpha_up(F5.3) salpha(F5.3).
variable labels
salpha_up ''Cronbach's alpha from UB phi''
salpha ''Standardized Cronbach's alpha''.
display labels.
list.
erase file='c:\temp\t2.sav'.
erase file='c:\temp\corr.sav'.
erase file='c:\temp\temp.sps '.
erase file='c:\temp\salpha_phi.sav'.
erase file='c:\temp\salpha.sav '.
erase file='c:\temp\corr1.sav '.
erase file='c:\temp\c1.sav '.
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.



To unsubscribe from Trouble with DEFINE command in published macro for reliability, click here.
NAML

Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with DEFINE command in published macro for reliability

Bruce Weaver
Administrator
David, if you're not careful, you'll get yourself worked up to the point of re-programming it (despite your earlier protestations about not being sufficiently interested).  ;-)


David Marso wrote
Another reason I take issue with such ludicrous, inept stabs at SPSS 'macro
programming' is that they engender a bad reputation for SPSS among curious
neophyte onlookers.  An otherwise bright but unfamiliar reader might
encounter this code and conclude quite incorrectly that SPSS is a festering
pile of unusable, rube Goldbergian, indirect,  nasty,  impossible to code
garbage.  If such abominations were truly necessary this onlooker would be
correct.  They however lack the evidence to the contrary but nonetheless
tell all their friends.

On Fri, Nov 20, 2015 at 2:40 PM, Bruce Weaver [via SPSSX Discussion] <
[hidden email]> wrote:

> After poking around a bit*, I conclude that your main problem is this:
>  When you copied the SPSS syntax from the article
> http://link.springer.com/article/10.3758%2FBF03192845#/page-1), one or
> more carriage returns were introduced that made things go awry in one or
> more of the WRITE OUTFILE commands.  In particular, get rid of the carriage
> return in the first WRITE OUTFILE command in the mp macro definition, and
> try again.
>
> It also looks to me as though double-quotes in the PDF for the article (")
> are being converted into a pair of single quotes when you copy and paste
> into a text editor (or syntax editor) -- i.e., " is being converted to ''.
> That may also be causing problems.  If the authors have the syntax files
> available for download somewhere, try that syntax rather than syntax copied
> and pasted from the article PDF.
>
> HTH.
>
>
> * Yes, I know, David.  It's a rabbit hole!  What can I say?  ;-)
>
>
> Reggie wrote
> Hi,
>
> I've come across an interesting method to estimate internal consistency
> reliability for composite scores based on dichotomous items in the
> following paper.
>
> Sun, W., Chou, C. P., Stacy, A. W., Ma, H., Unger, J., & Gallaher, P.
> (2007). SAS and SPSS macros to calculate standardized Cronbach’s alpha
> using the upper bound of the phi coefficient for dichotomous items.
> Behavior Research Methods, 39(1), 71-81.
>
> The paper includes the macro, with example data, in the Appendix. I've
> copied the example macro/data into a SPSS syntax file, but, when I run it,
> I invariably get an error on line 151: 'Unrecognized text appears on the
> command where a variable name was expected.' I believe the DEFINE command
> has specified the value of 3 on line 37, which is the number of variables
> in the data, but it doesn't seem to register throughout the macro for some
> reason. Any ideas?
>
> DATA LIST LIST /v1 v2 v3 .
> BEGIN DATA
> 1 1 1
> 1 0 0
> 1 1 0
> 1 1 1
> 1 0 1
> 1 0 1
> 1 1 1
> 1 0 0
> 0 1 0
> 1 1 1
> 1 1 1
> 1 1 0
> 1 1 1
> 1 1 1
> 0 1 0
> 1 1 1
> 0 1 0
> 1 1 1
> 1 1 1
> 1 1 1
> 1 1 0
> 1 1 1
> 1 1 1
> 1 1 1
> 1 0 1
> 1 0 0
> 1 1 1
> 0 0 0
> 1 1 1
> 1 1 1
> END DATA.
> save outfile 'c:\temp\t1.sav'.
> * to DEFINE the number of variables.
> DEFINE varNumber()
> 3
> !ENDDEFINE.
>
> *Note:1) The name of input data set should be t1.
> * 2) All dichotomous variables should be defined as v plus a number, such
> as v1, v2, v3, etc.
> * 3) The global macro, varNumber, should be assigned an integer.
> * 4) The folder, c:\temp, exists.
> SET PRINTBACK=off MPRINT=off .
> DATA LIST LIST /c.
> BEGIN DATA
> 1
> END DATA.
> save outfile 'c:\temp\c1.sav'.
> DEFINE mp(nbvar=!tokens(1))
> * macro 1 --------------- .
> !do !cnt=1 !to !nbvar
> !if (!cnt = 1) !then
> write outfile 'c:\temp\temp.sps' /''*to get percent.''/''aggregate outfile
> 'c:\temp\t2.sav'''/'' /break =
> const''/!quote(!concat(' /pv',!cnt,'=mean(v',!cnt,')')).
> !ifend.
> !if (!cnt = !nbvar) !then
> write outfile 'c:\temp\temp.sps' /!quote(!concat('
> /pv',!cnt,'=mean(v',!cnt,').')).
> !ifend.
> !if (!cnt <> 1 & !cnt <> !nbvar) !then
> write outfile 'c:\temp\temp.sps' /!quote(!concat('
> /pv',!cnt,'=mean(v',!cnt,')')).
> !ifend.
> !doend
> exe.
> !ENDDEFINE.
>
> * macro 2 --------------- .
> DEFINE upb_phi(var1=!tokens(1)/
> var2=!tokens(1)/
> var3=!tokens(1)).
> do if (!var1 gt !var2).
> + compute !var3=sqrt(!var2*(1-!var1)/(!var1*(1-!var2))).
> else if (!var1 le !var2).
> + compute !var3=sqrt(!var1*(1-!var2)/(!var2*(1-!var1))).
> end if.
> !ENDDEFINE.
>
> * macro 3 --------------- .
> DEFINE upb_phi1(nbvar=!tokens(1))
> !let !const1=1.
> !do !cnt=1 !to !nbvar
> !let !cnt1= !length(!concat(!blanks(!cnt), !blanks(!const1))).
> !do !cntt=!cnt1 !to !nbvar
> !let !vt1=!concat('pv',!cnt).
> !let !vt2=!concat('pv',!cntt).
> !let !vt3=!concat('pv',!cnt,'_',!cntt).
> write outfile 'c:\temp\temp.sps' /!quote(!concat('upb_phi var1=',!vt1, '
> var2=',!vt2, ' var3=',!vt3,'.')).
> !doend
> !doend
> exe.
> !ENDDEFINE.
>
> * macro 4 --------------- .
> DEFINE M_alphaUP(nbvar=!tokens(1))
> !let !ttt=!concat(' ').
> !do !cnt=1 !to !nbvar
> !do !cnt1=2 !to !nbvar
> !if (!cnt = 1 & !cnt1=2) !then
> !let !ttt= !concat('0 ').
> !ifend
> !if (!cnt < !cnt1 ) !then
> !let !ttt= !concat(!ttt,'+pv',!cnt,'_',!cnt1).
> !ifend
> !doend
> !doend
> compute totr=!ttt.
> compute totn=!nbvar*(!nbvar-1)/2.
> compute avgr=totr/totn.
> compute salpha_up=!nbvar*avgr/(1+(!nbvar-1)*avgr).
> exe.
> !ENDDEFINE.
>
> * macro 5 --------------- .
> DEFINE Mcorr(nbvar=!tokens(1))
> !let !ttt= !concat('v', !nbvar).
> reliability variables = v1 to !ttt
> /model=alpha
> /matrix=out ('c:\temp\corr.sav') noprint.
> !ENDDEFINE.
>
> * macro 6 --------------- .
> DEFINE Msum(nbvar=!tokens(1))
> !do !cnt=1 !to !nbvar
> !if (!cnt = 1) !then
> write outfile 'c:\temp\temp.sps' /''*to get percent.''/''aggregate outfile
> 'c:\temp\t2.sav'''/'' /break =
> const''/!quote(!concat(' /sv',!cnt,'=sum(v',!cnt,')')).
> !ifend.
> !if (!cnt = !nbvar) !then
> write outfile 'c:\temp\temp.sps' /!quote(!concat('
> /sv',!cnt,'=sum(v',!cnt,').')).
> write outfile 'c:\temp\temp.sps' /!quote(!concat(' /n=sum(const).')).
> !ifend.
> !if (!cnt <> 1 & !cnt <> !nbvar) !then
> write outfile 'c:\temp\temp.sps' /!quote(!concat('
> /sv',!cnt,'=sum(v',!cnt,')')).
> !ifend.
> !doend
> exe.
> !ENDDEFINE.
>
> * macro 7 --------------- .
> DEFINE Malpha(nbvar=!tokens(1))
> !let !ttt=!concat('sv1').
> !do !cnt=2 !to !nbvar
> !let !ttt= !concat(!ttt,'+sv',!cnt).
> !doend
> compute totr=(!ttt-!nbvar)/2.
> compute totn=!nbvar*(!nbvar-1)/2.
> compute avgr=totr/totn.
> compute salpha=!nbvar*avgr/(1+(!nbvar-1)*avgr).
> !ENDDEFINE.
> get file 'c:\temp\c1.sav'.
> mp nbvar=varnumber.
> get file='c:\temp\t1.sav'.
> compute const = 1.
> execute.
> *list.
> include 'c:\temp\temp.sps'.
> get file 'c:\temp\c1.sav'.
> upb_phi1 nbvar=varnumber.
> get file 'c:\temp\t2.sav'.
> include 'c:\temp\temp.sps'.
> save outfile 'c:\temp\salpha_phi.sav'.
> *list.
> get file 'c:\temp\salpha_phi.sav'.
> M_alphaUP nbvar=varnumber.
> save outfile 'c:\temp\salpha_phi.sav'
> /keep salpha_up.
> *list.
> get file 'c:\temp\t1.sav'.
> Mcorr nbvar=varnumber.
> get file 'c:\temp\corr.sav'.
> select if (rowtype_='CORR').
> save outfile 'c:\temp\corr1.sav'
> /drop rowtype_ varname_.
> get file 'c:\temp\corr1.sav'.
> compute const = 1.
> execute.
> *list.
> get file 'c:\temp\c1.sav'.
> Msum nbvar=varnumber.
> get file 'c:\temp\corr1.sav'.
> compute const = 1.
> execute.
> *list.
> include 'c:\temp\temp.sps'.
> get file 'c:\temp\t2.sav'.
> Malpha nbvar=varnumber.
> save outfile 'c:\temp\salpha.sav'
> /keep salpha.
> *list.
> match files file='c:\temp\salpha_phi.sav'
> /file='c:\temp\salpha.sav'.
> variable labels
> salpha_up ''Standardized Cronbach's alpha from Upper Bound phi
> Coefficient''
> salpha ''Standardized Cronbach's alpha''.
> save outfile 'c:\temp\alpha.sav'.
> set header=no printback=no.
> formats salpha_up(F5.3) salpha(F5.3).
> variable labels
> salpha_up ''Cronbach's alpha from UB phi''
> salpha ''Standardized Cronbach's alpha''.
> display labels.
> list.
> erase file='c:\temp\t2.sav'.
> erase file='c:\temp\corr.sav'.
> erase file='c:\temp\temp.sps '.
> erase file='c:\temp\salpha_phi.sav'.
> erase file='c:\temp\salpha.sav '.
> erase file='c:\temp\corr1.sav '.
> erase file='c:\temp\c1.sav '.
>
> --
> Bruce Weaver
> [hidden email]
> http://sites.google.com/a/lakeheadu.ca/bweaver/
>
> "When all else fails, RTFM."
>
>
>
> *NOTE: My Hotmail account is not monitored regularly. To send me an
> e-mail, please use the address shown above. *
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://spssx-discussion.1045642.n5.nabble.com/Trouble-with-DEFINE-command-in-published-macro-for-reliability-tp5730988p5730992.html
> To unsubscribe from Trouble with DEFINE command in published macro for
> reliability, click here
> <http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5730988&code=ZGF2aWQubWFyc29AZ21haWwuY29tfDU3MzA5ODh8LTkzOTgzMDYxMw==>
> .
> NAML
> <http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).