Hi,
I am in a bit of a jam and I am really hoping someone can help me out. I am trying to calculate item statistics using the RELIABILITY command for several hundred tests that are all in one dataset. I've created a macro that does almost everything I want it to, but I am getting hung up on one part. Unfortunately I don't have the macro with me, but I have recreated the part I am getting stuck on. The problem is these tests have different numbers of test questions. When I use the reliability command I have to list the variable names for the test questions. I want to write something like Q1 to Q50. However, for some exams it will be Q1 to Q60 or Q1 to Q20 etc. For the life of me I can't figure out how to write a macro that will change the second Q. My dataset is structured like this. Here is what I have tried most recently. As it turns out the do if command has no effect on !let. (My full macro creates new files by TestID and saves the output using OMS in a format I need. I just can't run the macro if the tests have different numbers of questions.) define mac() !do !i = 1 !to 70. do if !i = NumQuestions. !let !Q=!concat(Q,!i). execute. end if. !doend. RELIABILITY /VARIABLES=Q1 to !Q /SCALE('ALL VARIABLES') ALL /MODEL=ALPHA /STATISTICS=DESCRIPTIVE SCALE. !enddefine. I am pretty stuck at this point. I really need to get this working. If anyone has any suggestions I would really appreciate the help. Not to be picky, but if possible please keep any suggestions as simple as possible. My SPSS skills are fairly basic. Thank you in advance. |
From: Brandon <[hidden email]>; To: <[hidden email]>; Subject: [SPSSX-L] Macro Help Sent: Sat, May 30, 2015 3:15:36 AM
|
In reply to this post by Brandon
You need a control structure to run the reliability analysis on each test in the data set. One technique is to make self-modifying code, by first extracting the control data you need, then create appropriate syntax. The technique is demonstrated in http://www.spsstools.net/Macros.htm#SelfAdjustingMacros.
HTH /PR DATASET CLOSE ALL. *Specify a temporary syntax file. %temp% points to Windows Standard Temp folder*. FILE HANDLE fnTemp /NAME='%temp%\TempStx.sps'. *Test data set*. DATA LIST list / PersonID TestID NumQ Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 (13F3.0). BEGIN DATA 1 1 5 1 1 1 0 1 . . . . . 2 1 5 0 1 1 1 0 . . . . . 3 1 5 1 1 1 1 0 . . . . . 4 2 7 1 0 0 0 1 0 0 . . . 5 2 7 1 0 1 1 1 1 1 . . . 6 3 7 1 1 1 1 0 0 1 . . . 7 3 7 0 1 0 0 1 0 0 . . . 8 4 10 0 0 1 0 1 1 0 0 1 0 9 4 10 0 1 1 1 0 1 1 1 1 0 10 4 10 1 1 1 0 0 0 1 1 0 1 END DATA. DATASET NAME Test. *Macro to do analysis *. DEFINE @mac(!POS !TOKENS(1) /!POS !TOKENS(1)) TEMPORARY. SELECT IF (TestID EQ !1). RELIABILITY /VARIABLES=Q1 to !CONCAT("Q", !2) /SCALE('ALL VARIABLES') ALL /MODEL=ALPHA /STATISTICS=DESCRIPTIVE SCALE. !ENDDEFINE. *Generate control dataset*. DATASET ACTIVATE Test WINDOW=ASIS. DATASET DECLARE Control. AGGREGATE /OUTFILE = Control /BREAK = TestID NumQ /Subjects = N. DATASET ACTIVATE Control WINDOW=ASIS. *Create syntax file with commands to run macro with arguments*. WRITE OUTFILE=fnTemp /"@mac " testID " " NumQ "." . EXECUTE. *Back to working data set*. DATASET ACTIVATE Test WINDOW=ASIS. *Tidy up*. DATASET CLOSE Control. *Use split file to get TestID into analysis to help navigating in output*. SPLIT FILE BY TestID. *Run the generated commands*. INSERT FILE = fnTemp. SPLIT FILE OFF. *Tidy up*. ERASE FILE = fnTemp. |
In reply to this post by Brandon
You need to use an argument in your macro.
define mac(lastQuestion = !CMDEND) !do !i = 1 !to lastQuestion) do if !i = NumQuestions. !let !Q=!concat(Q,!i). execute. end if. !doend. RELIABILITY /VARIABLES=Q1 to !Q /SCALE('ALL VARIABLES') ALL /MODEL=ALPHA /STATISTICS=DESCRIPTIVE SCALE. !enddefine. mac lastQuestion = 20. mac lastQuestion = 40. mac lastQuestion = or other number of questions. > Op 30 mei 2015 om 05:15 heeft "Brandon" <[hidden email]> het volgende geschreven: > > Hi, > > I am in a bit of a jam and I am really hoping someone can help me out. I am > trying to calculate item statistics using the RELIABILITY command for > several hundred tests that are all in one dataset. I've created a macro that > does almost everything I want it to, but I am getting hung up on one part. > Unfortunately I don't have the macro with me, but I have recreated the part > I am getting stuck on. > > The problem is these tests have different numbers of test questions. When I > use the reliability command I have to list the variable names for the test > questions. I want to write something like Q1 to Q50. However, for some exams > it will be Q1 to Q60 or Q1 to Q20 etc. For the life of me I can't figure out > how to write a macro that will change the second Q. > > My dataset is structured like this. > > <http://spssx-discussion.1045642.n5.nabble.com/file/n5729648/Capture.jpg> > > Here is what I have tried most recently. As it turns out the do if command > has no effect on !let. (My full macro creates new files by TestID and saves > the output using OMS in a format I need. I just can't run the macro if the > tests have different numbers of questions.) > > define mac() > !do !i = 1 !to 70. > do if !i = NumQuestions. > !let !Q=!concat(Q,!i). > execute. > end if. > !doend. > RELIABILITY > /VARIABLES=Q1 to !Q > /SCALE('ALL VARIABLES') ALL > /MODEL=ALPHA > /STATISTICS=DESCRIPTIVE SCALE. > !enddefine. > > I am pretty stuck at this point. I really need to get this working. If > anyone has any suggestions I would really appreciate the help. Not to be > picky, but if possible please keep any suggestions as simple as possible. My > SPSS skills are fairly basic. > > Thank you in advance. > > > > -- > View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Macro-Help-tp5729648.html > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by Brandon
This would be alot simpler if RELIABILITIES was able to use variablewise deletion. Here is a python solution though. In a nutshell this makes an aggregate dataset with the rules, then loops over that aggregate dataset and uses spss.Submit using TEMPORARY and SELECT IF statements to select only that particular subset.
**********************************************************. *Making fake dataset. INPUT PROGRAM. LOOP #i = 1 TO 100. COMPUTE NumQuest = RV.BERNOULLI(0.5)*5 + 5. END CASE. END LOOP. END FILE. END INPUT PROGRAM. DATASET NAME Test. IF NumQuest = 5 TestID = 1. IF NumQuest = 10 TestID = 2. VECTOR Q(10,F1.0). LOOP #i = 1 TO NumQuest. COMPUTE Q(#i) = RV.BERNOULLI(0.5). END LOOP. EXECUTE. *make a second dataset of the number of questions. DATASET DECLARE AggQ. AGGREGATE OUTFILE='AggQ' /BREAK TestID /NumQuest = FIRST(NumQuest). DATASET ACTIVATE AggQ. *Import aggregate data into Python. BEGIN PROGRAM Python. import spssdata alldata = spssdata.Spssdata().fetchall() print alldata END PROGRAM. *Loop through each test id, use temporary-select if, and conduct reliabilities. DATASET ACTIVATE Test. DATASET CLOSE AggQ. BEGIN PROGRAM Python. import spss from string import Template #make a string template for the reliabilities code to submit c = Template("""*Reliabilities for subsets of variables. TITLE "TestID = $TestID". TEMPORARY. SELECT IF TestID = $TestID. RELIABILITY /VARIABLES=Q1 to $QLast /SCALE('ALL VARIABLES') ALL /MODEL=ALPHA /STATISTICS=DESCRIPTIVE SCALE. EXECUTE. """) #now looping over set. for i in alldata: testid = i[0] Qend = "Q" + str(int(i[1])) spss.Submit(c.substitute(TestID=testid,QLast=Qend)) END PROGRAM. **********************************************************. |
In reply to this post by kwame woei
If the problem is just that you need to
find all the questions without having to enumerate them manually, and they
all have a recognizable pattern in the names such as Qnn were n is one
or more digits, you can use the SPSSINC SELECT VARIABLES extension command
to generate a macro that you can then use in your main macro (possibly
with !EVAL).
Here's an example: SPSSINC SELECT VARIABLES MACRONAME="!allQs" /PROPERTIES PATTERN = "Q\d+". It creates a macro named !allQs whose value will be all the variable names that start with Q followed by at least one digit. This extension command is installed with the Python Essentials in Statistics 22 or later, or you can download it from the SPSS Community website (www.ibm.com/developerworks/spssdevcentral) in the extension commands collection. Of course, it requires the Python Essentials. SPSSINC SELECT VARIABLES can be a key tool in generalizing jobs. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: kwame woei <[hidden email]> To: [hidden email] Date: 05/31/2015 10:13 AM Subject: Re: [SPSSX-L] Macro Help Sent by: "SPSSX(r) Discussion" <[hidden email]> You need to use an argument in your macro. define mac(lastQuestion = !CMDEND) !do !i = 1 !to lastQuestion) do if !i = NumQuestions. !let !Q=!concat(Q,!i). execute. end if. !doend. RELIABILITY /VARIABLES=Q1 to !Q /SCALE('ALL VARIABLES') ALL /MODEL=ALPHA /STATISTICS=DESCRIPTIVE SCALE. !enddefine. mac lastQuestion = 20. mac lastQuestion = 40. mac lastQuestion = or other number of questions. > Op 30 mei 2015 om 05:15 heeft "Brandon" <[hidden email]> het volgende geschreven: > > Hi, > > I am in a bit of a jam and I am really hoping someone can help me out. I am > trying to calculate item statistics using the RELIABILITY command for > several hundred tests that are all in one dataset. I've created a macro that > does almost everything I want it to, but I am getting hung up on one part. > Unfortunately I don't have the macro with me, but I have recreated the part > I am getting stuck on. > > The problem is these tests have different numbers of test questions. When I > use the reliability command I have to list the variable names for the test > questions. I want to write something like Q1 to Q50. However, for some exams > it will be Q1 to Q60 or Q1 to Q20 etc. For the life of me I can't figure out > how to write a macro that will change the second Q. > > My dataset is structured like this. > > <http://spssx-discussion.1045642.n5.nabble.com/file/n5729648/Capture.jpg> > > Here is what I have tried most recently. As it turns out the do if command > has no effect on !let. (My full macro creates new files by TestID and saves > the output using OMS in a format I need. I just can't run the macro if the > tests have different numbers of questions.) > > define mac() > !do !i = 1 !to 70. > do if !i = NumQuestions. > !let !Q=!concat(Q,!i). > execute. > end if. > !doend. > RELIABILITY > /VARIABLES=Q1 to !Q > /SCALE('ALL VARIABLES') ALL > /MODEL=ALPHA > /STATISTICS=DESCRIPTIVE SCALE. > !enddefine. > > I am pretty stuck at this point. I really need to get this working. If > anyone has any suggestions I would really appreciate the help. Not to be > picky, but if possible please keep any suggestions as simple as possible. My > SPSS skills are fairly basic. > > Thank you in advance. > > > > -- > View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Macro-Help-tp5729648.html > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (not to SPSSX-L), with no body text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the command > INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
I do not have all of the context, but the overall idea seems problematical.
It is customary in psychometrics to intersperse the items of different scales in the same instrument. Also, a well designed instrument would have items that need to be reflected (reversed) before being used in a summative scale The scoring keys would need to be considered in setting up RELIABITY. It makes no sense to run to treat items from different scales and that have the item response scales for a given scale not in the same direction.
Art Kendall
Social Research Consultants |
In reply to this post by Albert-Jan Roskam-2
I couldn't get this to work with what I was trying to do, but it is good to know that it is out there. Thanks for your help.
|
Free forum by Nabble | Edit this page |