SPSS 17 Vista
I've a problem concatenating a string and a number in order to receive the content of an array. The program (excerpt) goes like that: name="z"+str(j) print name Instead of printing the array (please see below for the whole program) it only prints "z1". However, it should print: ['ouse', 'ous', 'use','aus'] Here is the whole program: * Python Beispiel 2 DATA LIST FREE / ID (f8.0) v1 (a20) v2 (a20) v3 (a20) v4 (a20) v5 (a20). BEGIN DATA 1 haus ext hose hemd schlips 2 ext house hose tower pferd 3 tower house ext schaukel schlips END DATA. BEGIN PROGRAM. import spss z0=(['ouse', 'ous', 'use','aus']) z1=(['ext', 'tex', 'te','xt']) z2=(['ower', 'auk', 'ips']) z3=(['sonst', 'alles', 'nichts']) for j in range(4): i=0 name="z"+str(j) print name for i in range(len(name)): variable=name[i] print variable spss.Submit(r""" do repeat #i =v1 to v5. if INDEX(#i,'"""+variable+"""') >0 v_"""+str(j)+"""=1. end repeat. EXECUTE . """) END PROGRAM. I can't find the solution in python.
Dr. Frank Gaeth
|
I'm out of the office until August 8th. While I'm out, Mike O'Neil will be filling in for me. You can reach him at 865-974-8333 or [hidden email]. Cheers, Bob
|
In reply to this post by drfg2008
name is not an array. It's
a string with values like z1. So printing it just prints 'z1'. And
since a string is indexable, zi[0], say, would just print "z".
One way to get what you want is to define another variable that lists the names: namelist = [z0, z1, z2, z3] and then index that structure. HTH, Jon Peck Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: drfg2008 <[hidden email]> To: [hidden email] Date: 07/31/2011 02:39 PM Subject: [SPSSX-L] python: concat strings Sent by: "SPSSX(r) Discussion" <[hidden email]> SPSS 17 Vista I've a problem concatenating a string and a number in order to receive the content of an array. The program (excerpt) goes like that: name="z"+str(j) print name Instead of printing the array (please see below for the whole program) it only prints "z1". However, it should print: ['ouse', 'ous', 'use','aus'] Here is the whole program: * Python Beispiel 2 DATA LIST FREE / ID (f8.0) v1 (a20) v2 (a20) v3 (a20) v4 (a20) v5 (a20). BEGIN DATA 1 haus ext hose hemd schlips 2 ext house hose tower pferd 3 tower house ext schaukel schlips END DATA. BEGIN PROGRAM. import spss z0=(['ouse', 'ous', 'use','aus']) z1=(['ext', 'tex', 'te','xt']) z2=(['ower', 'auk', 'ips']) z3=(['sonst', 'alles', 'nichts']) for j in range(4): i=0 name="z"+str(j) print name for i in range(len(name)): variable=name[i] print variable spss.Submit(r""" do repeat #i =v1 to v5. if INDEX(#i,'"""+variable+"""') >0 v_"""+str(j)+"""=1. end repeat. EXECUTE . """) END PROGRAM. I can't find the solution in python. ----- Dr. Frank Gaeth FU-Berlin -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/python-concat-strings-tp4653128p4653128.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 |
thanks!
However, in the following version (please see below) the result is the same: BEGIN PROGRAM. import spss v_list = (['v_0', 'v_1', 'v_2', 'v_3']) v_0=(['ouse', 'ous', 'use']) v_1=(['ext', 'tex', 'te','xt']) v_2=(['ower', 'auk', 'ips','ups','aps']) v_3=(['sonst', 'sonst', 'nichts','nix','hallo','sechs']) anzahl1 = len(v_list) print "Umfang der Variablenliste: "+ str(anzahl1) print "Die Variablen sind: " for i in range(anzahl1): print "this only prints a string: " print v_list[i] print "this prints the array: " print v_0 laenge_name1=len(v_list[i]) print i END PROGRAM.
Dr. Frank Gaeth
|
That's not what I meant, You need
to list the actual objects, not literals representing their names:
v_list = [v_0, v_1, v_2, v_3] Jon Peck Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: drfg2008 <[hidden email]> To: [hidden email] Date: 08/01/2011 01:15 AM Subject: Re: [SPSSX-L] python: concat strings Sent by: "SPSSX(r) Discussion" <[hidden email]> thanks! However, in the following version (please see below) the result is the same: BEGIN PROGRAM. import spss v_list = (['v_0', 'v_1', 'v_2', 'v_3']) v_0=(['ouse', 'ous', 'use']) v_1=(['ext', 'tex', 'te','xt']) v_2=(['ower', 'auk', 'ips','ups','aps']) v_3=(['sonst', 'sonst', 'nichts','nix','hallo','sechs']) anzahl1 = len(v_list) print "Umfang der Variablenliste: "+ str(anzahl1) print "Die Variablen sind: " for i in range(anzahl1): print "this only prints a string: " print v_list[i] print "this prints the array: " print v_0 laenge_name1=len(v_list[i]) print i END PROGRAM. ----- Dr. Frank Gaeth FU-Berlin -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/python-concat-strings-tp4653128p4654203.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 |
Thanks, now it works. DATA LIST FREE / ID (f8.0) v1 (a20) v2 (a20) v3 (a20) v4 (a20) v5 (a20). BEGIN DATA 1 haus ext hose hemd schlips 2 ext house hose tower pferd 3 tower house ext schaukel schlips END DATA. BEGIN PROGRAM. import spss v_0=(['ouse', 'ous', 'use']) v_1=(['ext', 'tex', 'te','xt']) v_2=(['ower', 'auk', 'ips','ups','aps']) v_3=(['sonst', 'sonst', 'nichts','nix','hallo','sechs']) v_list = [v_0, v_1, v_2, v_3] for i in range(len(v_list)): name=v_list[i] print name for k in range(len(name)): variable=name[k] print variable spss.Submit(r""" do repeat #i =v1 to v5. if INDEX(#i,'"""+variable+"""') >0 v_"""+str(i)+"""=1. end repeat. EXECUTE . """) END PROGRAM.
Dr. Frank Gaeth
|
Administrator
|
What is this supposed to actually do? I'll bet straight SPSS syntax would be a lot more readable!!!
Python seems to be a *first* resort for you rather than a 'solution' for when straight SPSS is difficult to achieve. ---
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?" |
Hi David,
why not using Python as first resort. If you come from a php-background, this is quite natural. Maybe you sometimes mess up things in Python (as I did in this example). However, Python provides interesting opportunities. I was asked to provide a solution for the following problem: You have 5 (or more) string variables. Over all 5 variables it should be checked if there are certain strings. For example: if 'ouse', 'ous', 'use' etc. exist in on of the 5 (or more) variables, a check-variable (for example "HOUSE") should get a "1". Plus, the syntax should be as short as possible. Frank
Dr. Frank Gaeth
|
Administrator
|
Re why not Python as a first resort, I think it depends on what you are doing. If you are writing code for general use by other folks you need to bear in mind the following: 1) Some folks (e.g., David) are using pre-Python versions of SPSS; 2) many folks with post-Python versions don't use Python, and may even be unable install it--e.g., it is not available in the student computer labs at my university.
The question you describe below sounds like the same one that was sent to the usenet newsgroup recently. I posted a native SPSS solution there (using LOOP inside of a DO-REPEAT). https://groups.google.com/d/topic/comp.soft-sys.stat.spss/uqHB1prBpKw/discussion Now donning my flame-proof jump-suit as I await responses from the APA--Association of Python Apologists. ;-)
--
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/). |
-post-Python versions ?
Do I understand, that later versions (my version is SPSS 17) do not integrate Python?
Dr. Frank Gaeth
|
Administrator
|
Bad description. I meant Python-capable versions.
--
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/). |
The question you describe below sounds like the same one that was sent to the usenet newsgroup recently.
Thanks for the link. Yes. She obviously posted the same question again on a german SPSS mailing list. Hm.
Dr. Frank Gaeth
|
Administrator
|
In reply to this post by Bruce Weaver
Besides 1 and 2, it unnecessarily
3. obfuscates otherwise perfectly readable code. 4. introduces a non standard undocumented layer of difficult to maintain code. --- Reminds me of the good old days when we had an external consultant using VB6 who had recently discovered the Windows API. He really barely knew squat about either VB6 or the Win-API. When it came time for reviewing his code he had created a half assed attempt at rewriting basic functionality of VB6 using API functions (very few comments and incredibly poor code quality etc). Pretty sad as there were serious showstopper bugs in his code and it took him 2 days to write what I would have written in 2 hours. Took me half a day to fix his garbage after we canned his ass. Now, I used the API ALL the time *WHEN* it was *NECESSARY* ie, no built in alternative in the language. I have no fundamental objections to using Python (when it is necessary), but not for basic simple things. If you need to query the data dictionary it seems like a necessary recourse. OTOH, if you are just trying to achieve something which can be done in simple syntax then it is putting the cart before the horse. Who is going to maintain/fix your python rewrite of SPSS after you are gone???
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?" |
Let's not smear Python with an incompetent
VB consultant.
In this particular example, the Statistics macro is pretty simple, but often the Python code is simpler, clearer, and easier to maintain. Jon Peck Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: David Marso <[hidden email]> To: [hidden email] Date: 08/03/2011 09:02 AM Subject: Re: [SPSSX-L] python: concat strings Sent by: "SPSSX(r) Discussion" <[hidden email]> Besides 1 and 2, it unnecessarily 3. obfuscates otherwise perfectly readable code. 4. introduces a non standard undocumented layer of difficult to maintain code. --- Reminds me of the good old days when we had an external consultant using VB6 who had recently discovered the Windows API. He really barely knew squat about either VB6 or the Win-API. When it came time for reviewing his code he had created a half assed attempt at rewriting basic functionality of VB6 using API functions (very few comments and incredibly poor code quality etc). Pretty sad as there were serious showstopper bugs in his code and it took him 2 days to write what I would have written in 2 hours. Took me half a day to fix his garbage after we canned his ass. Now, I used the API ALL the time *WHEN* it was *NECESSARY* ie, no built in alternative in the language. I have no fundamental objections to using Python (when it is necessary), but not for basic simple things. If you need to query the data dictionary it seems like a necessary recourse. OTOH, if you are just trying to achieve something which can be done in simple syntax then it is putting the cart before the horse. Who is going to maintain/fix your python rewrite of SPSS after you are gone??? Bruce Weaver wrote: > > Re why not Python as a first resort, I think it depends on what you are > doing. If you are writing code for general use by other folks you need to > bear in mind the following: 1) Some folks (e.g., David) are using > pre-Python versions of SPSS; 2) many folks with post-Python versions don't > use Python, and may even be unable install it--e.g., it is not available > in the student computer labs at my university. > > The question you describe below sounds like the same one that was sent to > the usenet newsgroup recently. I posted a native SPSS solution there > (using LOOP inside of a DO-REPEAT). > > > https://groups.google.com/d/topic/comp.soft-sys.stat.spss/uqHB1prBpKw/discussion > > Now donning my flame-proof jump-suit as I await responses from the > APA--Association of Python Apologists. ;-) > > > > drfg2008 wrote: >> >> Hi David, >> why not using Python as first resort. If you come from a php-background, >> this is quite natural. Maybe you sometimes mess up things in Python (as I >> did in this example). However, Python provides interesting opportunities. >> >> I was asked to provide a solution for the following problem: You have 5 >> (or more) string variables. Over all 5 variables it should be checked if >> there are certain strings. For example: if 'ouse', 'ous', 'use' etc. >> exist in on of the 5 (or more) variables, a check-variable (for example >> "HOUSE") should get a "1". Plus, the syntax should be as short as >> possible. >> >> Frank >> > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/python-concat-strings-tp4653128p4662500.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 |
In reply to this post by David Marso
Took me half a day to fix his garbage after we canned his ass. Who is going to maintain/fix your python rewrite of SPSS after you are gone???
Well, they better don't can my ass. (thanks for the nice expression ;-) Frank
Dr. Frank Gaeth
|
Administrator
|
This could be the start of a new career for you, David. ESSL--English Slang as a Second Language. Reminds me of Robin Williams in Good Morning Vietnam. ;-)
http://www.youtube.com/watch?v=jNtpc-D6nqU
--
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/). |
Hi all,
I'm working through the example for using repeated measures in mixed models in Norusis "advanced statistical procedures companion". this has been a very helpful reference (but would be more helpful if syntax were listed versus drop downs) on pages 235 -240 there is an example of "time" being entered as a fixed effect in a mixed design model of repeated measures. the variable is categorical with values of 0,1,2,3. When this is entered as a fixed effect, the results show a factor with 3 df but only gives 1 F-value associated with this effect. Using my own data, when i enter a time variable with 5 levels, it's treating this as a categorical variable and giving me an estimate for each level of time. below is the syntax. is there something that needs to be included for this procedure to differentiate wanting the effects of the variable as a whole versus each level of the variable? thanks carol MIXED dv BY time /CRITERIA = CIN(95) MXITER(100) MXSTEP(5) SCORING(1) SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE) /FIXED = time | SSTYPE(3) /METHOD = REML /PRINT = SOLUTION TESTCOV /RANDOM INTERCEPT | SUBJECT(SubID) COVTYPE(VC) . ===================== 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 |
Administrator
|
Hi Carol,
Does MIXED dv WITH time ... rather than MIXED dv BY time do the trick? HTH, David ---
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?" |
it sure does!
thank you Carol -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso Sent: Thursday, August 04, 2011 11:26 AM To: [hidden email] Subject: Re: mixed models example in norusis Hi Carol, Does MIXED dv WITH time ... rather than MIXED dv BY time do the trick? HTH, David --- Parise, Carol A. wrote: > > Hi all, > > > I'm working through the example for using repeated measures in mixed > models in Norusis "advanced statistical procedures companion". this > has been a very helpful reference (but would be more helpful if syntax > were listed versus drop downs) > > on pages 235 -240 there is an example of "time" being entered as a > fixed effect in a mixed design model of repeated measures. the > variable is categorical with values of 0,1,2,3. > > When this is entered as a fixed effect, the results show a factor with > 3 df but only gives 1 F-value associated with this effect. > > Using my own data, when i enter a time variable with 5 levels, it's > treating this as a categorical variable and giving me an estimate for > each level of time. > > below is the syntax. > > is there something that needs to be included for this procedure to > differentiate wanting the effects of the variable as a whole versus > each level of the variable? > > thanks > carol > > > MIXED > dv BY time > /CRITERIA = CIN(95) MXITER(100) MXSTEP(5) SCORING(1) > SINGULAR(0.000000000001) HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) > PCONVERGE(0.000001, ABSOLUTE) > /FIXED = time | SSTYPE(3) > /METHOD = REML > /PRINT = SOLUTION TESTCOV > /RANDOM INTERCEPT | SUBJECT(SubID) COVTYPE(VC) . > > ===================== > 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 > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/python-concat-strings-tp4653128p4667418.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 |
Carol,
Have you looked at the Examples section of the MIXED chapter in the Syntax Reference? That has some syntax similar to what you're working with. Alex |
Free forum by Nabble | Edit this page |