|
Hello
I want to compute a new variable SEX out of two. The data are from a study with two measurements. Because not every student was present by both measurements (time 1 variable is assex, time 2 variable bssex), there are cases with a value (1 or 2) in both variables or in just one of them. I tried the following command, which didn't work: DO IF assex GE 1. COMPUTE sex=assex. ELSE IF assex LT 1. COMPUTE sex=bssex. ELSE. COMPUTE sex=0. END IF. What's wrong with it? I appreciate any help, thanks. Tom ===================== 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 |
|
Hi Tom
What about the following syntax? data list Free /assex(F8.0) bssex (F8.0) . begin data 1, 1 2, , 2 1, End Data. if not missing(assex) sex = assex. if not missing(bssex) sex = bssex. if missing(sex) sex = 0. Exec. Hope this helps, Christian ********************************** la volta statistics Christian Schmidhauser, Dr.phil.II Weinbergstrasse 108 CH-8006 Zürich Tel: +41 (043) 233 98 01 Fax: +41 (043) 233 98 02 email: mailto:[hidden email] Web: www.lavolta.ch -----Ursprüngliche Nachricht----- Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von Balmer Thomas Gesendet: Freitag, 8. Oktober 2010 11:43 An: [hidden email] Betreff: Do if Hello I want to compute a new variable SEX out of two. The data are from a study with two measurements. Because not every student was present by both measurements (time 1 variable is assex, time 2 variable bssex), there are cases with a value (1 or 2) in both variables or in just one of them. I tried the following command, which didn't work: DO IF assex GE 1. COMPUTE sex=assex. ELSE IF assex LT 1. COMPUTE sex=bssex. ELSE. COMPUTE sex=0. END IF. What's wrong with it? I appreciate any help, thanks. Tom ===================== 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 |
|
It did help, works fine, thanks Christian!
Tom -----Ursprüngliche Nachricht----- Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von la volta statistics Gesendet: Freitag, 8. Oktober 2010 12:14 An: [hidden email] Betreff: AW: Do if Hi Tom What about the following syntax? data list Free /assex(F8.0) bssex (F8.0) . begin data 1, 1 2, , 2 1, End Data. if not missing(assex) sex = assex. if not missing(bssex) sex = bssex. if missing(sex) sex = 0. Exec. Hope this helps, Christian ********************************** la volta statistics Christian Schmidhauser, Dr.phil.II Weinbergstrasse 108 CH-8006 Zürich Tel: +41 (043) 233 98 01 Fax: +41 (043) 233 98 02 email: mailto:[hidden email] Web: www.lavolta.ch -----Ursprüngliche Nachricht----- Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von Balmer Thomas Gesendet: Freitag, 8. Oktober 2010 11:43 An: [hidden email] Betreff: Do if Hello I want to compute a new variable SEX out of two. The data are from a study with two measurements. Because not every student was present by both measurements (time 1 variable is assex, time 2 variable bssex), there are cases with a value (1 or 2) in both variables or in just one of them. I tried the following command, which didn't work: DO IF assex GE 1. COMPUTE sex=assex. ELSE IF assex LT 1. COMPUTE sex=bssex. ELSE. COMPUTE sex=0. END IF. What's wrong with it? I appreciate any help, thanks. Tom ===================== 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 ===================== 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 |
|
In reply to this post by Tom
|
|
In reply to this post by Tom
In situations like this I always do a
check:
cros assex by bssex .
. . .and then possibly:
compute sex = assex*10 + bssex.
recode sex ~ ~ ~ etc.
|
|
Administrator
|
In reply to this post by la volta statistics
Here's another variation that includes the possibility of assex and bssex having different values. data list Free /assex bssex (2f1.0) . begin data 1 1 2 2 1 9 9 1 2 9 9 2 1 2 2 1 9 9 end data. missing values assex bssex (9). compute sex = mean(assex,bssex). recode sex (sysmis=9). value labels sex 1 'Male' 1.5 'PROBLEM: assex NE bssex' 2 'Female' 9 'Missing' . missing values sex(9). frequencies sex.
--
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/). |
|
In reply to this post by E. Bernardo
Eins,
Use the table subcommand of the match files command as in (and since your files are sorted) Match files file='file 1'/table='file 2'/by var1. Gene Maguin ________________________________ From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Eins Bernardo Sent: Friday, October 08, 2010 6:29 AM To: [hidden email] Subject: Merging files or Adding variables? My datafile1 consists of a numeric variable, The values are four digit numbers where each value (e.g. 4) occurs many times. For example, the datafile below shows that VAR1 has the following values: 4444, 5555 and 6545 where each occurs many times. VAR1 4444 4444 4444 4444 5555 5555 5555 5555 6545 6545 6545 6545 Another datafile2 consists of two variables VAR2 and VAR3 where the values of VAR2 are the same with VAR1, except that VAR2 has no duplicates. Datafile2 looks like below: VAR2 VAR3 4444 X 5555 Y 6545 Z How to add VAR3 to Datafile1 such that Datafile1 becomes VAR1 VAR3 4444 X 4444 X 4444 X 4444 X 5555 Y 5555 Y 5555 Y 5555 Y 6545 z 6545 z 6545 z 6545 z Thanks a lot for your help. Eins --- On Fri, 10/8/10, Balmer Thomas <[hidden email]> wrote: From: Balmer Thomas <[hidden email]> Subject: Do if To: [hidden email] Date: Friday, 8 October, 2010, 9:42 AM Hello I want to compute a new variable SEX out of two. The data are from a study with two measurements. Because not every student was present by both measurements (time 1 variable is assex, time 2 variable bssex), there are cases with a value (1 or 2) in both variables or in just one of them. I tried the following command, which didn't work: DO IF assex GE 1. COMPUTE sex=assex. ELSE IF assex LT 1. COMPUTE sex=bssex. ELSE. COMPUTE sex=0. END IF. What's wrong with it? I appreciate any help, thanks. Tom ===================== 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 |
|
| Free forum by Nabble | Edit this page |
