creating a variable based on the values of other two variables

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

creating a variable based on the values of other two variables

E. Bernardo
Hello SPSS Experts,

I would like to ask how to create a variable based on the values of other two variables.  As shown below, the first three columns such as student ID (ID), school year of enrollment (SY) and semester of enrollment (Semester) are available in my SPSS database.  I want to create the fourth column called date of enrollment (DOE), a date variable.  The dates should be created based on the values of SY and Semester.  Semester=1 is referenced as June 1  while Semester=2 is referenced as November 1.  For example, if a student enrolled during the school year 2004-2005 and semester=1, then DOE = 06/1/2004.

ID SY Semester DOE
1 2004-2005 1 06/1/2004
2 2004-2005 2 10/1/2004
3 2005-2006 1
4 2005-2006 2
5 2006-2007 1
6 2006-2007 2

Your help is highly solicited. Thank you.
Eins
Reply | Threaded
Open this post in threaded view
|

Re: creating a variable based on the values of other two variables

Ruben Geert van den Berg
Dear Eins,

If I guessed the formats of your variables correctly, the following should work.

data list free/id(f1.0)sy(a9)semester(f1.0).
begin data
1 '2004-2005' 1
2 '2004-2005' 2
3 '2005-2006' 1
4 '2010-2011' 2
end data.

if semester=1 doe=date.mdy(6,1,num(sub(sy,1,4),f4)).
if semester=2 doe=date.mdy(11,1,num(sub(sy,1,4),f4)).
for doe(adate10).

Best,

Ruben

P.s. you did mean November, right?


Date: Thu, 4 Oct 2012 11:18:16 +0800
From: [hidden email]
Subject: creating a variable based on the values of other two variables
To: [hidden email]

Hello SPSS Experts,

I would like to ask how to create a variable based on the values of other two variables.  As shown below, the first three columns such as student ID (ID), school year of enrollment (SY) and semester of enrollment (Semester) are available in my SPSS database.  I want to create the fourth column called date of enrollment (DOE), a date variable.  The dates should be created based on the values of SY and Semester.  Semester=1 is referenced as June 1  while Semester=2 is referenced as November 1.  For example, if a student enrolled during the school year 2004-2005 and semester=1, then DOE = 06/1/2004.

ID SY Semester DOE
1 2004-2005 1 06/1/2004
2 2004-2005 2 10/1/2004
3 2005-2006 1
4 2005-2006 2
5 2006-2007 1
6 2006-2007 2

Your help is highly solicited. Thank you.
Eins