"do repeat" code

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

"do repeat" code

Alina Sheyman-3
I am trying to match observations for 07 (07.1 through 07.5) to observations
for 08 (08.1 through 08.5) I wrote the following code, and it doesn't seem
to be working. Does anyone know what the problem is?


do repeat start2007 =start_date_07.1  to start_date_07.5/
start2008 =start_date_08.1 to start_date_08.5/
match=match1 to match 5.
compute match=start2007=start2008.
end repeat.


Also, what I would like to do ultimately is to compare each observation for
07 (7.1 through 7.5) to all of the observations for 08, rather than
comparing just 07.1 to 08.1. Is there anyway I can adjust the code to do this?

Thank you

=====================
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: "do repeat" code

Richard Ristow
At 03:18 PM 10/1/2008, Alina Sheyman wrote:

>I am trying to match observations for 07 (07.1 through 07.5) to
>observations for 08 (08.1 through 08.5) I wrote the following code,
>and it doesn't seem to be working. Does anyone know what the problem is?
>
>do repeat start2007 =start_date_07.1 to start_date_07.5/
>           start2008 =start_date_08.1 to start_date_08.5/
>           match     =match1          to match 5.
>.  compute match=start2007=start2008.
>end repeat.

I've reformatted your code, mostly for readability. Under >batch<
syntax rules, starting "start2008 =" in column 1 is a syntax error;
conceivably, that's your problem. Otherwise, I don't see anything wrong.

It's hard to fix something that "doesn't seem to be working." Can you
give us what error messages you got, if any; and a few test cases,
with the results you got?

-Good luck,
  Richard

=====================
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: "do repeat" code

Hashmi, Syed S
In reply to this post by Alina Sheyman-3
I'm not sure what you're trying to do here but the error might be in the
COMPUTE command, where you have "=" signs all through.
However, if what you're trying to do is create a new variable with
values that are equal to the 07 values only when those values themselves
equal an 08 value, then the following might help.

Try the following syntax (untested). This will compare 7.1 to 8.1, 7.2
to 8.2, and so on.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DO REPEAT start2007 =start_date_07.1  to start_date_07.5
 /start2008 =start_date_08.1 to start_date_08.5
 /match=match1 to match 5.
    DO IF start2007 = start2008.
      COMPUTE match = start2007.
    END IF.
END REPEAT.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


As for your second question you can use the ANY function to work that
out.  However, the syntax you use will depend on what you want.  If you
want to check if 07.1 matches any value from 08.1 to 08.5 then you'd do
it as follows (untested syntax):

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DO REPEAT start2007 =start_date_07.1  to start_date_07.5
/match=match1 to match 5.
    DO IF ANY(start2007, start_date_07.1  to start_date_07.5).
      COMPUTE match = start2007.
    END IF.
END REPEAT.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This will result in 5 new variables each corresponding to a different 07
variable.

If this is not what you were looking for, then try to post a few more
details including your specific error message.

HTH.

- Shahrukh



> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf
> Of Alina Sheyman
> Sent: Wednesday, October 01, 2008 2:19 PM
> To: [hidden email]
> Subject: "do repeat" code
>
> I am trying to match observations for 07 (07.1 through 07.5) to
> observations
> for 08 (08.1 through 08.5) I wrote the following code, and it doesn't
> seem
> to be working. Does anyone know what the problem is?
>
>
> do repeat start2007 =start_date_07.1  to start_date_07.5/
> start2008 =start_date_08.1 to start_date_08.5/
> match=match1 to match 5.
> compute match=start2007=start2008.
> end repeat.
>
>
> Also, what I would like to do ultimately is to compare each
observation

> for
> 07 (7.1 through 7.5) to all of the observations for 08, rather than
> comparing just 07.1 to 08.1. Is there anyway I can adjust the code to
> do this?
>
> Thank you
>
> =====================
> 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: "do repeat" code

Alina Sheyman-3
In reply to this post by Alina Sheyman-3
This is actually what I am trying to do, however when I run this code

DO REPEAT start2007 =start_date_07.1  to start_date_07.5
>/match=match1 to match 5.
>    DO IF ANY(start2007, start_date_07.1  to start_date_07.5).
>      COMPUTE match = start2007.
>    END IF.
>END REPEAT.

I get the follow errors

DO REPEAT start2007 =start_date_07.1  to start_date_07.5
/match=match1 to match 5.

>Error # 4512 in column 18.  Text: match
>The form VARX TO VARY to refer to a range of variables has been used
>incorrectly.  When using VARX TO VARY to create new variables, X must be an
>integer less than or equal to the integer Y.  (Can't use A3 TO A1.)
>This command not executed.
   DO IF ANY(start2007, start_date_07.1  to start_date_07.5).

>Error # 4285 in column 14.  Text: start2007
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.
     COMPUTE match = start2007.

>Error # 4285 in column 22.  Text: start2007
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.
   END IF.

>Error # 4070.  Command name: END IF
>The command does not follow an unclosed DO IF command.  Maybe the DO IF
>command was not recognized because of an error.  Use the level-of-control
>shown to the left of the SPSS commands to determine the range of LOOPs and DO
>IFs.
>This command not executed.
END REPEAT.

>Error # 4001.  Command name: END REPEAT
>An END REPEAT command has appeared without a previous DO REPEAT command.
>This command not executed.
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>

=====================
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: "do repeat" code

Oliver, Richard
In reply to this post by Hashmi, Syed S
I think the Compute statement is correct and does what is intended. The value of match is set to 1 (true) if the other two values are equal, otherwise match is set to 0 (false).

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Hashmi, Syed S
Sent: Wednesday, October 01, 2008 3:07 PM
To: [hidden email]
Subject: Re: "do repeat" code

I'm not sure what you're trying to do here but the error might be in the
COMPUTE command, where you have "=" signs all through.
However, if what you're trying to do is create a new variable with
values that are equal to the 07 values only when those values themselves
equal an 08 value, then the following might help.

Try the following syntax (untested). This will compare 7.1 to 8.1, 7.2
to 8.2, and so on.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DO REPEAT start2007 =start_date_07.1  to start_date_07.5
 /start2008 =start_date_08.1 to start_date_08.5
 /match=match1 to match 5.
    DO IF start2007 = start2008.
      COMPUTE match = start2007.
    END IF.
END REPEAT.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


As for your second question you can use the ANY function to work that
out.  However, the syntax you use will depend on what you want.  If you
want to check if 07.1 matches any value from 08.1 to 08.5 then you'd do
it as follows (untested syntax):

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DO REPEAT start2007 =start_date_07.1  to start_date_07.5
/match=match1 to match 5.
    DO IF ANY(start2007, start_date_07.1  to start_date_07.5).
      COMPUTE match = start2007.
    END IF.
END REPEAT.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This will result in 5 new variables each corresponding to a different 07
variable.

If this is not what you were looking for, then try to post a few more
details including your specific error message.

HTH.

- Shahrukh



> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf
> Of Alina Sheyman
> Sent: Wednesday, October 01, 2008 2:19 PM
> To: [hidden email]
> Subject: "do repeat" code
>
> I am trying to match observations for 07 (07.1 through 07.5) to
> observations
> for 08 (08.1 through 08.5) I wrote the following code, and it doesn't
> seem
> to be working. Does anyone know what the problem is?
>
>
> do repeat start2007 =start_date_07.1  to start_date_07.5/
> start2008 =start_date_08.1 to start_date_08.5/
> match=match1 to match 5.
> compute match=start2007=start2008.
> end repeat.
>
>
> Also, what I would like to do ultimately is to compare each
observation

> for
> 07 (7.1 through 7.5) to all of the observations for 08, rather than
> comparing just 07.1 to 08.1. Is there anyway I can adjust the code to
> do this?
>
> Thank you
>
> =====================
> 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: "do repeat" code

William Dudley WNDUDLEY
In reply to this post by Alina Sheyman-3
It look like you have a space between match and 5.


William N. Dudley, PhD
Associate Dean for Research
The School of Health and Human Performance Office of Research
The University of North Carolina at Greensboro
126 HHP Building, PO Box 26170
Greensboro, NC 27402-6170
VOICE 336.2562475
FAX 336.334.3238



Alina Sheyman <[hidden email]>
Sent by: "SPSSX(r) Discussion" <[hidden email]>
10/01/2008 04:39 PM
Please respond to
Alina Sheyman <[hidden email]>


To
[hidden email]
cc

Subject
Re: "do repeat" code






This is actually what I am trying to do, however when I run this code

DO REPEAT start2007 =start_date_07.1  to start_date_07.5
>/match=match1 to match 5.
>    DO IF ANY(start2007, start_date_07.1  to start_date_07.5).
>      COMPUTE match = start2007.
>    END IF.
>END REPEAT.

I get the follow errors

DO REPEAT start2007 =start_date_07.1  to start_date_07.5
/match=match1 to match 5.

>Error # 4512 in column 18.  Text: match
>The form VARX TO VARY to refer to a range of variables has been used
>incorrectly.  When using VARX TO VARY to create new variables, X must be
an
>integer less than or equal to the integer Y.  (Can't use A3 TO A1.)
>This command not executed.
   DO IF ANY(start2007, start_date_07.1  to start_date_07.5).

>Error # 4285 in column 14.  Text: start2007
>Incorrect variable name: either the name is more than 64 characters, or
it is
>not defined by a previous command.
>This command not executed.
     COMPUTE match = start2007.

>Error # 4285 in column 22.  Text: start2007
>Incorrect variable name: either the name is more than 64 characters, or
it is
>not defined by a previous command.
>This command not executed.
   END IF.

>Error # 4070.  Command name: END IF
>The command does not follow an unclosed DO IF command.  Maybe the DO IF
>command was not recognized because of an error.  Use the level-of-control
>shown to the left of the SPSS commands to determine the range of LOOPs
and DO
>IFs.
>This command not executed.
END REPEAT.

>Error # 4001.  Command name: END REPEAT
>An END REPEAT command has appeared without a previous DO REPEAT command.
>This command not executed.
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>

=====================
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: "do repeat" code

ViAnn Beadle
In reply to this post by Alina Sheyman-3
You've got a space between match and 5 for the /match stand-in variable.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Alina Sheyman
Sent: Wednesday, October 01, 2008 2:37 PM
To: [hidden email]
Subject: Re: "do repeat" code

This is actually what I am trying to do, however when I run this code

DO REPEAT start2007 =start_date_07.1  to start_date_07.5
>/match=match1 to match 5.
>    DO IF ANY(start2007, start_date_07.1  to start_date_07.5).
>      COMPUTE match = start2007.
>    END IF.
>END REPEAT.

I get the follow errors

DO REPEAT start2007 =start_date_07.1  to start_date_07.5
/match=match1 to match 5.

>Error # 4512 in column 18.  Text: match
>The form VARX TO VARY to refer to a range of variables has been used
>incorrectly.  When using VARX TO VARY to create new variables, X must be an
>integer less than or equal to the integer Y.  (Can't use A3 TO A1.)
>This command not executed.
   DO IF ANY(start2007, start_date_07.1  to start_date_07.5).

>Error # 4285 in column 14.  Text: start2007
>Incorrect variable name: either the name is more than 64 characters, or it
is
>not defined by a previous command.
>This command not executed.
     COMPUTE match = start2007.

>Error # 4285 in column 22.  Text: start2007
>Incorrect variable name: either the name is more than 64 characters, or it
is
>not defined by a previous command.
>This command not executed.
   END IF.

>Error # 4070.  Command name: END IF
>The command does not follow an unclosed DO IF command.  Maybe the DO IF
>command was not recognized because of an error.  Use the level-of-control
>shown to the left of the SPSS commands to determine the range of LOOPs and
DO
>IFs.
>This command not executed.
END REPEAT.

>Error # 4001.  Command name: END REPEAT
>An END REPEAT command has appeared without a previous DO REPEAT command.
>This command not executed.
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>

=====================
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: "do repeat" code

Alina Sheyman-3
In reply to this post by Alina Sheyman-3
Fixed the space, but something is still not being calculated correctly -
identical values that should show up as "1" in the new match variable, show
up blank. I'm working with dates, might that be complicating things?


On Wed, 1 Oct 2008 14:42:39 -0600, ViAnn Beadle <[hidden email]> wrote:

>You've got a space between match and 5 for the /match stand-in variable.
>
>-----Original Message-----
>From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
>Alina Sheyman
>Sent: Wednesday, October 01, 2008 2:37 PM
>To: [hidden email]
>Subject: Re: "do repeat" code
>
>This is actually what I am trying to do, however when I run this code
>
>DO REPEAT start2007 =start_date_07.1  to start_date_07.5
>>/match=match1 to match 5.
>>    DO IF ANY(start2007, start_date_07.1  to start_date_07.5).
>>      COMPUTE match = start2007.
>>    END IF.
>>END REPEAT.
>
>I get the follow errors
>
>DO REPEAT start2007 =start_date_07.1  to start_date_07.5
>/match=match1 to match 5.
>
>>Error # 4512 in column 18.  Text: match
>>The form VARX TO VARY to refer to a range of variables has been used
>>incorrectly.  When using VARX TO VARY to create new variables, X must be an
>>integer less than or equal to the integer Y.  (Can't use A3 TO A1.)
>>This command not executed.
>   DO IF ANY(start2007, start_date_07.1  to start_date_07.5).
>
>>Error # 4285 in column 14.  Text: start2007
>>Incorrect variable name: either the name is more than 64 characters, or it
>is
>>not defined by a previous command.
>>This command not executed.
>     COMPUTE match = start2007.
>
>>Error # 4285 in column 22.  Text: start2007
>>Incorrect variable name: either the name is more than 64 characters, or it
>is
>>not defined by a previous command.
>>This command not executed.
>   END IF.
>
>>Error # 4070.  Command name: END IF
>>The command does not follow an unclosed DO IF command.  Maybe the DO IF
>>command was not recognized because of an error.  Use the level-of-control
>>shown to the left of the SPSS commands to determine the range of LOOPs and
>DO
>>IFs.
>>This command not executed.
>END REPEAT.
>
>>Error # 4001.  Command name: END REPEAT
>>An END REPEAT command has appeared without a previous DO REPEAT command.
>>This command not executed.
>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>
>=====================
>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: "do repeat" code

Melissa Ives
You are also missing a period at the end of the DO REPEAT command.
(Why do you have variable names with embedded periods?  Seems to me that would be confusing.)


Melissa

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Alina Sheyman
Sent: Wednesday, October 01, 2008 3:52 PM
To: [hidden email]
Subject: Re: [SPSSX-L] "do repeat" code

Fixed the space, but something is still not being calculated correctly - identical values that should show up as "1" in the new match variable, show up blank. I'm working with dates, might that be complicating things?


On Wed, 1 Oct 2008 14:42:39 -0600, ViAnn Beadle <[hidden email]> wrote:

>You've got a space between match and 5 for the /match stand-in variable.
>
>-----Original Message-----
>From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf
>Of Alina Sheyman
>Sent: Wednesday, October 01, 2008 2:37 PM
>To: [hidden email]
>Subject: Re: "do repeat" code
>
>This is actually what I am trying to do, however when I run this code
>
>DO REPEAT start2007 =start_date_07.1  to start_date_07.5
>>/match=match1 to match 5.
>>    DO IF ANY(start2007, start_date_07.1  to start_date_07.5).
>>      COMPUTE match = start2007.
>>    END IF.
>>END REPEAT.
>
>I get the follow errors
>
>DO REPEAT start2007 =start_date_07.1  to start_date_07.5
>/match=match1 to match 5.
>
>>Error # 4512 in column 18.  Text: match The form VARX TO VARY to refer
>>to a range of variables has been used incorrectly.  When using VARX TO
>>VARY to create new variables, X must be an integer less than or equal
>>to the integer Y.  (Can't use A3 TO A1.) This command not executed.
>   DO IF ANY(start2007, start_date_07.1  to start_date_07.5).
>
>>Error # 4285 in column 14.  Text: start2007 Incorrect variable name:
>>either the name is more than 64 characters, or it
>is
>>not defined by a previous command.
>>This command not executed.
>     COMPUTE match = start2007.
>
>>Error # 4285 in column 22.  Text: start2007 Incorrect variable name:
>>either the name is more than 64 characters, or it
>is
>>not defined by a previous command.
>>This command not executed.
>   END IF.
>
>>Error # 4070.  Command name: END IF
>>The command does not follow an unclosed DO IF command.  Maybe the DO
>>IF command was not recognized because of an error.  Use the
>>level-of-control shown to the left of the SPSS commands to determine
>>the range of LOOPs and
>DO
>>IFs.
>>This command not executed.
>END REPEAT.
>
>>Error # 4001.  Command name: END REPEAT An END REPEAT command has
>>appeared without a previous DO REPEAT command.
>>This command not executed.
>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>
>=====================
>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

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: "do repeat" code

Maguin, Eugene
In reply to this post by Alina Sheyman-3
Alina,

Ok, good, you fixed the extra space character. So now you are running this
code (tidied up a bit).

DO REPEAT start2007=start_date_07.1 to start_date_07.5/
   match=match1 to match5.
   DO IF ANY(start2007, start_date_07.1 to start_date_07.5).
      COMPUTE match = start2007.
   END IF.
END REPEAT.

And you say,
>>Fixed the space, but something is still not being calculated correctly -
identical values that should show up as "1" in the new match variable, show
up blank. I'm working with dates, might that be complicating things?

That's a clever use of the Any function but I wonder if there is trouble
because of that. I've nerver used Any so probably there's something for me
to learn here. My question is what happens to the evaluation of the Any
function if one or more of the variables in the list have a missing value
for the case. Does Any return sysmis for the case or does it skip that
variable and base the evaluation on the remaining variables? If this is
plausible, can anyone comment on how Any works in this situation?

Gene Maguin

=====================
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: "do repeat" code

Art Kendall
In reply to this post by Alina Sheyman-3
Open a new instance of SPSS.
copy, past, and run the syntax below.

see which one is what you want.
If neither is, edit the data section and add 5 variables want1 to
want5.  and repost your request to the list.
Add more "cases" if that is necessary to clarify what you are looking for.

data list list /id (f2)start_date_07.1 to start_date_07.5
start_date_08.1 to start_date_08.5 (10adate10).
begin data.
01 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007 10/01/2008
10/02/2008 10/07/2008 11/13/2008 11/29/2008
02 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007  9/01/2008
10/01/2008 10/02/2008 10/07/2008 11/15/2008
03 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007  9/01/2008
9/01/2008 10/01/2008 10/07/2008 11/15/2008
04 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007 10/01/2008
10/03/2008 10/07/2008 11/07/2008 11/29/2008
end data.

* find if dates with same index are the "same".
do repeat start2007 =start_date_07.1  to start_date_07.5/
          start2008 =start_date_08.1 to start_date_08.5/
          match=match1 to match5.
compute match=datesum(start2007,1,"years","closest") eq start2008.
end repeat.
formats match1 to match5 (f1).
list vars= id match1 to match5.


* find out if any of the 2008 dates are the same as a 2007 date.
do repeat start2007 =start_date_07.1  to start_date_07.5/
          match=match1 to match5.
compute match=any(datesum(start2007,1,"years","closest"),start_date_08.1
to start_date_08.5).
end repeat.
formats match1 to match5 (f1).
list vars= id match1 to match5.


Art Kendall
Social Research Consultants

Alina Sheyman wrote:

> I am trying to match observations for 07 (07.1 through 07.5) to observations
> for 08 (08.1 through 08.5) I wrote the following code, and it doesn't seem
> to be working. Does anyone know what the problem is?
>
>
> do repeat start2007 =start_date_07.1  to start_date_07.5/
> start2008 =start_date_08.1 to start_date_08.5/
> match=match1 to match 5.
> compute match=start2007=start2008.
> end repeat.
>
>
> Also, what I would like to do ultimately is to compare each observation for
> 07 (7.1 through 7.5) to all of the observations for 08, rather than
> comparing just 07.1 to 08.1. Is there anyway I can adjust the code to do this?
>
> Thank you
>
> =====================
> 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: "do repeat" code

Alina Sheyman-3
In reply to this post by Alina Sheyman-3
Art,

 This is great, thank you.
A follow-up question is this - if I want to know whether the dates are in
some range of each other (ie. between one and three years apart)rather than
an exact value apart, is there some way to do it?
Looking at "help" it seems this function only works with exact values.



On Wed, 1 Oct 2008 17:26:42 -0400, Art Kendall <[hidden email]> wrote:

>Open a new instance of SPSS.
>copy, past, and run the syntax below.
>
>see which one is what you want.
>If neither is, edit the data section and add 5 variables want1 to
>want5.  and repost your request to the list.
>Add more "cases" if that is necessary to clarify what you are looking for.
>
>data list list /id (f2)start_date_07.1 to start_date_07.5
>start_date_08.1 to start_date_08.5 (10adate10).
>begin data.
>01 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007 10/01/2008
>10/02/2008 10/07/2008 11/13/2008 11/29/2008
>02 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007  9/01/2008
>10/01/2008 10/02/2008 10/07/2008 11/15/2008
>03 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007  9/01/2008
>9/01/2008 10/01/2008 10/07/2008 11/15/2008
>04 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007 10/01/2008
>10/03/2008 10/07/2008 11/07/2008 11/29/2008
>end data.
>
>* find if dates with same index are the "same".
>do repeat start2007 =start_date_07.1  to start_date_07.5/
>          start2008 =start_date_08.1 to start_date_08.5/
>          match=match1 to match5.
>compute match=datesum(start2007,1,"years","closest") eq start2008.
>end repeat.
>formats match1 to match5 (f1).
>list vars= id match1 to match5.
>
>
>* find out if any of the 2008 dates are the same as a 2007 date.
>do repeat start2007 =start_date_07.1  to start_date_07.5/
>          match=match1 to match5.
>compute match=any(datesum(start2007,1,"years","closest"),start_date_08.1
>to start_date_08.5).
>end repeat.
>formats match1 to match5 (f1).
>list vars= id match1 to match5.
>
>
>Art Kendall
>Social Research Consultants
>
>Alina Sheyman wrote:
>> I am trying to match observations for 07 (07.1 through 07.5) to observations
>> for 08 (08.1 through 08.5) I wrote the following code, and it doesn't seem
>> to be working. Does anyone know what the problem is?
>>
>>
>> do repeat start2007 =start_date_07.1  to start_date_07.5/
>> start2008 =start_date_08.1 to start_date_08.5/
>> match=match1 to match 5.
>> compute match=start2007=start2008.
>> end repeat.
>>
>>
>> Also, what I would like to do ultimately is to compare each observation for
>> 07 (7.1 through 7.5) to all of the observations for 08, rather than
>> comparing just 07.1 to 08.1. Is there anyway I can adjust the code to do
this?

>>
>> Thank you
>>
>> =====================
>> 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: "do repeat" code

Alina Sheyman-3
In reply to this post by Alina Sheyman-3
Also,
 what if I want to test each of the 07 dates against each of the 08 dates,
meaning that I want SPSS to return 25 "match" variables. Can I adjust the
code to do that?

On Wed, 1 Oct 2008 17:26:42 -0400, Art Kendall <[hidden email]> wrote:

>Open a new instance of SPSS.
>copy, past, and run the syntax below.
>
>see which one is what you want.
>If neither is, edit the data section and add 5 variables want1 to
>want5.  and repost your request to the list.
>Add more "cases" if that is necessary to clarify what you are looking for.
>
>data list list /id (f2)start_date_07.1 to start_date_07.5
>start_date_08.1 to start_date_08.5 (10adate10).
>begin data.
>01 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007 10/01/2008
>10/02/2008 10/07/2008 11/13/2008 11/29/2008
>02 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007  9/01/2008
>10/01/2008 10/02/2008 10/07/2008 11/15/2008
>03 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007  9/01/2008
>9/01/2008 10/01/2008 10/07/2008 11/15/2008
>04 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007 10/01/2008
>10/03/2008 10/07/2008 11/07/2008 11/29/2008
>end data.
>
>* find if dates with same index are the "same".
>do repeat start2007 =start_date_07.1  to start_date_07.5/
>          start2008 =start_date_08.1 to start_date_08.5/
>          match=match1 to match5.
>compute match=datesum(start2007,1,"years","closest") eq start2008.
>end repeat.
>formats match1 to match5 (f1).
>list vars= id match1 to match5.
>
>
>* find out if any of the 2008 dates are the same as a 2007 date.
>do repeat start2007 =start_date_07.1  to start_date_07.5/
>          match=match1 to match5.
>compute match=any(datesum(start2007,1,"years","closest"),start_date_08.1
>to start_date_08.5).
>end repeat.
>formats match1 to match5 (f1).
>list vars= id match1 to match5.
>
>
>Art Kendall
>Social Research Consultants
>
>Alina Sheyman wrote:
>> I am trying to match observations for 07 (07.1 through 07.5) to observations
>> for 08 (08.1 through 08.5) I wrote the following code, and it doesn't seem
>> to be working. Does anyone know what the problem is?
>>
>>
>> do repeat start2007 =start_date_07.1  to start_date_07.5/
>> start2008 =start_date_08.1 to start_date_08.5/
>> match=match1 to match 5.
>> compute match=start2007=start2008.
>> end repeat.
>>
>>
>> Also, what I would like to do ultimately is to compare each observation for
>> 07 (7.1 through 7.5) to all of the observations for 08, rather than
>> comparing just 07.1 to 08.1. Is there anyway I can adjust the code to do
this?

>>
>> Thank you
>>
>> =====================
>> 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: "do repeat" code

Art Kendall
In reply to this post by Alina Sheyman-3
compute match= range(datediff(start2008, start2007,"years"),1,3) .

Art Kendall
Social Research Consultants

Alina Sheyman wrote:

> Art,
>
>  This is great, thank you.
> A follow-up question is this - if I want to know whether the dates are in
> some range of each other (ie. between one and three years apart)rather than
> an exact value apart, is there some way to do it?
> Looking at "help" it seems this function only works with exact values.
>
>
>
> On Wed, 1 Oct 2008 17:26:42 -0400, Art Kendall <[hidden email]> wrote:
>
>
>> Open a new instance of SPSS.
>> copy, past, and run the syntax below.
>>
>> see which one is what you want.
>> If neither is, edit the data section and add 5 variables want1 to
>> want5.  and repost your request to the list.
>> Add more "cases" if that is necessary to clarify what you are looking for.
>>
>> data list list /id (f2)start_date_07.1 to start_date_07.5
>> start_date_08.1 to start_date_08.5 (10adate10).
>> begin data.
>> 01 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007 10/01/2008
>> 10/02/2008 10/07/2008 11/13/2008 11/29/2008
>> 02 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007  9/01/2008
>> 10/01/2008 10/02/2008 10/07/2008 11/15/2008
>> 03 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007  9/01/2008
>> 9/01/2008 10/01/2008 10/07/2008 11/15/2008
>> 04 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007 10/01/2008
>> 10/03/2008 10/07/2008 11/07/2008 11/29/2008
>> end data.
>>
>> * find if dates with same index are the "same".
>> do repeat start2007 =start_date_07.1  to start_date_07.5/
>>          start2008 =start_date_08.1 to start_date_08.5/
>>          match=match1 to match5.
>> compute match=datesum(start2007,1,"years","closest") eq start2008.
>> end repeat.
>> formats match1 to match5 (f1).
>> list vars= id match1 to match5.
>>
>>
>> * find out if any of the 2008 dates are the same as a 2007 date.
>> do repeat start2007 =start_date_07.1  to start_date_07.5/
>>          match=match1 to match5.
>> compute match=any(datesum(start2007,1,"years","closest"),start_date_08.1
>> to start_date_08.5).
>> end repeat.
>> formats match1 to match5 (f1).
>> list vars= id match1 to match5.
>>
>>
>> Art Kendall
>> Social Research Consultants
>>
>> Alina Sheyman wrote:
>>
>>> I am trying to match observations for 07 (07.1 through 07.5) to observations
>>> for 08 (08.1 through 08.5) I wrote the following code, and it doesn't seem
>>> to be working. Does anyone know what the problem is?
>>>
>>>
>>> do repeat start2007 =start_date_07.1  to start_date_07.5/
>>> start2008 =start_date_08.1 to start_date_08.5/
>>> match=match1 to match 5.
>>> compute match=start2007=start2008.
>>> end repeat.
>>>
>>>
>>> Also, what I would like to do ultimately is to compare each observation for
>>> 07 (7.1 through 7.5) to all of the observations for 08, rather than
>>> comparing just 07.1 to 08.1. Is there anyway I can adjust the code to do
>>>
> this?
>
>>> Thank you
>>>
>>> =====================
>>> 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
>
>
>

=====================
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: "do repeat" code

Art Kendall
In reply to this post by Alina Sheyman-3
Open a new instance of SPSS.  Cut, paste, and run the syntax below.
Then check whether you agree with the results.
If you disagree please point out where you disagree.
If you agree, adapt the syntax to your situation.
data list free /id (f2)start_date_07.1 to start_date_07.5
start_date_08.1 to start_date_08.5 (10adate10).
begin data.
01 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007 10/01/2008
10/02/2008 10/07/2008 11/13/2008 11/29/2008
02 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007  9/01/2008
10/01/2008 10/02/2008 10/07/2008 11/15/2008
03 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007  9/01/2008
9/01/2008 10/01/2008 10/07/2008 11/15/2008
04 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007 10/01/2008
10/03/2008 10/07/2008 11/07/2008 11/29/2008
end data.
vector
  match1_ (5,f1)
  match2_ (5,f1)
  match3_ (5,f1)
  match4_ (5,f1)
  match5_ (5,f1).
vector
  x2007 = start_date_07.1 to start_date_07.5
 /x2008 = start_date_08.1 to start_date_08.5.
* find if each pair of dates is a match or not.
loop #i = 1 to 5.
compute match1_(#i) = range(datediff(x2008(#i), x2007(1),"years"),1,3) .
compute match2_(#i) = range(datediff(x2008(#i), x2007(2),"years"),1,3) .
compute match3_(#i) = range(datediff(x2008(#i), x2007(3),"years"),1,3) .
compute match4_(#i) = range(datediff(x2008(#i), x2007(4),"years"),1,3) .
compute match5_(#i) = range(datediff(x2008(#i), x2007(5),"years"),1,3) .
end loop.
list vars= id match1_1 to match5_5.


Art Kendall
Social Research Consultants

Alina Sheyman wrote:

> Also,
>  what if I want to test each of the 07 dates against each of the 08 dates,
> meaning that I want SPSS to return 25 "match" variables. Can I adjust the
> code to do that?
>
> On Wed, 1 Oct 2008 17:26:42 -0400, Art Kendall <[hidden email]> wrote:
>
>
>> Open a new instance of SPSS.
>> copy, past, and run the syntax below.
>>
>> see which one is what you want.
>> If neither is, edit the data section and add 5 variables want1 to
>> want5.  and repost your request to the list.
>> Add more "cases" if that is necessary to clarify what you are looking for.
>>
>> data list list /id (f2)start_date_07.1 to start_date_07.5
>> start_date_08.1 to start_date_08.5 (10adate10).
>> begin data.
>> 01 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007 10/01/2008
>> 10/02/2008 10/07/2008 11/13/2008 11/29/2008
>> 02 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007  9/01/2008
>> 10/01/2008 10/02/2008 10/07/2008 11/15/2008
>> 03 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007  9/01/2008
>> 9/01/2008 10/01/2008 10/07/2008 11/15/2008
>> 04 10/01/2007 10/02/2007 10/07/2007 11/13/2007 11/29/2007 10/01/2008
>> 10/03/2008 10/07/2008 11/07/2008 11/29/2008
>> end data.
>>
>> * find if dates with same index are the "same".
>> do repeat start2007 =start_date_07.1  to start_date_07.5/
>>          start2008 =start_date_08.1 to start_date_08.5/
>>          match=match1 to match5.
>> compute match=datesum(start2007,1,"years","closest") eq start2008.
>> end repeat.
>> formats match1 to match5 (f1).
>> list vars= id match1 to match5.
>>
>>
>> * find out if any of the 2008 dates are the same as a 2007 date.
>> do repeat start2007 =start_date_07.1  to start_date_07.5/
>>          match=match1 to match5.
>> compute match=any(datesum(start2007,1,"years","closest"),start_date_08.1
>> to start_date_08.5).
>> end repeat.
>> formats match1 to match5 (f1).
>> list vars= id match1 to match5.
>>
>>
>> Art Kendall
>> Social Research Consultants
>>
>> Alina Sheyman wrote:
>>
>>> I am trying to match observations for 07 (07.1 through 07.5) to observations
>>> for 08 (08.1 through 08.5) I wrote the following code, and it doesn't seem
>>> to be working. Does anyone know what the problem is?
>>>
>>>
>>> do repeat start2007 =start_date_07.1  to start_date_07.5/
>>> start2008 =start_date_08.1 to start_date_08.5/
>>> match=match1 to match 5.
>>> compute match=start2007=start2008.
>>> end repeat.
>>>
>>>
>>> Also, what I would like to do ultimately is to compare each observation for
>>> 07 (7.1 through 7.5) to all of the observations for 08, rather than
>>> comparing just 07.1 to 08.1. Is there anyway I can adjust the code to do
>>>
> this?
>
>>> Thank you
>>>
>>> =====================
>>> 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
>
>
>

=====================
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: "do repeat" code

Richard Ristow
In reply to this post by Alina Sheyman-3
At 12:13 PM 10/2/2008, Alina Sheyman wrote:

>  what if I want to test each of the 07 dates against each of the 08
> dates, meaning that I want SPSS to return 25 "match" variables. Can
> I adjust the code to do that?

So you have variables for all 07 dates >and< variables for all 08 dates.

It looked, from your code, like you combined them from multiple
records using CASESTOVARS. You can simplify your logic by using
CASESTOVARS for 08 only, so each 07 date still is in a separate
record. Then, your logic need only compare the single 07 date (in the
record being processed) to the 08 dates in the same record.

But for a solution to what, I think, is the same problem, not using
CASESTOVARS at all, see my posting "Re: working with multiple files
without merge", going out the same time I send this one.

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