Help in calculating spell lengths

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

Help in calculating spell lengths

David Rosenbluth
I have an SPSS problem that I'm having difficulty solving.



I am trying to calculate the length of the initial spell that people are in a social service program. I have an array of variables month1 to month9. For each record, every month variable (m1 to m9) has a 0 (indicating no program participation) or a 1 (indicating participation).



e.g.

     m1       m2       m3      m4       m5       m6       m7       m8       m9

     .00      1.00     1.00     1.00     1.00      .00       .00      1.00      .00

     .00       .00      1.00     1.00      .00       .00      1.00      .00      1.00

    1.00     1.00     1.00     1.00     1.00     1.00     1.00     1.00     1.00

     .00       .00      1.00      .00      1.00      .00      1.00      .00      1.00



I would like to calculate the length of a person's first spell - that involves going through each array until you hit the first '1' and then calculating all the consecutive months where the value is '1'.



So in the data above, the first person would have an initial spell of 4 months; the 2nd person would have a spell of 2 months; the third person 9 months; and the 4th person 1 month.



I'm having difficulty figuring out how to do this. I can create a loop if everyone starts in month1, but I can't figure out the syntax when people have different starting months. Can anyone provide suggestions?



Thanks.

=====================
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:Help in calculating spell lengths

Jerabek Jindrich
Hello David,

following syntax should do the job.

COMPUTE #found = 0.
VECTOR m = m1 to m9.
COMPUTE initial=0.
LOOP #i=1 to 9.
DO IF m(#i)=1.
COMPUTE #found=1.
COMPUTE initial = initial +1.
END IF.
END LOOP if #found and m(#i)=0.
END LOOP.
EXEC.

regards
Jindra

> ------------ Původní zpráva ------------
> Od: David Rosenbluth <[hidden email]>
> Předmět: Help in calculating spell lengths
> Datum: 17.4.2008 05:44:51
> ----------------------------------------
> I have an SPSS problem that I'm having difficulty solving.
>
>
>
> I am trying to calculate the length of the initial spell that people are in a
> social service program. I have an array of variables month1 to month9. For each
> record, every month variable (m1 to m9) has a 0 (indicating no program
> participation) or a 1 (indicating participation).
>
>
>
> e.g.
>
>      m1       m2       m3      m4       m5       m6       m7       m8       m9
>
>      .00      1.00     1.00     1.00     1.00      .00       .00      1.00
> .00
>
>      .00       .00      1.00     1.00      .00       .00      1.00      .00
> 1.00
>
>     1.00     1.00     1.00     1.00     1.00     1.00     1.00     1.00
> 1.00
>
>      .00       .00      1.00      .00      1.00      .00      1.00      .00
> 1.00
>
>
>
> I would like to calculate the length of a person's first spell - that involves
> going through each array until you hit the first '1' and then calculating all
> the consecutive months where the value is '1'.
>
>
>
> So in the data above, the first person would have an initial spell of 4 months;
> the 2nd person would have a spell of 2 months; the third person 9 months; and
> the 4th person 1 month.
>
>
>
> I'm having difficulty figuring out how to do this. I can create a loop if
> everyone starts in month1, but I can't figure out the syntax when people have
> different starting months. Can anyone provide suggestions?
>
>
>
> Thanks.
>
> =====================
> 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: Help in calculating spell lengths

Albert-Jan Roskam
In reply to this post by David Rosenbluth
Hi David!

Does this do what you want?

* sample data.
data list free
  / m1 (f1) m2 (f1) m3 (f1) m4 (f1) m5 (f1) m6 (f1) m7
(f1) m8 (f1) m9 (f1).
begin data
0 1 1 1 1 0 0 1 0
0 0 1 1 0 0 1 0 1
1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1
end data.

* actual code.
compute spell = 0.
formats spell (f4.0).
vector v = m1 to m9.
loop #row = 1 to 9.
+ if (v(#row) = 1) spell = spell + 1.
end loop if (v(#row) = 0 and spell > 0).
list spell.

Cheers!!
Albert-Jan




--- David Rosenbluth <[hidden email]>
wrote:

> I have an SPSS problem that I'm having difficulty
> solving.
>
>
>
> I am trying to calculate the length of the initial
> spell that people are in a social service program. I
> have an array of variables month1 to month9. For
> each record, every month variable (m1 to m9) has a 0
> (indicating no program participation) or a 1
> (indicating participation).
>
>
>
> e.g.
>
>      m1       m2       m3      m4       m5       m6
>      m7       m8       m9
>
>      .00      1.00     1.00     1.00     1.00
> .00       .00      1.00      .00
>
>      .00       .00      1.00     1.00      .00
> .00      1.00      .00      1.00
>
>     1.00     1.00     1.00     1.00     1.00
> 1.00     1.00     1.00     1.00
>
>      .00       .00      1.00      .00      1.00
> .00      1.00      .00      1.00
>
>
>
> I would like to calculate the length of a person's
> first spell - that involves going through each array
> until you hit the first '1' and then calculating all
> the consecutive months where the value is '1'.
>
>
>
> So in the data above, the first person would have an
> initial spell of 4 months; the 2nd person would have
> a spell of 2 months; the third person 9 months; and
> the 4th person 1 month.
>
>
>
> I'm having difficulty figuring out how to do this. I
> can create a loop if everyone starts in month1, but
> I can't figure out the syntax when people have
> different starting months. Can anyone provide
> suggestions?
>
>
>
> Thanks.
>
> =====================
> 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
>



      ____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

=====================
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: Help in calculating spell lengths

Spousta Jan
In reply to this post by Jerabek Jindrich
Hi all,

Just a small correction to Jindra's solution: drop the END LOOP. line at the bottom of the syntax or you'll get errors.

For those who ask for an alternative DO REPEAT solution I have this one:

data list free /m1 to m9.
begin data.
0       1       1       1       1       0       0       1       0
0       0       1       1       0       0       1       0       1
1       1       1       1       1       1       1       1       1
0       0       1       0       1       0       1       0       1
end data.
form all (f1).

compute initial = 0.
compute #status = 1.
do repe x = m1 to m9.
- if (#status) initial = initial + x.
- if (x = 0 & initial > 0) #status = 0.
end repe.
exe.

Unfortunately a command END REPEAT IF ... is impossible; it would allow a very elegant solution.

Best regards

Jan

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jerabek Jindrich
Sent: Thursday, April 17, 2008 9:34 AM
To: [hidden email]
Subject: Re:Help in calculating spell lengths

Hello David,

following syntax should do the job.

COMPUTE #found = 0.
VECTOR m = m1 to m9.
COMPUTE initial=0.
LOOP #i=1 to 9.
DO IF m(#i)=1.
COMPUTE #found=1.
COMPUTE initial = initial +1.
END IF.
END LOOP if #found and m(#i)=0.
END LOOP.
EXEC.

regards
Jindra

> ------------ Původní zpráva ------------
> Od: David Rosenbluth <[hidden email]>
> Předmět: Help in calculating spell lengths
> Datum: 17.4.2008 05:44:51
> ----------------------------------------
> I have an SPSS problem that I'm having difficulty solving.
>
>
>
> I am trying to calculate the length of the initial spell that people
> are in a social service program. I have an array of variables month1
> to month9. For each record, every month variable (m1 to m9) has a 0
> (indicating no program
> participation) or a 1 (indicating participation).
>
>
>
> e.g.
>
>      m1       m2       m3      m4       m5       m6       m7       m8       m9
>
>      .00      1.00     1.00     1.00     1.00      .00       .00      1.00
> .00
>
>      .00       .00      1.00     1.00      .00       .00      1.00      .00
> 1.00
>
>     1.00     1.00     1.00     1.00     1.00     1.00     1.00     1.00
> 1.00
>
>      .00       .00      1.00      .00      1.00      .00      1.00      .00
> 1.00
>
>
>
> I would like to calculate the length of a person's first spell - that
> involves going through each array until you hit the first '1' and then
> calculating all the consecutive months where the value is '1'.
>
>
>
> So in the data above, the first person would have an initial spell of
> 4 months; the 2nd person would have a spell of 2 months; the third
> person 9 months; and the 4th person 1 month.
>
>
>
> I'm having difficulty figuring out how to do this. I can create a loop
> if everyone starts in month1, but I can't figure out the syntax when
> people have different starting months. Can anyone provide suggestions?
>
>
>
> Thanks.
>
> =====================
> 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



_____

Tato zpráva a všechny připojené soubory jsou důvěrné a určené výlučně adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno jakékoliv zveřejňování, zprostředkování nebo jiné použití těchto informací. Jestliže jste tento mail dostali neoprávněně, prosím, uvědomte odesilatele a smažte zprávu i přiložené soubory. Odesilatel nezodpovídá za jakékoliv chyby nebo opomenutí způsobené tímto přenosem.

This message and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact the sender and delete the message as well as all attached documents. The sender does not accept liability for any errors or omissions as a result of the transmission.

-.- --

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