Hey there.
I want to average 4 variables that have some missings. I don't want to lose all variables with only 1 missing value. How do I tell SPSS this? IF 4 values are present: then average 4 values (standard) IF only 3 values are present: then average only 3. IF less than 3 values present: code as missing. Thanks T ===================== 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 |
You want the compute mean function. It looks like this:
COMPUTE testv=MEAN(var1,var2). If you want to make sure it computes the mean only when at least X number of variables are present (since this would literally give you the mean of 1 variable if all others are missing), include a .# after the mean. Compute testv=mean.3(var1, var2, var3, var4) In the above example you get the mean of the 4 variables, and the mean is based on the valid non-missing. However, if a case is missing more than 1 of the variable, it will make it a sysmis. Matthew J Poes Research Data Specialist Center for Prevention Research and Development University of Illinois 510 Devonshire Dr. Champaign, IL 61820 Phone: 217-265-4576 email: [hidden email] -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Torvon Sent: Friday, October 05, 2012 1:29 PM To: [hidden email] Subject: Average 4 variables, but take into account missings Hey there. I want to average 4 variables that have some missings. I don't want to lose all variables with only 1 missing value. How do I tell SPSS this? IF 4 values are present: then average 4 values (standard) IF only 3 values are present: then average only 3. IF less than 3 values present: code as missing. Thanks T ===================== 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 torvon
something like this
untested syntax should work.
compute avg_x = mean.3 (x1 to x4). recode avg_x (sysmis = -1). missing values avg_x (-1). value labels avg_x -1 'too few values to get valid average'. Art Kendall Social Research ConsultantsOn 10/5/2012 2:29 PM, Torvon wrote: Hey there. I want to average 4 variables that have some missings. I don't want to lose all variables with only 1 missing value. How do I tell SPSS this? IF 4 values are present: then average 4 values (standard) IF only 3 values are present: then average only 3. IF less than 3 values present: code as missing. Thanks T ===================== 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
Art Kendall
Social Research Consultants |
In reply to this post by torvon
untested
COMPUTE AVG = (V1 + V2+ V3 + V4) / 4. IF V1 = SYSMIS(V1) AVG = (V2 + V3 + V4) / 3. IF V2 = SYSMIS(V2) AVG = (V1 + V3 + V4) / 3. IF V3 = SYSMIS(V3) AVG = (V2 + V1 + V4) / 3. IF V4 = SYSMIS(V4) AVG = (V2 + V3 + V1) / 3. IF V1 = SYSMIS(V1) AND V2 = SYSMIS(V2) AVG = SYSMIS(AVG). IF V1 = SYSMIS(V1) AND V3 = SYSMIS(V2) AVG = SYSMIS(AVG). IF V1 = SYSMIS(V1) AND V4 = SYSMIS(V2) AVG = SYSMIS(AVG). IF V1 = SYSMIS(V2) AND V3 = SYSMIS(V2) AVG = SYSMIS(AVG). IF V1 = SYSMIS(V2) AND V4 = SYSMIS(V2) AVG = SYSMIS(AVG). IF V1 = SYSMIS(V3) AND V4 = SYSMIS(V2) AVG = SYSMIS(AVG). |
In reply to this post by torvon
Use the mean function and specify the minimum
number of nonmissing values, .e.g.
compute avg = mean.3(v1 to v4). (or list the variables explicitly. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: Torvon <[hidden email]> To: [hidden email] Date: 10/05/2012 12:32 PM Subject: [SPSSX-L] Average 4 variables, but take into account missings Sent by: "SPSSX(r) Discussion" <[hidden email]> Hey there. I want to average 4 variables that have some missings. I don't want to lose all variables with only 1 missing value. How do I tell SPSS this? IF 4 values are present: then average 4 values (standard) IF only 3 values are present: then average only 3. IF less than 3 values present: code as missing. Thanks T ===================== 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 Art Kendall
"something like this tested syntax will work."
data list free / v1 to v4. begin data 1 2 3 5 1 2 3 . 1 2 . . 1 . . . . 1 2 3 . . 1 2 . . . 1 end data. COMPUTE AVG3=MAX(-1,MEAN.3(v1 TO v4)). MISSING VALUES AVG3 (-1). LIST. V1 V2 V3 V4 AVG3 1.000000 2.000000 3.000000 5.000000 2.750000 1.000000 2.000000 3.000000 . 2.000000 1.000000 2.000000 . . -1.00000 1.000000 . . . -1.00000 . 1.000000 2.000000 3.000000 2.000000 . . 1.000000 2.000000 -1.00000 . . . 1.000000 -1.00000 Number of cases read: 7 Number of cases listed: 7
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?" |
Administrator
|
In reply to this post by Art Kendall
I like Art's use of a user-defined missing value here, because the reason for the "missingness" is known. But bear in mind that depending on the range of possible values for v1 to v4, -1 might not be a good choice of that user-defined value. The general idea is to use some clearly out of range value. Also, 9 or some variation on it (e.g., -9, 99, 999 etc) is often used to indicate missing.
HTH.
--
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/). |
Administrator
|
In reply to this post by JKRockStomper
"untested"???
Clearly not tested!!! Please review the functions provided in SPSS . MEAN, SUM ... MEAN.n etc... --- V1 V2 V3 V4 AVG 1.000000 2.000000 3.000000 5.000000 2.750000 1.000000 2.000000 3.000000 . . 1.000000 2.000000 . . . 1.000000 . . . . . 1.000000 2.000000 3.000000 . . . 1.000000 2.000000 . . . . 1.000000 . Number of cases read: 7 Number of cases listed: 7
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?" |
Administrator
|
In reply to this post by Bruce Weaver
I do as well. I think I will adopt -666 as my choice.
COMPUTE AVG3=MAX(-666,MEAN.3(v1 TO v4)). MISSING VALUES AVG3 (-666).
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?" |
Free forum by Nabble | Edit this page |