(Apologies for cross-posting) From a beginner user of SPSS:
I am trying to run the following syntax: do if (missing(chdstat1) = 1). compute ownchild =2. else if (chdstat1 = 1 | chdstat2 = 1 | chdstat3 =1 | chdstat4 = 1 | chdstat5 = 1 |chdstat6 = 1). compute ownchild = 1. else. compute ownchild = 0. end if. exe. However, the 3rd part of the statement, else. compute ownchild = 0. Is not being processed at all. However, the syntax will run if I remove the full stop in the first line, so that SPSS throws and error message, and then replace it. This syntax was based one on another analysis I have run a month ago, which used to work, but now only works through the method of making SPSS have and error and then re-running. Can anyone tell me why this is the case? Natalie ****************************** Natalie Nicholls Information Analyst/Statistician NHS National Services Scotland ISD, Epidemiology and Statistics Group Area 143a, 1st Floor Gyle Square 1 South Gyle Crescent Edinburgh EH12 9EB Tel: 0131 275 6550 _________________________________________________________________ NHS National Services Scotland Disclaimer The information contained in this message may be confidential or legally privileged and is intended for the addressee only. If you have received this message in error or there are any problems please notify the originator immediately. The unauthorised use, disclosure, copying or alteration of this message is strictly forbidden. _________________________________________________________________ |
Natalie,
try to put each statement into separate line. This works: *----------------------. do if (missing(chdstat1) = 1). compute ownchild =2. else if (chdstat1 = 1 | chdstat2 = 1 | chdstat3 =1 | chdstat4 = 1 | chdstat5 = 1 |chdstat6 = 1). compute ownchild = 1. else. compute ownchild = 0. end if. exe. *----------------------. Note, that in case when chdstat1 is not missing AND some of chdstat2 to chdstat6 have missing values AND no one of non-missing values of chdstat1 to chdstat6 equals 1 THEN expression (chdstat1 = 1 | chdstat2 = 1 | chdstat3 =1 | chdstat4 = 1 | chdstat5 = 1 |chdstat6 = 1) stays indeterminate. As a result the value for ownchild will not be changed. I would suggest using function "ANY" instead of multiple "OR" comparisons. But be careful, this will work differently in the situation described above. If no one of chdstat1 to chdstat6 variables will have 1 no matter have they missing values or not, the result of ANY will be "FALSE" and the last ELSE will work. *----------------------. do if missing(chdstat1). compute ownchild =2. else if ANY(1, chdstat1 TO chdstat6). compute ownchild = 1. else. compute ownchild = 0. end if. exe. *----------------------. Best, Anton > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] > On Behalf Of Nicholls, Natalie > Sent: Friday, December 01, 2006 12:54 PM > To: [hidden email] > Subject: a simple (!) question > > > (Apologies for cross-posting) From a beginner user of SPSS: > > I am trying to run the following syntax: > > do if (missing(chdstat1) = 1). > compute ownchild =2. > else if (chdstat1 = 1 | chdstat2 = 1 | chdstat3 =1 | chdstat4 > = 1 | chdstat5 = 1 |chdstat6 = 1). compute ownchild = 1. > else. compute ownchild = 0. end if. exe. > > However, the 3rd part of the statement, > else. > compute ownchild = 0. > > Is not being processed at all. However, the syntax will run > if I remove the full stop in the first line, so that SPSS > throws and error message, and then replace it. This syntax > was based one on another analysis I have run a month ago, > which used to work, but now only works through the method of > making SPSS have and error and then re-running. > > Can anyone tell me why this is the case? > > Natalie > > > ****************************** > > Natalie Nicholls > Information Analyst/Statistician > NHS National Services Scotland > ISD, Epidemiology and Statistics Group > Area 143a, 1st Floor > Gyle Square > 1 South Gyle Crescent > Edinburgh > EH12 9EB > > Tel: 0131 275 6550 > > > _________________________________________________________________ > NHS National Services Scotland Disclaimer > > The information contained in this message may be confidential > or legally privileged and is intended for the addressee only. > If you have received this message in error or there are any > problems please notify the originator immediately. The > unauthorised use, disclosure, copying or alteration of this > message is strictly forbidden. > _________________________________________________________________ > |
In reply to this post by Nicholls, Natalie
Thank you all, it's all working now
Natalie. _________________________________________________________________ NHS National Services Scotland Disclaimer The information contained in this message may be confidential or legally privileged and is intended for the addressee only. If you have received this message in error or there are any problems please notify the originator immediately. The unauthorised use, disclosure, copying or alteration of this message is strictly forbidden. _________________________________________________________________ |
In reply to this post by Nicholls, Natalie
There is example syntax below the sig block.
Save all your current work, then open a new instance of SPSS. Make sure that you put warnings, etc. into the output file. <edit> <options> <viewer>. Cut-and-paste then run the syntax. Does this do what you want? If not please restate your question in more detail. Perhaps post a small data set with variables "have" and "want". Hope this helps. Art [hidden email] Social Research Consultants * make up some data. data list list /id(f2) chdstat1 to chdstat6(6f1). begin data. 01 1 1 1 1 1 1 02 -1 0 0 0 0 0 03 x 0 0 0 0 0 04 0 1 0 0 0 0 05 1 0 0 0 0 0 06 0 0 0 0 0 0 end data. missing values chdstat1 to chdstat6 (lo thru -1). * do if missing(chdstat1). compute ownchild =2. else if any(1, chdstat1 to chdstat6). * if chdstat variables are not contiguous remove the * from the line below and delete the line above. *else if any(1, chdstat1,chdstat2,chdstat3,chdstat4,chdstat5,chdstat6). compute ownchild = 1. else. compute ownchild = 0. end if. formats ownchild(f1). list. exe. Nicholls, Natalie wrote: >(Apologies for cross-posting) From a beginner user of SPSS: > >I am trying to run the following syntax: > >do if (missing(chdstat1) = 1). > compute ownchild =2. >else if (chdstat1 = 1 | chdstat2 = 1 | chdstat3 =1 | chdstat4 = 1 | chdstat5 >= 1 |chdstat6 = 1). >compute ownchild = 1. >else. >compute ownchild = 0. >end if. >exe. > >However, the 3rd part of the statement, >else. >compute ownchild = 0. > >Is not being processed at all. However, the syntax will run if I remove the >full stop in the first line, so that SPSS throws and error message, and then >replace it. This syntax was based one on another analysis I have run a month >ago, which used to work, but now only works through the method of making >SPSS have and error and then re-running. > >Can anyone tell me why this is the case? > >Natalie > > >****************************** > >Natalie Nicholls >Information Analyst/Statistician >NHS National Services Scotland >ISD, Epidemiology and Statistics Group >Area 143a, 1st Floor >Gyle Square >1 South Gyle Crescent >Edinburgh >EH12 9EB > >Tel: 0131 275 6550 > > >_________________________________________________________________ >NHS National Services Scotland Disclaimer > >The information contained in this message may be confidential or >legally privileged and is intended for the addressee only. If you have >received this message in error or there are any problems please notify the >originator immediately. The unauthorised use, disclosure, copying or >alteration of this message is strictly forbidden. >_________________________________________________________________ > > > > |
Free forum by Nabble | Edit this page |