Creating a variable to look at 2 of 3 years of data

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

Creating a variable to look at 2 of 3 years of data

Veena Nambiar

Hi All,

 

This is a very basic question I could use some assistance on.  Often times, I am asked to check if a school met a particular indicator over time. For instance. I would like to determine if a set of schools made a particular indicator in 2 out of 3 years. These are the variables I have:

 

sch_09=Yes/No

sch_08=Yes/No

sch_07=Yes/No

 

If Yes on sch_09, the school met the indicator in 09, If Yes on sch_08, the school met the indicator in 08, etc.  I would like create a variable to indicate if the school made the criteria in any two of the three years. I could use the following syntax, that goes through all of the 2 year combinations, but would like something more efficient since I sometimes have many years of data I am looking at and writing out the combinations is inefficient:

 

STRING met_2yr (A3).

IF (sch_09='Yes' & schl_08='Yes') met_2yr='Yes'.

IF (sch_08='Yes' & schl_07='Yes') met_2yr='Yes'.

IF (sch_09='Yes' & schl_07='Yes') met_2yr='Yes'.

EXECUTE.

 

Thank you for your help!

 

Veena

 

Reply | Threaded
Open this post in threaded view
|

Re: Creating a variable to look at 2 of 3 years of data

Maguin, Eugene
Veena,

Look at the count command as in
Count met_2yr=sch_07 sch_08 sch_09('Yes').
Recode met_2yr(0 1=0)(2=1).


Gene Maguin


>>>This is a very basic question I could use some assistance on.  Often
times, I am asked to check if a school met a particular indicator over time.
For instance. I would like to determine if a set of schools made a
particular indicator in 2 out of 3 years. These are the variables I have:

sch_09=Yes/No
sch_08=Yes/No
sch_07=Yes/No

If Yes on sch_09, the school met the indicator in 09, If Yes on sch_08, the
school met the indicator in 08, etc.  I would like create a variable to
indicate if the school made the criteria in any two of the three years. I
could use the following syntax, that goes through all of the 2 year
combinations, but would like something more efficient since I sometimes have
many years of data I am looking at and writing out the combinations is
inefficient:

STRING met_2yr (A3).
IF (sch_09='Yes' & schl_08='Yes') met_2yr='Yes'.
IF (sch_08='Yes' & schl_07='Yes') met_2yr='Yes'.
IF (sch_09='Yes' & schl_07='Yes') met_2yr='Yes'.
EXECUTE.

Thank you for your help!
Veena

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Creating a variable to look at 2 of 3 years of data

Bruce Weaver
Administrator
In reply to this post by Veena Nambiar
For Yes/No variables that you are creating yourself, it's more convenient to use numeric variables with 1=Yes and 0=No.  Such variables can be used directly for filtering, for example.  Try this:

count #yesses = sch_07 sch_08 sch09 ("Yes").
compute met_2yr = (#yesses GE 2).
format met_2yr (f2.0).
value labels met_2yr
 0 'No'
 1 'Yes'
.
list.

The '#' makes #yesses a scratch variable that exists only temporarily.  That's why you won't find it in your data file.


Veena Nambiar wrote
Hi All,

This is a very basic question I could use some assistance on.  Often times, I am asked to check if a school met a particular indicator over time. For instance. I would like to determine if a set of schools made a particular indicator in 2 out of 3 years. These are the variables I have:

sch_09=Yes/No
sch_08=Yes/No
sch_07=Yes/No

If Yes on sch_09, the school met the indicator in 09, If Yes on sch_08, the school met the indicator in 08, etc.  I would like create a variable to indicate if the school made the criteria in any two of the three years. I could use the following syntax, that goes through all of the 2 year combinations, but would like something more efficient since I sometimes have many years of data I am looking at and writing out the combinations is inefficient:

STRING met_2yr (A3).
IF (sch_09='Yes' & schl_08='Yes') met_2yr='Yes'.
IF (sch_08='Yes' & schl_07='Yes') met_2yr='Yes'.
IF (sch_09='Yes' & schl_07='Yes') met_2yr='Yes'.
EXECUTE.

Thank you for your help!

Veena
--
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/).