Subtracting case values to create a new variable

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

Subtracting case values to create a new variable

Linda Case
I am reposting this as I did not see it posted last week and have not gotten
any replies, so am wondering if it was not posted (my apologies if this is a
repeat)

Linda


Thanks for this code. I tried it and it worked, but as you noted, did not
delineate between subjects. There are multiple subjects (dogs, actually).
They are identified under the variable "Name", and so each dog has 26
records (rows), one for each week.


So, could you tell me how to tell SPSS to delineate between the individual
subjects when I compute BW difference between weeks using the code that you
provided?

Thanks in advance!

Linda

Linda P. Case
AutumnGold Consulting
(217) 586-4864
www.autumngoldconsulting.com
[hidden email] or [hidden email]
-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Richard Ristow
Sent: Friday, April 25, 2008 2:28 PM
To: [hidden email]
Subject: Re: Subtracting case values to create a new variable

At 12:15 PM 4/25/2008, Linda Case wrote:

>I have a set of longitudinal data comprised of 26 weeks.  I have
>"week" as a variable and several dependent variables of interest.
>One of these is body weight. I would like to calculate a new
>variable of change in BW per week

Assuming that each week's data is a separate SPSS record, function
LAG was invented for this:

COMPUTE BWchange = BW - LAG(BW).

If you have several people in the file, you need extra code to make
sure you don't treat person 2's week 1 as 'following' person 1's week 26.

And if your data isn't organized like this, post again, telling us
how it is laid out.

=====================
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: Subtracting case values to create a new variable

Melissa Ives
Linda,

This is actually the 3rd time this was posted.

Assuming that there is only one dog per name...
Put the compute statement within an if lagging on name.
Be sure to sort by name and week first.

If (name=lag(name)) BWchange = BW - LAG(BW).

Melissa

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Linda Case
Sent: Monday, April 28, 2008 11:09 AM
To: [hidden email]
Subject: [SPSSX-L] Subtracting case values to create a new variable

I am reposting this as I did not see it posted last week and have not gotten any replies, so am wondering if it was not posted (my apologies if this is a
repeat)

Linda


Thanks for this code. I tried it and it worked, but as you noted, did not delineate between subjects. There are multiple subjects (dogs, actually).
They are identified under the variable "Name", and so each dog has 26 records (rows), one for each week.


So, could you tell me how to tell SPSS to delineate between the individual subjects when I compute BW difference between weeks using the code that you provided?

Thanks in advance!

Linda

Linda P. Case
AutumnGold Consulting
(217) 586-4864
www.autumngoldconsulting.com
[hidden email] or [hidden email] -----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Richard Ristow
Sent: Friday, April 25, 2008 2:28 PM
To: [hidden email]
Subject: Re: Subtracting case values to create a new variable

At 12:15 PM 4/25/2008, Linda Case wrote:

>I have a set of longitudinal data comprised of 26 weeks.  I have "week"
>as a variable and several dependent variables of interest.
>One of these is body weight. I would like to calculate a new variable
>of change in BW per week

Assuming that each week's data is a separate SPSS record, function LAG was invented for this:

COMPUTE BWchange = BW - LAG(BW).

If you have several people in the file, you need extra code to make sure you don't treat person 2's week 1 as 'following' person 1's week 26.

And if your data isn't organized like this, post again, telling us how it is laid out.

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

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.

=====================
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: Subtracting case values to create a new variable

Linda Case
Thanks Melissa!  (Sorry for the repeats - for some reason I did not get the
posts).

Linda

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Melissa Ives
Sent: Monday, April 28, 2008 11:14 AM
To: [hidden email]
Subject: Re: Subtracting case values to create a new variable

Linda,

This is actually the 3rd time this was posted.

Assuming that there is only one dog per name...
Put the compute statement within an if lagging on name.
Be sure to sort by name and week first.

If (name=lag(name)) BWchange = BW - LAG(BW).

Melissa

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Linda Case
Sent: Monday, April 28, 2008 11:09 AM
To: [hidden email]
Subject: [SPSSX-L] Subtracting case values to create a new variable

I am reposting this as I did not see it posted last week and have not gotten
any replies, so am wondering if it was not posted (my apologies if this is a
repeat)

Linda


Thanks for this code. I tried it and it worked, but as you noted, did not
delineate between subjects. There are multiple subjects (dogs, actually).
They are identified under the variable "Name", and so each dog has 26
records (rows), one for each week.


So, could you tell me how to tell SPSS to delineate between the individual
subjects when I compute BW difference between weeks using the code that you
provided?

Thanks in advance!

Linda

Linda P. Case
AutumnGold Consulting
(217) 586-4864
www.autumngoldconsulting.com
[hidden email] or [hidden email] -----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Richard Ristow
Sent: Friday, April 25, 2008 2:28 PM
To: [hidden email]
Subject: Re: Subtracting case values to create a new variable

At 12:15 PM 4/25/2008, Linda Case wrote:

>I have a set of longitudinal data comprised of 26 weeks.  I have "week"
>as a variable and several dependent variables of interest.
>One of these is body weight. I would like to calculate a new variable
>of change in BW per week

Assuming that each week's data is a separate SPSS record, function LAG was
invented for this:

COMPUTE BWchange = BW - LAG(BW).

If you have several people in the file, you need extra code to make sure you
don't treat person 2's week 1 as 'following' person 1's week 26.

And if your data isn't organized like this, post again, telling us how it is
laid out.

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

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.

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