Selecting sets of cases sequentially for a CREATE command (time series)

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

Selecting sets of cases sequentially for a CREATE command (time series)

R Deighton
Hi people,

I haven't been able to do something which I initially felt wouldn't be that
difficult.

I have a series of diary entries in a times series dataset, where I have the
variables id (person, of which there are 8), and entry (a number from one to
60 showing which number diary entry is referenced), and some other
variables, something like this:

id  entry   var1
1     1         6
1     2         3
1     3         5
.      .          .  (etc.)
2     1         7
2     2         2
2     3         4
                      (etc.)

I simply want to create a time series lag variable for var1, but obviously I
don't want the lag to be calculated between one person's 60th entry and the
next person's first entry, so I want to find a way to perform this
separately for each different person. Several options don't seem to work or
be allowed by SPSS preceding a CREATE command, including:
 - TEMPORARY followed by SELECT IF,
 - DO IF
 - FILTER
 - LOOP

I have then turned to select if in a copied file, then using MATCH files
(something like below), but I haven't been able to find the right syntax.

SORT CASES BY id entry (A).
  DATASET NAME raw.
  DATASET COPY temp.
  DATASET ACTIVATE temp.
  SELECT IF id = 1.
  CREATE
  /var1_1=LAG(var1).
  SORT CASES BY id entry.
  MATCH FILES FILE raw / FILE* / BY id entry.
EXECUTE.

(Then repeat for each new id up to 8).

This doesn't work so far. I need to use another MATCH command to bring the
lag variable back to the raw file, but then for subsequent id values, the
'raw' dataset doesn't keeping adding the next lot of var1_1 values, but
stays on the values for id=1.

Any suggestions would be much appreciated!
Russell





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

Re: Selecting sets of cases sequentially for a CREATE command (time series)

David Marso
Administrator
SPLIT FILE BY ID.
CREATE .....
;-]


R Deighton wrote

> Hi people,
>
> I haven't been able to do something which I initially felt wouldn't be
> that
> difficult.
>
> I have a series of diary entries in a times series dataset, where I have
> the
> variables id (person, of which there are 8), and entry (a number from one
> to
> 60 showing which number diary entry is referenced), and some other
> variables, something like this:
>
> id  entry   var1
> 1     1         6
> 1     2         3
> 1     3         5
> .      .          .  (etc.)
> 2     1         7
> 2     2         2
> 2     3         4
>                       (etc.)
>
> I simply want to create a time series lag variable for var1, but obviously
> I
> don't want the lag to be calculated between one person's 60th entry and
> the
> next person's first entry, so I want to find a way to perform this
> separately for each different person. Several options don't seem to work
> or
> be allowed by SPSS preceding a CREATE command, including:
>  - TEMPORARY followed by SELECT IF,
>  - DO IF
>  - FILTER
>  - LOOP
>
> I have then turned to select if in a copied file, then using MATCH files
> (something like below), but I haven't been able to find the right syntax.
>
> SORT CASES BY id entry (A).
>   DATASET NAME raw.
>   DATASET COPY temp.
>   DATASET ACTIVATE temp.
>   SELECT IF id = 1.
>   CREATE
>   /var1_1=LAG(var1).
>   SORT CASES BY id entry.
>   MATCH FILES FILE raw / FILE* / BY id entry.
> EXECUTE.
>
> (Then repeat for each new id up to 8).
>
> This doesn't work so far. I need to use another MATCH command to bring the
> lag variable back to the raw file, but then for subsequent id values, the
> 'raw' dataset doesn't keeping adding the next lot of var1_1 values, but
> stays on the values for id=1.
>
> Any suggestions would be much appreciated!
> Russell
>
>
>
>
>
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Selecting sets of cases sequentially for a CREATE command (time series)

David Marso
Administrator
Also:

DO IF ID EQ LAG(ID).
COMPUTE newVar=LAG(Var).
END IF.

or

IF ID EQ LAG(ID) newVar=LAG(Var).

are also acceptable solutions as is
SPLIT FILE BY id.
SHIFT VALUES...
leave that to you to look into the syntax.


David Marso wrote

> SPLIT FILE BY ID.
> CREATE .....
> ;-]
>
>
> R Deighton wrote
>> Hi people,
>>
>> I haven't been able to do something which I initially felt wouldn't be
>> that
>> difficult.
>>
>> I have a series of diary entries in a times series dataset, where I have
>> the
>> variables id (person, of which there are 8), and entry (a number from one
>> to
>> 60 showing which number diary entry is referenced), and some other
>> variables, something like this:
>>
>> id  entry   var1
>> 1     1         6
>> 1     2         3
>> 1     3         5
>> .      .          .  (etc.)
>> 2     1         7
>> 2     2         2
>> 2     3         4
>>                       (etc.)
>>
>> I simply want to create a time series lag variable for var1, but
>> obviously
>> I
>> don't want the lag to be calculated between one person's 60th entry and
>> the
>> next person's first entry, so I want to find a way to perform this
>> separately for each different person. Several options don't seem to work
>> or
>> be allowed by SPSS preceding a CREATE command, including:
>>  - TEMPORARY followed by SELECT IF,
>>  - DO IF
>>  - FILTER
>>  - LOOP
>>
>> I have then turned to select if in a copied file, then using MATCH files
>> (something like below), but I haven't been able to find the right syntax.
>>
>> SORT CASES BY id entry (A).
>>   DATASET NAME raw.
>>   DATASET COPY temp.
>>   DATASET ACTIVATE temp.
>>   SELECT IF id = 1.
>>   CREATE
>>   /var1_1=LAG(var1).
>>   SORT CASES BY id entry.
>>   MATCH FILES FILE raw / FILE* / BY id entry.
>> EXECUTE.
>>
>> (Then repeat for each new id up to 8).
>>
>> This doesn't work so far. I need to use another MATCH command to bring
>> the
>> lag variable back to the raw file, but then for subsequent id values, the
>> 'raw' dataset doesn't keeping adding the next lot of var1_1 values, but
>> stays on the values for id=1.
>>
>> Any suggestions would be much appreciated!
>> Russell
>>
>>
>>
>>
>>
>> --
>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (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
>
>
>
>
>
> -----
> Please reply to the list and not to my personal email.
> Those desiring my consulting or training services please feel free to
> email me.
> ---
> "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos
> ne forte conculcent eas pedibus suis."
> Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in
> abyssum?"
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Selecting sets of cases sequentially for a CREATE command (time series)

R Deighton
Many thanks guys. I'm impressed again by your syntactical nimbleness. The
simple split file followed by create was best for my purposes, as I may need
to use CREATE as opposed to COMPUTE in order to use other subcommands apart
from LAG (like moving average).
Much obliged.




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

Re: Selecting sets of cases sequentially for a CREATE command (time series)

David Marso
Administrator
As you can see there are many ways to skin the cat.
I have been using SPSS since the devil was a little boy so I ought to be
pretty nimble.
Have been posting solutions in this group since the early 90's
--

R Deighton wrote

> Many thanks guys. I'm impressed again by your syntactical nimbleness. The
> simple split file followed by create was best for my purposes, as I may
> need
> to use CREATE as opposed to COMPUTE in order to use other subcommands
> apart
> from LAG (like moving average).
> Much obliged.
>
>
>
>
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
--
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"