DO REPEAT not allowed inside DO IF

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

DO REPEAT not allowed inside DO IF

John F Hall
Apologies for the length of this query. I spent the New Year attempting to generate an index of 'consumer deprivation' using data from a 1962 survey by the late Garry Runciman, reported in his book Relative Deprivation and Social Justice (Routledge and Kegan Paul, 1966). See my page: Relative Deprivation and Social Justice For each item in a set of consumer goods he asked: Does your household have . . . ? Yes, No, DK IF NO; Would you like . . . ? Yes, No, DK IF YES: Do you expect to get . . . in next year or so . . . ? Yes, No, DK I don't have a copy of his original questionnaire, but I used the same idea (and almost the same items) for the SSRC Survey Unit Quality of Life in Britain survey, 1975, and the same coding scheme. Fieldwork and coding for both surveys were done by Research Services Ltd (RSL) who used Donovan Data Systems for computer processing and initial analysis. The responses for each item were originally multi-punched on a single column (2 x 80-column cards per case). The codes indicated a unique series of responses for each item. The Runciman data used the + and – positions read as alpha then recoded to numeric, one code per item. 1"Yes, already have" 9 "Don't know if already have" 2 " Don't have, don't want" 8 " DK if want" 3 " 'Want and expect to get'' 4 " Want, but don't expect to get'' 5 " Want, but don't know if expect to get''  The multi-punched data were spread out as 7 separate variables in VARddd format on 7 columns of a 3rd card and entered into SPSS as VAR307 to VAR313 (all UPPER CASE and only VAR allowed in early version of SPSS). In VARddd format the first digit indicates a card (record) and the last pair the starting column of the field. FREQUENCIES VAR307 TO VAR313. . . yields the results shown in the following table :   The Runciman data were similarly coded, but the automatic archiving program at UKDS spread them out as three separate variables for each item. See: Data set: Relative Deprivation and Social Justice 1966 (UKDS SN 28) The first set of 7 consumer items was: Varname Item tv Television phone Telephone car Car or van fridge Refrigerator washmach Washing machine recordpl Record player cheating Central heating 0 'Non-response' 1 'Yes' 2 'No' If NO, ''Do you want . . ?" wanttv wantphn wantcar wantfrg wantwash wantrpl wantch 0 'not applicable' 1 'Yes' 2 'No' 3 ''Don't know'' If YES, ''Do you expect to get one soon?" tvsoon phnsoon carsoon frgsoon washsoon rplsoon chsoon 0 'not applicable' 1 'Yes' 2 'No' 3 ''Don't know'' Runciman also had a second set of 6 'aspirational' consumer items, but the SSRC QoL survey did not use these: A house of your own A fur coat for your wife Go abroad for holidays A spare bedroom for visitors 1st class travel A private education . . with an additional question: If don't expect to get: 'Do you think other people can afford . . ?"   I wanted to get the Runciman household consumer goods data into the same format as the SSRC QoL and started by trying to nest DO REPEAT inside DO IF, but SPSS does not allow this, so I had to go the long way round by specifying separately a derived variable for each item * Encoding: UTF-8. count tv1a = tv (2) wanttv (1) /tv1b = tv (2) wanttv (2) /tv1c = tv (2) wanttv (3). frequencies tv1a tv1b tv1c. compute tv1=tv. do if tv1a=2. compute tv1 =2. else if tv1b=2. compute tv1 =3. else if tv1c=2. compute tv1 =4. end if. formats tv1a to tv1 (n1). variable labels tv1 'Have/want tv'. value labels tv1 1 'Yes, already have' 2 'No, but want' 3 ''No, but don't want'' 4 ''No but don't know if want''. frequencies tv1 . [NB: I normally use abbreviated syntax] tv1 Have/want tv Frequency Percent Valid Percent Cumulative Percent Valid 1 Yes, already have 1185 83.7 83.9 83.9 2 No, but want' 65 4.6 4.6 88.5 3 No, but don't want 161 11.4 11.4 99.9 4 No, but don't know if want 2 .1 .1 100.0 Total 1413 99.9 100.0 Missing System 2 .1 Total 1415 100.0 This produced the desired coding for television, but was extremely tedious and time-consuming to repeat for each of the other 6 items in the list. I haven't even tried to do it for 'Expect to get in next year or so'   What I really need is the equivalent of the below syntax in which XX is replaced by: tv to cheating wanttv to wantch tv1 to cheating1: * Encoding: UTF-8. count XX1a = XX (2) wantXX (1) /XX1b = XX (2) wantXX (2) /XX1c = XX (2) wantXX (3). frequencies XX1a XX1b XX1c. compute XX1=XX. do if XX1a=2. compute XX1 =2. else if XX1b=2. compute XX1 =3. else if XX1c=2. compute XX1 =4. end if. formats XX1a to XX1 (n1). variable labels XX1 'Have/want XX'. value labels XX1 1 'Yes, already have' 2 'No, but want' 3 ''No, but don't want'' 4 ''No but don't know if want''. frequencies XX1 . Does anyone fancy a shot at a macro or Python code to do this? Something to pass the time during Covid lockdown and freezing weather. Thanks in advance. John F Hall MA (Cantab) Dip Ed (Dunelm) IBM-SPSS Academic Author 9900074 Email: [hidden email] Website: Journeys in Survey Research Course: Survey Analysis Workshop (SPSS)

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
Reply | Threaded
Open this post in threaded view
|

Re: DO REPEAT not allowed inside DO IF

Maguin, Eugene

Would you post a DO IF DO REPEAT syntax block that didn’t work and the error/warning messages that resulted. I’ve used that construction before and received no errors so I’m surprised it didn’t work for you.

Gene Maguin

 

From: SPSSX(r) Discussion <[hidden email]> On Behalf Of John F Hall
Sent: Friday, January 08, 2021 7:25 AM
To: [hidden email]
Subject: DO REPEAT not allowed inside DO IF

 

Apologies for the length of this query. I spent the New Year attempting to generate an index of 'consumer deprivation' using data from a 1962 survey by the late Garry Runciman, reported in his book Relative Deprivation and Social Justice (Routledge and Kegan Paul, 1966). See my page: Relative Deprivation and Social Justice For each item in a set of consumer goods he asked: Does your household have . . . ? Yes, No, DK IF NO; Would you like . . . ? Yes, No, DK IF YES: Do you expect to get . . . in next year or so . . . ? Yes, No, DK I don't have a copy of his original questionnaire, but I used the same idea (and almost the same items) for the SSRC Survey Unit Quality of Life in Britain survey, 1975, and the same coding scheme. Fieldwork and coding for both surveys were done by Research Services Ltd (RSL) who used Donovan Data Systems for computer processing and initial analysis. The responses for each item were originally multi-punched on a single column (2 x 80-column cards per case). The codes indicated a unique series of responses for each item. The Runciman data used the + and – positions read as alpha then recoded to numeric, one code per item. 1"Yes, already have" 9 "Don't know if already have" 2 " Don't have, don't want" 8 " DK if want" 3 " 'Want and expect to get'' 4 " Want, but don't expect to get'' 5 " Want, but don't know if expect to get''  The multi-punched data were spread out as 7 separate variables in VARddd format on 7 columns of a 3rd card and entered into SPSS as VAR307 to VAR313 (all UPPER CASE and only VAR allowed in early version of SPSS). In VARddd format the first digit indicates a card (record) and the last pair the starting column of the field. FREQUENCIES VAR307 TO VAR313. . . yields the results shown in the following table :   The Runciman data were similarly coded, but the automatic archiving program at UKDS spread them out as three separate variables for each item. See: Data set: Relative Deprivation and Social Justice 1966 (UKDS SN 28) The first set of 7 consumer items was: Varname Item tv Television phone Telephone car Car or van fridge Refrigerator washmach Washing machine recordpl Record player cheating Central heating 0 'Non-response' 1 'Yes' 2 'No' If NO, ''Do you want . . ?" wanttv wantphn wantcar wantfrg wantwash wantrpl wantch 0 'not applicable' 1 'Yes' 2 'No' 3 ''Don't know'' If YES, ''Do you expect to get one soon?" tvsoon phnsoon carsoon frgsoon washsoon rplsoon chsoon 0 'not applicable' 1 'Yes' 2 'No' 3 ''Don't know'' Runciman also had a second set of 6 'aspirational' consumer items, but the SSRC QoL survey did not use these: A house of your own A fur coat for your wife Go abroad for holidays A spare bedroom for visitors 1st class travel A private education . . with an additional question: If don't expect to get: 'Do you think other people can afford . . ?"   I wanted to get the Runciman household consumer goods data into the same format as the SSRC QoL and started by trying to nest DO REPEAT inside DO IF, but SPSS does not allow this, so I had to go the long way round by specifying separately a derived variable for each item * Encoding: UTF-8. count tv1a = tv (2) wanttv (1) /tv1b = tv (2) wanttv (2) /tv1c = tv (2) wanttv (3). frequencies tv1a tv1b tv1c. compute tv1=tv. do if tv1a=2. compute tv1 =2. else if tv1b=2. compute tv1 =3. else if tv1c=2. compute tv1 =4. end if. formats tv1a to tv1 (n1). variable labels tv1 'Have/want tv'. value labels tv1 1 'Yes, already have' 2 'No, but want' 3 ''No, but don't want'' 4 ''No but don't know if want''. frequencies tv1 . [NB: I normally use abbreviated syntax] tv1 Have/want tv Frequency Percent Valid Percent Cumulative Percent Valid 1 Yes, already have 1185 83.7 83.9 83.9 2 No, but want' 65 4.6 4.6 88.5 3 No, but don't want 161 11.4 11.4 99.9 4 No, but don't know if want 2 .1 .1 100.0 Total 1413 99.9 100.0 Missing System 2 .1 Total 1415 100.0 This produced the desired coding for television, but was extremely tedious and time-consuming to repeat for each of the other 6 items in the list. I haven't even tried to do it for 'Expect to get in next year or so'   What I really need is the equivalent of the below syntax in which XX is replaced by: tv to cheating wanttv to wantch tv1 to cheating1: * Encoding: UTF-8. count XX1a = XX (2) wantXX (1) /XX1b = XX (2) wantXX (2) /XX1c = XX (2) wantXX (3). frequencies XX1a XX1b XX1c. compute XX1=XX. do if XX1a=2. compute XX1 =2. else if XX1b=2. compute XX1 =3. else if XX1c=2. compute XX1 =4. end if. formats XX1a to XX1 (n1). variable labels XX1 'Have/want XX'. value labels XX1 1 'Yes, already have' 2 'No, but want' 3 ''No, but don't want'' 4 ''No but don't know if want''. frequencies XX1 . Does anyone fancy a shot at a macro or Python code to do this? Something to pass the time during Covid lockdown and freezing weather. Thanks in advance. John F Hall MA (Cantab) Dip Ed (Dunelm) IBM-SPSS Academic Author 9900074 Email: [hidden email] Website: Journeys in Survey Research Course: Survey Analysis Workshop (SPSS)


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
Reply | Threaded
Open this post in threaded view
|

Re: DO REPEAT not allowed inside DO IF

Rich Ulrich
In reply to this post by John F Hall
John,
I don't know what incompatibility there is in our software, but
I see your entire post as one paragraph -- not a single carriage return.
What I received in my Outlook email looks the same as what I find
when I go to Nabble. I copied it to an editor and reformatted it so
that I could read it.
For the benefit of anyone else who had the same problem, here
is the revised (not perfect but intelligible) version.
*   *   * [re-formatted post from John Hall]

Apologies for the length of this query. I spent the New Year attempting to generate an index of 'consumer deprivation' using data from a 1962 survey by the late Garry Runciman, reported in his book Relative Deprivation and Social Justice (Routledge and Kegan Paul, 1966).


See my page: Relative Deprivation and Social Justice

For each item in a set of consumer goods he asked:

Does your household have . . . ? Yes, No, DK

IF NO; Would you like . . . ? Yes, No, DK

IF YES: Do you expect to get . . . in next year or so . . . ? Yes, No, DK


I don't have a copy of his original questionnaire, but I used the same idea (and almost the same items) for the SSRC Survey Unit Quality of Life in Britain survey, 1975, and the same coding scheme. Fieldwork and coding for both surveys were done by Research Services Ltd (RSL) who used Donovan Data Systems for computer processing and initial analysis. The responses for each item were originally multi-punched on a single column (2 x 80-column cards per case). The codes indicated a unique series of responses for each item.


The Runciman data used the + and – positions read as alpha then recoded to numeric, one code per item. 1"Yes, already have" 9 "Don't know if already have" 2 " Don't have, don't want" 8 " DK if want" 3 " 'Want and expect to get'' 4 " Want, but don't expect to get'' 5 " Want, but don't know if expect to get'' 


The multi-punched data were spread out as 7 separate variables in VARddd format on 7 columns of a 3rd card and entered into SPSS as VAR307 to VAR313 (all UPPER CASE and only VAR allowed in early version of SPSS).


In VARddd format the first digit indicates a card (record) and the last pair the starting column of the field.


FREQUENCIES VAR307 TO VAR313. . . yields the results shown in the following table :  


The Runciman data were similarly coded, but the automatic archiving program at UKDS spread them out as three separate variables for each item. See: Data set: Relative Deprivation and Social Justice 1966 (UKDS SN 28)


The first set of 7 consumer items was:

Varname Item tv Television phone Telephone car Car or van fridge Refrigerator washmach Washing machine recordpl Record player cheating Central heating 0 'Non-response' 1 'Yes' 2 'No'

If NO, ''Do you want . . ?" wanttv wantphn wantcar wantfrg wantwash wantrpl wantch 0 'not applicable' 1 'Yes' 2 'No' 3 ''Don't know''

If YES, ''Do you expect to get one soon?" tvsoon phnsoon carsoon frgsoon washsoon rplsoon chsoon 0 'not applicable' 1 'Yes' 2 'No' 3 ''Don't know''


Runciman also had a second set of 6 'aspirational' consumer items, but the SSRC QoL survey did not use these: A house of your own A fur coat for your wife Go abroad for holidays A spare bedroom for visitors 1st class travel A private education . . with an additional question: If don't expect to get: 'Do you think other people can afford . . ?"  


I wanted to get the Runciman household consumer goods data into the same format as the SSRC QoL and started by trying to nest DO REPEAT inside DO IF, but SPSS does not allow this, so I had to go the long way round by specifying separately a derived variable for each item


Encoding: UTF-8.


count tv1a = tv (2) wanttv (1) /tv1b = tv (2) wanttv (2) /tv1c = tv (2) wanttv (3).

frequencies tv1a tv1b tv1c.

compute tv1=tv.

do if tv1a=2.

compute tv1 =2.

else if tv1b=2.

compute tv1 =3.

else if tv1c=2.

compute tv1 =4. end if.

formats tv1a to tv1 (n1).

variable labels tv1 'Have/want tv'.

value labels tv1 1 'Yes, already have' 2 'No, but want' 3 ''No, but don't want'' 4 ''No but don't know if want''.

frequencies tv1 .

[NB: I normally use abbreviated syntax]tv1 Have/want tv

Frequency Percent Valid Percent Cumulative Percent Valid

1 Yes, already have 1185 83.7 83.9 83.9

2 No, but want' 65 4.6 4.6 88.5

3 No, but don't want 161 11.4 11.4 99.9

4 No, but don't know if want 2 .1 .1 100.0

Total 1413 99.9 100.0

Missing System 2 .1 Total 1415 100.0


This produced the desired coding for television, but was extremely tedious and time-consuming to repeat for each of the other 6 items in the list. I haven't even tried to do it for 'Expect to get in next year or so'  


What I really need is the equivalent of the below syntax in which XX is replaced by: tv to cheating wanttv to wantch tv1 to cheating1: * Encoding: UTF-8.

count XX1a = XX (2) wantXX (1) /XX1b = XX (2) wantXX (2) /XX1c = XX (2) wantXX (3).


frequencies XX1a XX1b XX1c.

compute XX1=XX.

do if XX1a=2.

compute XX1 =2.

else if XX1b=2.

compute XX1 =3.

else if XX1c=2.

compute XX1 =4.

end if.

formats XX1a to XX1 (n1).

variable labels XX1 'Have/want XX'.

value labels XX1 1 'Yes, already have' 2 'No, but want' 3 ''No, but don't want'' 4 ''No but don't know if want''.

frequencies XX1 .


Does anyone fancy a shot at a macro or Python code to do this? Something to pass the time during Covid lockdown and freezing weather.

Thanks in advance.

John F Hall MA (Cantab) Dip Ed (Dunelm) IBM-SPSS Academic Author 9900074 Email: [hidden email] Website: Journeys in Survey Research Course: Survey Analysis Workshop (SPSS)



===================== 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