Do if

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

Do if

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

AW: Do if

la volta statistics
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
Tom
Reply | Threaded
Open this post in threaded view
|

AW: Do if

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

Merging files or Adding variables?

E. Bernardo
In reply to this post by Tom
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
LISTSERV@... (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: AW: Do if

John F Hall
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.
 
 
----- Original Message -----
Sent: Friday, October 08, 2010 12:26 PM
Subject: AW: Do if


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: [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

Reply | Threaded
Open this post in threaded view
|

Re: AW: Do if

Bruce Weaver
Administrator
In reply to this post by la volta statistics
la volta statistics wrote
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
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/).
Reply | Threaded
Open this post in threaded view
|

Re: Merging files or Adding variables?

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

Re: Merging files or Adding variables?

Johnny Amora
Here is an alternative using a GUI:
 
  1. Open the data file datafile1.sav.
  2. From the Data menu, select Merge Files and then Add Variables... .
  3. Select the file to merge ( datafile2.sav), and then click Continue.
  4. In the Add variables dialog box, select Match cases on key variables in sorted files and check Non-active dataset is keyed table. Under "Key Variables:", select VAR1. Click OK.
 
This will produce the same results of Gene's suggestion. It is important to sort both the data files by key variable(s) before you merge them. By the way, you need to change the  VAR2 in your datafile2 to VAR1.  The key variables should be the same.

Cheers,
Johnny
 


--- On Fri, 10/8/10, Gene Maguin <[hidden email]> wrote:

From: Gene Maguin <[hidden email]>
Subject: Re: Merging files or Adding variables?
To: [hidden email]
Date: Friday, 8 October, 2010, 9:03 PM

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:SPSSX-L@...] On Behalf Of
Eins Bernardo
Sent: Friday, October 08, 2010 6:29 AM
To: SPSSX-L@...
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 <Thomas.Balmer@...> wrote:



        From: Balmer Thomas <Thomas.Balmer@...>
        Subject: Do if
        To: SPSSX-L@...
        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
        LISTSERV@... (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
LISTSERV@... (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