Quote through variables in spss

Im looking for a way to cycle through variables (for example, from a week from a week to a week52) and count how many times the value changes over them. For example, a week from week to week18 can be encoded as 1 week19 - week40 can be encoded as 4 and week 41 to 52 can be encoded as 3

This will be 2 transits in the data.

How can I write code that can find me this information? I am new to this and it will be very helpful for me to help me in the right direction.

+4
source share
1 answer

You can use the DO REPEAT command to loop through lists of variables. The following is an example of using this command to create a date before and after a date to compare and increment the counter variable when the two variables are different.

 data list fixed / observation (A1). begin data 1 2 3 4 5 end data. *making random data. vector week(52). do repeat week = week1 to week52. compute week = RND(RV.UNIFORM(0.5,4.4)). end repeat. execute. *initialize count to zero. compute count = 0. do repeat week_after = week2 to week52 / week_before = week1 to week51. if week_after <> week_before count = count + 1. end repeat. execute. 
+4
source

Source: https://habr.com/ru/post/1387168/


All Articles