Thursday 15 August 2013

count - spss counting first consecutive zeros across variables -


I have to count on the day when no subject is treated ("0" in my file. It is marked with "1." The subject can receive many courses of treatment and I want to count the days between the first and the second. I do not want to be interested in the time between second and third treatment. My SPSS file looks like this:

ID day 1 day2 day3 day4 day28
a --- 1 ----- 0 --- - 0 ---- 1 ------ 0
b --- 1 ---- 0 ----- 1 ---- 0 ----- - 1
c --- etc.

I am only interested in the first series of zero. I hope to get the output:

id first_smile
a 2 b 1
C ...

Anyone in Rei can help, here. Obviously, calculation of all zeroes is not going to work just because there are several sets of zero in one line.

Cheers, Delan

This is a very common approach that will help you get treatment for various treatments. Allow time to calculate the middle time. First of all I create vector which stores all the treatments locations, using an Loc1 to Loc5 ( day1 to day5 using an example in the form of).

data list free / day 1 day 2 days 3 days 4 days 5 BEGIN data 1 0 0 1 0 1 0 1 0 1 Egg Data Vector Day = Day 1 Day 5. Vector Public (5, F 2.0) COMPUTE #id = 1. LOOP #i = 1 TO 5. If Days (# E) = 1. COMPUTE Loc (#id) = #i. COMPUTE #id = #id + 1. End if the end result

Now if you run this change, then Folk vector will look for this example data.

  Loc1 Loc2 Loc3 Loc4 Loc5 1 4. . 1 3 5  

Now the first series is as simple to calculate the difference:

  COMPUTE first_series_zero = Loc2 - Loc1 - 1.  

If any other (or earlier) treatment is never done then it becomes unavailable, and is not dependent on day1 always on the first day of treatment Now the difference between all treatments is quite simple to calculate, and this is a DO REPEAT approach.

  Vector Difce (4, F2.0). Repeat F = Lok 1 to Lok 4 / B = Lok 2 to Lok 5 / D = DTS 1 to DTS 4. Compute D = B - F - 1. End repeat  

and therefore will be zero between DifS1 1 and second treatment, DifS2 second And the third treatment will be zero between etc. (These repeats and the first loop can be made more efficient with a loop which only goes to valid / possible values.)


No comments:

Post a Comment