3

I have a variable for each month of the year which value is either 1 (designates something has been checked in that month) or SYSMIS.

How do I recode this into a new variable e.g. VAR1 where I get something like

 0 = no checks in a year
 1 = 1 check in a year
 2 = 2 checks in a year every six months
 3 = 2+ checks in a year (where 2 of them were six months apart)

As an alternative I've been using a system where I calculate the total checks in that year and then see if there was 0, 1, or 2+ checks but this is not accurate because I can't see if two checks were six months apart or in two consecutive months

NUMERIC var1_Total (F3.0).
COMPUTE var1_Total=varA.1+varA.2+varA.3+varA.4+varA.5+varA.6+varA.7+varA.8+varA.9+varA.10+varA.11+varA.12.
EXECUTE.

NUMERIC var2 (F5.0).
VALUE LABELS var2 0 '0' 1 '1' 2 '>=2'.
IF (var1_Total=0)   var2=0.
IF (var1_Total=1)   var2=1.
IF (var1_Total>=2) var2=2.
EXECUTE.
Tony
  • 69
  • 8
  • You need to define your criteria of the number of months between two checks better? What if 3, 4 checks? Then is it that you want the maximum gap between any two check, I suspect is what you require? – Jignesh Sutar Dec 08 '15 at 13:12

2 Answers2

1

Assuming varA.1 to varA.12 are in consecutive order in the data file and assuming the presence of something occuring that month is represented by a numeric code one:

COMPUTE var1_Total=sum(varA.1 to varA.12).
RECODE var1_Total (3 THRU HI=3).
Jignesh Sutar
  • 2,909
  • 10
  • 13
  • Sorry I wasn't very clear with my question. What you describe here is I think what I've been doing so far but this doesn't take into consideration the 'checks must be six-months apart' clause. Another person answered my question through, thanks for your help. – Tony Dec 09 '15 at 10:35
1

So what you need is an indicator variable which tells you if there are at least two checks exactly six months apart, right?

This will do it:

* Check if one of the pairs (varA.1, varA.7; varA.2, varA.8; ...) both have the value 1.
DO REPEAT var_p1=varA.1 TO varA.6
          /var_p2=varA.7 TO varA.12.
    IF (var_p1=1 AND var_p2=1) six_month = 1.
END REPEAT.

Then you can adjust the IF commands:

* Note that cases with var1_total>=2 but without checks six month apart will get the value 1.
IF (var1_Total=0)               var2=0.
IF (var1_Total>=1)              var2=1.
IF (var1_Total=2 AND six_month) var2=2.
IF (var1_Total>2 AND six_month) var2=3.
EXECUTE.
mirirai
  • 1,365
  • 9
  • 25
  • This is brilliant, exactly what I needed.So if I wanted to modify this for checks every 3 months: `DO REPEAT var_p1=varA.1 TO varA.3 /var_p2=varA.4 TO varA.6 /var_p3=varA.7 TO varA.12. IF (var_p1=1 AND var_p2=1 AND var_p3=1) three_month = 1. END REPEAT.` Right? What if I wanted to add a thirteenth month just to be sure I capture the check I might miss during data collection month, how would I account for the extra month in syntax? – Tony Dec 09 '15 at 10:36
  • **Checks every three months:** If I understand you right this should be true if someone has at least 4 checks, three months apart. I think you got the right idea, but you made a mistake. Your code should rather be `DO REPEAT var_p1=varA.1 TO var.A3 /var_p2=varA.4 TO varA.6 /var_p3=varA.7 TO varA.9 /var_p4=varA.10 TO varA.12. IF (var_p1=1 AND var_p2=1 AND var_p3=1 AND var_p4=1) three_month=1. END REPEAT.` – mirirai Dec 09 '15 at 14:15
  • **13. month:** Should varA.1=1, varA.6=1, varA.13=0 result in six_month=1 or 0? And what about varA.1=0, varA.6=1, varA.13=1? – mirirai Dec 09 '15 at 14:19
  • Thanks for the correction. Actually, never mind for the 13 month, I didn't think it through, I guess it doesn't make sense nor would add any benefit. – Tony Dec 10 '15 at 09:14