|
Hi,
I'm a newbie with syntax so am struggling with this problem and would like to ask for your help. I have a data set and am trying to replace missing values for certain variables but only where respondents are males.
I thought I could do an IF THEN statement like the following (males are coded as "1") but my sad little syntax doesn't work:
IF sex=1 THEN
RMV /Var1=SMEAN(Var1_1).
EXECUTE.
Is it possible to do a conditional replacement of missing values? Thank you.
josey
|
|
Where is your:
END IF.
|
|
Thanks for the suggestion. I revised the syntax to include END IF before EXECUTE but sadly it still doesn't work.
joesy
On Mon, Jul 19, 2010 at 2:46 PM, MaxJasper <[hidden email]> wrote:
|
|
Dear Joesy,
The syntax I expected to work is: do IF sex=1.
RMV /Var1=SMEAN(Var1).
end if.
EXECUTE.
However, the RMV procedure indicates it's incompatible with a do if statement. A workaround (that preserves your variable and value labels) could be:
*Create test data.
data list free/sex var1.
begin data 1 '' 1 2 1 3 0 '' 0 2 0 3 end data. *Label test data.
variable labels var1"Test score on very difficult statistics examn".
value labels sex 1'male'0'female'/var1 1'Bad'2'Medium'3'Good'. *Copy variable for RMV procedure.
compute copy_var1=var1.
*RMV procedure.
RMV /copy_Var1=SMEAN(Var1). *Here comes the 'if' statement.
if sex=1 var1=copy_var1.
*The last command, delete variables, won't work if you don't use EXECUTE here, therefore.
EXECUTE.
*We don't need the copy anymore, so.
delete variables copy_var1.
*Happy end ;-).
Ruben van den Berg Consultant Models & Methods TNS NIPO Email: [hidden email] Mobiel: +31 6 24641435 Telefoon: +31 20 522 5738 Internet: www.tns-nipo.com Date: Mon, 19 Jul 2010 16:43:08 -1000 From: [hidden email] Subject: Re: How to replace missing values for selective variables only for male respondents? To: [hidden email] Thanks for the suggestion. I revised the syntax to include END IF before EXECUTE but sadly it still doesn't work.
joesy
On Mon, Jul 19, 2010 at 2:46 PM, MaxJasper <[hidden email]> wrote:
New Windows 7: Find the right PC for you. Learn more. |
|
In reply to this post by Java Joe
Dear Joesy,
Perhaps more appropriate than my first suggestion, is the solution below. It computes the means for each sex separately which is probably more to your liking. Best, Ruben van den Berg Consultant Models & Methods TNS NIPO Email: [hidden email] Mobiel: +31 6 24641435 Telefoon: +31 20 522 5738 Internet: www.tns-nipo.com *Create test data. data list free/sex var1. begin data 1 '' 1 2 1 3 0 '' 0 1 0 3 end data. *Label test data. variable labels var1"Test score on very difficult statistics examn". value labels sex 1'male'0'female'/var1 1'Bad'2'Medium'3'Good'. *Create means conditional on sex. aggregate /outfile =* mode addvariables /break sex /mean_var1_sex=mean(var1). *Here comes the 'if' statement. if sex=1 and mis(var1)=1 var1=mean_var1_sex. *The last command, delete variables, won't work if you don't use EXECUTE here, therefore. EXECUTE. *We don't need the means anymore, so. delete variables mean_var1_sex. *Happy end ;-). Date: Mon, 19 Jul 2010 16:43:08 -1000 From: [hidden email] Subject: Re: How to replace missing values for selective variables only for male respondents? To: [hidden email] Thanks for the suggestion. I revised the syntax to include END IF before EXECUTE but sadly it still doesn't work.
joesy
On Mon, Jul 19, 2010 at 2:46 PM, MaxJasper <[hidden email]> wrote:
Ruben van den Berg Consultant Models & Methods TNS NIPO Email: [hidden email] Mobiel: +31 6 24641435 Telefoon: +31 20 522 5738 Internet: www.tns-nipo.com Date: Mon, 19 Jul 2010 16:43:08 -1000 From: [hidden email] Subject: Re: How to replace missing values for selective variables only for male respondents? To: [hidden email] Thanks for the suggestion. I revised the syntax to include END IF before EXECUTE but sadly it still doesn't work.
joesy
On Mon, Jul 19, 2010 at 2:46 PM, MaxJasper <[hidden email]> wrote:
Express yourself instantly with MSN Messenger! MSN Messenger |
|
Thank you very much for the syntax examples! I think I need to learn more about syntax commands to be able to write them as well as you and others on this forum but it's really awesome to see what syntax can do.
Thank you!
joesy
On Mon, Jul 19, 2010 at 9:19 PM, Ruben van den Berg <[hidden email]> wrote:
|
|
Administrator
|
In reply to this post by Java Joe
You've had some responses showing you HOW to impute the mean where data are missing. But I don't think anyone has asked WHY you are imputing the mean. Nowadays, it is considered a very poor choice by those who work in the area of missing data. Here are a couple fairly readable articles you could take a look at, for example. http://folk.ntnu.no/slyderse/medstat/KLMED8006/Shafer.pdf http://oregonstate.edu/~acock/growth-curves/working%20with%20missing%20values.pdf 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/). |
|
In reply to this post by Java Joe
Java Joe,
I'm surprised that nobody pointed out one of the two direct methods. As you've discovered, spss doesn't use a 'then' keyword in the context of an 'if' command. Furthermore, you may have discovered the a 'do if' command won't work either. One direct method is Temporary. Select if (sex eq 1). RMV /Var1=SMEAN(Var1_1). There is another command that can be used and is functionally equivalent to the 'temporary. Select if' sequence but I can't remember it now, perhaps because I never use it. Gene Maguin >>I'm a newbie with syntax so am struggling with this problem and would like to ask for your help. I have a data set and am trying to replace missing values for certain variables but only where respondents are males. I thought I could do an IF THEN statement like the following (males are coded as "1") but my sad little syntax doesn't work: IF sex=1 THEN RMV /Var1=SMEAN(Var1_1). EXECUTE. Is it possible to do a conditional replacement of missing values? Thank you. josey ===================== 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 |
|
Ruben,
Well, well, I learned something. I've never used RMV but I skimmed through the documentation before posting and, while I didn't see any statement about an interaction with temporary. Select if., I easily might have missed it. Temporary. Select if works with procedures such as frequencies, crosstabs, regression etc. I'll bet the key issue is that rmv creates new variables, unlike frequencies or crosstabs, and there's a logical conflict between the meaning of 'temporary' and the creation of new variables and which didn't occur to me at the time. Gene Maguin ________________________________ From: Ruben van den Berg [mailto:[hidden email]] Sent: Tuesday, July 20, 2010 12:58 PM To: Gene Maguin Subject: RE: How to replace missing values for selective variables only for male respondents? Dear Gene, I tried your suggestion but it's not working. I get the warning: Warnings This procedure is supposed to save new variables. However, because a TEMPORARY command is in effect the saving cannot be done. Rerun without a TEMPORARY command. This command not executed. My guess is that RMV is a procedure rather than a transformation command, which is why it won't work within [do if./end if.] or [temp.sel if.] or [do repeat.end repeat.]. But perhaps I missed something? My complete syntax has been pasted below. Best, Ruben van den Berg Consultant Models & Methods TNS NIPO Email: [hidden email] Mobiel: +31 6 24641435 Telefoon: +31 20 522 5738 Internet: www.tns-nipo.com data list free/sex var1. begin data 1 '' 1 2 1 3 0 '' 0 1 0 3 end data. Temporary. Select if (sex eq 1). RMV /Var1=SMEAN(Var1). ________________________________ New Windows 7: Find the right PC for you. Learn more. <http://windows.microsoft.com/shop> ===================== 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 Java Joe
Many thanks for Bruce Weaver for the articles on missing values and Gene Maguin for the syntax.
To answer Bruce Weaver's question on why I was imputing the mean, it was because I noticed the "Replace Missing Values" option listed under the SPSS Transform submenu and wanted to try it out. ;)
joesy
-----Original Message-----
You've had some responses showing you HOW to impute the mean where data are missing. But I don't think anyone has asked WHY you are imputing the mean. Nowadays, it is considered a very poor choice by those who work in the area of missing data. Here are a couple fairly readable articles you could take a look at, for example.
http://folk.ntnu.no/slyderse/medstat/KLMED8006/Shafer.pdf
http://oregonstate.edu/~acock/growth-curves/working%20with%20missing%20values.pdf
HTH.
----- -- Bruce Weaver http://sites.google.com/a/lakeheadu.ca/bweaver/
-----Original Message-----
Java Joe,
I'm surprised that nobody pointed out one of the two direct methods. As you've discovered, spss doesn't use a 'then' keyword in the context of an 'if' command. Furthermore, you may have discovered the a 'do if' command won't work either. One direct method is
Temporary. Select if (sex eq 1). RMV /Var1=SMEAN(Var1_1).
There is another command that can be used and is functionally equivalent to the 'temporary. Select if' sequence but I can't remember it now, perhaps because I never use it.
Gene Maguin
|
| Free forum by Nabble | Edit this page |
