Compound IF syntax

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

Compound IF syntax

Jim Moffitt
I have 6 contiguous variables named q1-q26.

For all 200 of my cases all twenty-six of those variables contain either
a system missing dot, a 1, or a zero.
 
I have another variable named Sam.
 
For all 200 of my cases Sam currently contains either a system missing
dot or a 1.
 
How do I write a syntax line that says for every case in which none of
the values in any of the twenty-six contiguous variables are 1 and any
of the values in those twenty-six contiguous variables are zero, set the
value of Sam to 0?
 
Thanks for your help.
Reply | Threaded
Open this post in threaded view
|

Re: Compound IF syntax

David Wasserman
This is untested syntax, but since the SUM function only returns missing if
all the values are missing (unless otherwise specified with the .n suffix),
this should work:

IF SUM(Q1 TO Q26) EQ 0 Sam = 0.

David Wasserman
Custom Data Analysis and SPSS Programming

----- Original Message -----
From: "Jim Moffitt" <[hidden email]>
Newsgroups: bit.listserv.spssx-l
To: <[hidden email]>
Sent: Saturday, July 22, 2006 9:39 AM
Subject: Compound IF syntax


I have 6 contiguous variables named q1-q26.

For all 200 of my cases all twenty-six of those variables contain either
a system missing dot, a 1, or a zero.

I have another variable named Sam.

For all 200 of my cases Sam currently contains either a system missing
dot or a 1.

How do I write a syntax line that says for every case in which none of
the values in any of the twenty-six contiguous variables are 1 and any
of the values in those twenty-six contiguous variables are zero, set the
value of Sam to 0?

Thanks for your help.
Reply | Threaded
Open this post in threaded view
|

Re: Compound IF syntax

John McConnell
In reply to this post by Jim Moffitt
 Jim,

 I can't test this at the moment but it sounds like a job for COUNT. Something like

COUNT N1S=Q1 to Q26 (1).
COUNT N0S=Q1 to Q26 (0).
IF N1S EQ 0 AND N0S GE 1 SAM=0.

 hth

 John

 John McConnell
 Applied Insights



---------- Original Message ----------------------------------
From: Jim Moffitt <[hidden email]>
Reply-To: [hidden email]
Date:          Sat, 22 Jul 2006 10:39:00 -0500

>I have 6 contiguous variables named q1-q26.
>
>For all 200 of my cases all twenty-six of those variables contain either
>a system missing dot, a 1, or a zero.
>
>I have another variable named Sam.
>
>For all 200 of my cases Sam currently contains either a system missing
>dot or a 1.
>
>How do I write a syntax line that says for every case in which none of
>the values in any of the twenty-six contiguous variables are 1 and any
>of the values in those twenty-six contiguous variables are zero, set the
>value of Sam to 0?
>
>Thanks for your help.
>
Reply | Threaded
Open this post in threaded view
|

Re: Compound IF syntax

Jim Moffitt
In reply to this post by David Wasserman
David:
Your code seems to work just fine. Thanks so much for a very clever
solution.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
David Wasserman
Sent: Saturday, July 22, 2006 11:35 AM
To: [hidden email]
Subject: Re: Compound IF syntax

This is untested syntax, but since the SUM function only returns missing
if all the values are missing (unless otherwise specified with the .n
suffix), this should work:

IF SUM(Q1 TO Q26) EQ 0 Sam = 0.

David Wasserman
Custom Data Analysis and SPSS Programming

----- Original Message -----
From: "Jim Moffitt" <[hidden email]>
Newsgroups: bit.listserv.spssx-l
To: <[hidden email]>
Sent: Saturday, July 22, 2006 9:39 AM
Subject: Compound IF syntax


I have 6 contiguous variables named q1-q26.

For all 200 of my cases all twenty-six of those variables contain either
a system missing dot, a 1, or a zero.

I have another variable named Sam.

For all 200 of my cases Sam currently contains either a system missing
dot or a 1.

How do I write a syntax line that says for every case in which none of
the values in any of the twenty-six contiguous variables are 1 and any
of the values in those twenty-six contiguous variables are zero, set the
value of Sam to 0?

Thanks for your help.
Reply | Threaded
Open this post in threaded view
|

Re: Compound IF syntax

Jim Moffitt
In reply to this post by John McConnell
John:
Your code seems to work just fine. Thanks so much for your help.

-----Original Message-----
From: John McConnell [mailto:[hidden email]]
Sent: Saturday, July 22, 2006 12:09 PM
To: [hidden email]; Moffitt, James (West)
Subject: Re: Compound IF syntax


 Jim,

 I can't test this at the moment but it sounds like a job for COUNT.
Something like

COUNT N1S=Q1 to Q26 (1).
COUNT N0S=Q1 to Q26 (0).
IF N1S EQ 0 AND N0S GE 1 SAM=0.

 hth

 John

 John McConnell
 Applied Insights



---------- Original Message ----------------------------------
From: Jim Moffitt <[hidden email]>
Reply-To: [hidden email]
Date:          Sat, 22 Jul 2006 10:39:00 -0500

>I have 6 contiguous variables named q1-q26.
>
>For all 200 of my cases all twenty-six of those variables contain
>either a system missing dot, a 1, or a zero.
>
>I have another variable named Sam.
>
>For all 200 of my cases Sam currently contains either a system missing
>dot or a 1.
>
>How do I write a syntax line that says for every case in which none of
>the values in any of the twenty-six contiguous variables are 1 and any
>of the values in those twenty-six contiguous variables are zero, set
>the value of Sam to 0?
>
>Thanks for your help.
>
Reply | Threaded
Open this post in threaded view
|

weighted numbers

Albert-Jan Roskam
Dear all,

I want to calculate the relative proportions of people
within educational categories, stratified by sex and
country. I use a standardized weight that corrects for
sample selection bias.  Could anybody tell me
why-oh-why the two methods listed below yield
(slightly) different results? The N function of the
aggregate counts the weighed number of cases within
the break group. So why are the AGGREGATE results
identical to the output I get using SUMMARIZE with an
UNweighted sample? Am I missing something?

Thanks a lot in advance!

Albert-Jan


weight by w_plus.

** Method 1.
compute dummy = 1.
summarize tables = dummy by sex by country3 by educat
/   cells = npct (educat).

** Method 2.
aggregate outfile = "d:\temp\tmp.sav" / break = sex
country3 educat / n = n.
aggregate outfile = * / break = sex country3 / n_tot =
n.
match files table = * / file = "d:\temp\tmp.sav" / by
= sex country3.
compute pct = (n / n_tot ) * 100.
exe.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: weighted numbers

Beadle, ViAnn
Weights don't apply to AGGREGATE; only to statistical procedures.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Albert-jan Roskam
Sent: Monday, July 24, 2006 7:52 AM
To: [hidden email]
Subject: weighted numbers

Dear all,

I want to calculate the relative proportions of people
within educational categories, stratified by sex and
country. I use a standardized weight that corrects for
sample selection bias.  Could anybody tell me
why-oh-why the two methods listed below yield
(slightly) different results? The N function of the
aggregate counts the weighed number of cases within
the break group. So why are the AGGREGATE results
identical to the output I get using SUMMARIZE with an
UNweighted sample? Am I missing something?

Thanks a lot in advance!

Albert-Jan


weight by w_plus.

** Method 1.
compute dummy = 1.
summarize tables = dummy by sex by country3 by educat
/   cells = npct (educat).

** Method 2.
aggregate outfile = "d:\temp\tmp.sav" / break = sex
country3 educat / n = n.
aggregate outfile = * / break = sex country3 / n_tot =
n.
match files table = * / file = "d:\temp\tmp.sav" / by
= sex country3.
compute pct = (n / n_tot ) * 100.
exe.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: weighted numbers

Albert-Jan Roskam
Thank you for your quick reply!

But if I add the NU function I can generate weighted
(N) as well as UNweighted numbers of cases. Which is
why I used N, not UN.

aggregate outfile = "d:\temp\tmp.sav" / break = sex
country3 educat / n = n / nu = nu.

Albert-Jan


--- "Beadle, ViAnn" <[hidden email]> wrote:

> Weights don't apply to AGGREGATE; only to
> statistical procedures.
>
> -----Original Message-----
> From: SPSSX(r) Discussion
> [mailto:[hidden email]] On Behalf Of
> Albert-jan Roskam
> Sent: Monday, July 24, 2006 7:52 AM
> To: [hidden email]
> Subject: weighted numbers
>
> Dear all,
>
> I want to calculate the relative proportions of
> people
> within educational categories, stratified by sex and
> country. I use a standardized weight that corrects
> for
> sample selection bias.  Could anybody tell me
> why-oh-why the two methods listed below yield
> (slightly) different results? The N function of the
> aggregate counts the weighed number of cases within
> the break group. So why are the AGGREGATE results
> identical to the output I get using SUMMARIZE with
> an
> UNweighted sample? Am I missing something?
>
> Thanks a lot in advance!
>
> Albert-Jan
>
>
> weight by w_plus.
>
> ** Method 1.
> compute dummy = 1.
> summarize tables = dummy by sex by country3 by
> educat
> /   cells = npct (educat).
>
> ** Method 2.
> aggregate outfile = "d:\temp\tmp.sav" / break = sex
> country3 educat / n = n.
> aggregate outfile = * / break = sex country3 / n_tot
> =
> n.
> match files table = * / file = "d:\temp\tmp.sav" /
> by
> = sex country3.
> compute pct = (n / n_tot ) * 100.
> exe.
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around
> http://mail.yahoo.com
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: weighted numbers

Beadle, ViAnn
In reply to this post by Albert-Jan Roskam
Oh, I think your right here. Perhaps the problem is that of missing values?

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Albert-jan Roskam
Sent: Monday, July 24, 2006 8:29 AM
To: [hidden email]
Subject: Re: weighted numbers

Thank you for your quick reply!

But if I add the NU function I can generate weighted
(N) as well as UNweighted numbers of cases. Which is
why I used N, not UN.

aggregate outfile = "d:\temp\tmp.sav" / break = sex
country3 educat / n = n / nu = nu.

Albert-Jan


--- "Beadle, ViAnn" <[hidden email]> wrote:

> Weights don't apply to AGGREGATE; only to
> statistical procedures.
>
> -----Original Message-----
> From: SPSSX(r) Discussion
> [mailto:[hidden email]] On Behalf Of
> Albert-jan Roskam
> Sent: Monday, July 24, 2006 7:52 AM
> To: [hidden email]
> Subject: weighted numbers
>
> Dear all,
>
> I want to calculate the relative proportions of
> people
> within educational categories, stratified by sex and
> country. I use a standardized weight that corrects
> for
> sample selection bias.  Could anybody tell me
> why-oh-why the two methods listed below yield
> (slightly) different results? The N function of the
> aggregate counts the weighed number of cases within
> the break group. So why are the AGGREGATE results
> identical to the output I get using SUMMARIZE with
> an
> UNweighted sample? Am I missing something?
>
> Thanks a lot in advance!
>
> Albert-Jan
>
>
> weight by w_plus.
>
> ** Method 1.
> compute dummy = 1.
> summarize tables = dummy by sex by country3 by
> educat
> /   cells = npct (educat).
>
> ** Method 2.
> aggregate outfile = "d:\temp\tmp.sav" / break = sex
> country3 educat / n = n.
> aggregate outfile = * / break = sex country3 / n_tot
> =
> n.
> match files table = * / file = "d:\temp\tmp.sav" /
> by
> = sex country3.
> compute pct = (n / n_tot ) * 100.
> exe.
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around
> http://mail.yahoo.com
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: weighted numbers

Albert-Jan Roskam
Aaahh... thanks! You were right. Adding
SELECT IF NOT MISSING (educat).
makes the two methodes yield the same results.

Albert-Jan

--- "Beadle, ViAnn" <[hidden email]> wrote:

> Oh, I think your right here. Perhaps the problem is
> that of missing values?
>
> -----Original Message-----
> From: SPSSX(r) Discussion
> [mailto:[hidden email]] On Behalf Of
> Albert-jan Roskam
> Sent: Monday, July 24, 2006 8:29 AM
> To: [hidden email]
> Subject: Re: weighted numbers
>
> Thank you for your quick reply!
>
> But if I add the NU function I can generate weighted
> (N) as well as UNweighted numbers of cases. Which is
> why I used N, not UN.
>
> aggregate outfile = "d:\temp\tmp.sav" / break = sex
> country3 educat / n = n / nu = nu.
>
> Albert-Jan
>
>
> --- "Beadle, ViAnn" <[hidden email]> wrote:
>
> > Weights don't apply to AGGREGATE; only to
> > statistical procedures.
> >
> > -----Original Message-----
> > From: SPSSX(r) Discussion
> > [mailto:[hidden email]] On Behalf Of
> > Albert-jan Roskam
> > Sent: Monday, July 24, 2006 7:52 AM
> > To: [hidden email]
> > Subject: weighted numbers
> >
> > Dear all,
> >
> > I want to calculate the relative proportions of
> > people
> > within educational categories, stratified by sex
> and
> > country. I use a standardized weight that corrects
> > for
> > sample selection bias.  Could anybody tell me
> > why-oh-why the two methods listed below yield
> > (slightly) different results? The N function of
> the
> > aggregate counts the weighed number of cases
> within
> > the break group. So why are the AGGREGATE results
> > identical to the output I get using SUMMARIZE with
> > an
> > UNweighted sample? Am I missing something?
> >
> > Thanks a lot in advance!
> >
> > Albert-Jan
> >
> >
> > weight by w_plus.
> >
> > ** Method 1.
> > compute dummy = 1.
> > summarize tables = dummy by sex by country3 by
> > educat
> > /   cells = npct (educat).
> >
> > ** Method 2.
> > aggregate outfile = "d:\temp\tmp.sav" / break =
> sex
> > country3 educat / n = n.
> > aggregate outfile = * / break = sex country3 /
> n_tot
> > =
> > n.
> > match files table = * / file = "d:\temp\tmp.sav" /
> > by
> > = sex country3.
> > compute pct = (n / n_tot ) * 100.
> > exe.
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> > protection around
> > http://mail.yahoo.com
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around
> http://mail.yahoo.com
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com