|
Hi, I have a list of variables that take value 1 or 2. The variables have consecutives names. As I can add variables as long as a condition is met .(ex. 1 or 2).
=====================
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 try this: DO REPEAT x=g75 to g84. Do if (x=1). compute y=sum(x)./* I want sum (g75 to g84) only when take value=1 END IF. END REPEAT. Javier. |
|
Administrator
|
Does this do what you want?
COUNT Y1 = g75 to g84 (1). COUNT Y2 = g75 to g84 (2). COUNT Y1or2 = g75 to g84 (1 2). FORMATS Y1 to Y1or2 (F2.0). DESCRIPTIVES Y1 to Y1or2.
--
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/). |
|
In reply to this post by Javier Meneses
It’s not clear exactly what you want, but how about. . ? count x = g75 to g85 (1). freq x. John F Hall (Mr) [Retired academic survey researcher] Email: [hidden email] Website: www.surveyresearch.weebly.com SPSS start page: www.surveyresearch.weebly.com/1-survey-analysis-workshop From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of javier meneses Hi, I have a list of variables that take value 1 or 2. The variables have consecutives names. As I can add variables as long as a condition is met .(ex. 1 or 2). I try this: DO REPEAT x=g75 to g84. Do if (x=1). compute y=sum(x)./* I want sum (g75 to g84) only when take value=1 END IF. END REPEAT. Javier. ===================== 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
|
In reply to this post by Javier Meneses
As Bruce and John have pointed out COUNT is quite useful.
OTOH, your syntax is incorrect. The following will do what you seem to want. DO REPEAT x=g75 TO g84. IF (x EQ 1) y=SUM(y,x). END REPEAT. Alternatively DO REPEAT x=g75 TO g84. COMPUTE y= SUM(y,(x EQ 1)). END REPEAT. Note that SUM does NOT require y to be initialized as it would if you were to use: COMPUTE y=y+(x EQ 1). OTOH: For this case you will want to look at the utility of the COUNT command.
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?" |
|
In reply to this post by Bruce Weaver
Genial Bruce, Thank. 2016-02-10 13:04 GMT-03:00 Bruce Weaver <[hidden email]>: Does this do what you want? |
|
Alternatively: Recode
g75 to g84 (1=1) (2=0). Compute y=sum(g75 to g84). Yes it would be safer to recode into-but I didn’t have time to test. Melissa From: SPSSX(r) Discussion [mailto:[hidden email]]
On Behalf Of javier meneses Genial Bruce, Thank. 2016-02-10 13:04 GMT-03:00 Bruce Weaver <[hidden email]>:
===================== 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
This correspondence contains proprietary information some or all of which may be legally privileged; it is for the intended recipient only. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this correspondence and completely dispose of the correspondence immediately. Please notify the sender if you have received this email in error. NOTE: Messages to or from the State of Connecticut domain may be subject to the Freedom of Information statutes and regulations. ===================== 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 |
|
Considering that the SUM of '1's is the same as the COUNT of '1's, I believe this can be done with COUNT, requiring neither recode nor sums.Count Y = g75 TO g84 (1). On Thu, Mar 10, 2016 at 8:58 AM, Ives, Melissa L <[hidden email]> wrote:
|
| Free forum by Nabble | Edit this page |
