Help with creating a string variable from two variables (numeric/string)

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

Help with creating a string variable from two variables (numeric/string)

Delma Byrne
Hi there, 

I have a dataset of individual level student examination data, all primary cases. Some students have more than one year of examination data.

The data contains the following variables: 
Student Id 
School id variables for each examination: 33 individual string variables 'School1' 'School2' 'School3' ....)
Yearofexam variable for each examination: 33 individual numeric variables 'Y1' 'Y2' 'Y3'....) 


Using a vector, I have created  two variables: 
(a) the year of the most recent examination: ('WHAT' a numeric variable)
(b) the school that the student attended at that time: ('WHERE' a numeric variable)

I now want to create a new string variable 'schoolid' using these two variables to identify the school id of the most recent exam. What command should I use after creating the new string variable 'schid'? Basically, I now know the year and the school of the most recent exam and want to create a new school variable based on the school that the most recent exam took place. 

STRING schild (A10). 

I've tried using CONCAT, but it doesn't seem to allow me to use an 'if' function. 
Basically what I'd like to do is: 

STRING schild (A10). 
if (WHEN=1) schid=School33. 
if (WHEN=2) schid=School27. 
if (WHEN=3) schid=School4. 

Any help anyone could offer would be most appreciated! 

Delma 

  




===================== 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: Help with creating a string variable from two variables (numeric/string)

spss.giesel@yahoo.de
Hi, Delma,

how about this?

---
STRING schild (A10). 
COMPUTE Ymin = MIN(Y1,Y2,Y3,Y4,Y5,Y6,Y7,Y8,Y9,Y10,Y11,Y12,Y13,Y14,Y15,Y16,Y17,Y18,Y19,Y20,
Y21,Y22,Y23,Y24,Y25,Y26,Y27,Y28,Y29,Y30,Y31,Y32,Y33).
DO REPEAT 
y =  Y1 Y2 Y3 Y4 Y5 Y6 Y7 Y8 Y9 Y10
Y11 Y12 Y13 Y14 Y15 Y16 Y17 Y18 Y19 Y20
Y21 Y22 Y23 Y24 Y25 Y26 Y27 Y28 Y29 Y30
Y31 Y32 Y33
/s = School1 School2 School3 School4 School5 School6 School7 School8 School9 School10 
School11 School12 School13 School14 School15 School16 School17 School18 School19 School20 
School21 School22 School23 School24 School25 School26 School27 School28 School29 School30 
School31 School32 School33.

IF (y = Ymin) schid = RTRIM(s).
END REPEAT.
FRE schid.


Mario Giesel
Munich, Germany
---

Am Samstag, 18. April 2020, 14:04:41 MESZ hat Delma Byrne <[hidden email]> Folgendes geschrieben:


Hi there, 

I have a dataset of individual level student examination data, all primary cases. Some students have more than one year of examination data.

The data contains the following variables: 
Student Id 
School id variables for each examination: 33 individual string variables 'School1' 'School2' 'School3' ....)
Yearofexam variable for each examination: 33 individual numeric variables 'Y1' 'Y2' 'Y3'....) 


Using a vector, I have created  two variables: 
(a) the year of the most recent examination: ('WHAT' a numeric variable)
(b) the school that the student attended at that time: ('WHERE' a numeric variable)

I now want to create a new string variable 'schoolid' using these two variables to identify the school id of the most recent exam. What command should I use after creating the new string variable 'schid'? Basically, I now know the year and the school of the most recent exam and want to create a new school variable based on the school that the most recent exam took place. 

STRING schild (A10). 

I've tried using CONCAT, but it doesn't seem to allow me to use an 'if' function. 
Basically what I'd like to do is: 

STRING schild (A10). 
if (WHEN=1) schid=School33. 
if (WHEN=2) schid=School27. 
if (WHEN=3) schid=School4. 

Any help anyone could offer would be most appreciated! 

Delma 

  




===================== 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
===================== 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: Help with creating a string variable from two variables (numeric/string)

Bruce Weaver
Administrator
In reply to this post by Delma Byrne
Have you considered using VARSTOCASES to convert your file from wide to long?
I think that everything you want to do will be considerably easier with a
long file format.  HTH.



Delma Byrne wrote
> Hi there, 
> I have a dataset of individual level student examination data, all primary
> cases. Some students have more than one year of examination data.
> The data contains the following variables: Student Id School id variables
> for each examination: 33 individual string variables 'School1' 'School2'
> 'School3' ....)Yearofexam variable for each examination: 33 individual
> numeric variables 'Y1' 'Y2' 'Y3'....) 
> --- snip the rest ---





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

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

Re: Help with creating a string variable from two variables (numeric/string)

David Marso-2
In reply to this post by Delma Byrne
Indeed.

=====================
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