# Comparing values of subsequent cases (syntax)

#### astr

##### New Member
Hi! I'm stuck with a seemingly simple problem (comparing values One variable - Multiple cases). Please help!

This is what I want to do:
I have records for a variable for different participants for several subsequent months, that is there is more than one case for each participant (number of cases per ID varies). So it looks something like this:
ID VAR1
1 3
1 3
1 4
2 6
2 7
2 7
3 2
3 5

I need to create a new variable which would show whether the value of VAR1 has changed compared to the previous month (0 - no change, 1 - change). So it should look like this in the end:
ID VAR1 NEW
1 3 .
1 3 0
1 4 1
2 6 .
2 7 1
2 7 0
3 2 .
3 5 1

Could please anyone help me with the syntax for this transformation?

PS Probably worth mentioning that my database is pretty large, so any manual transformation is out of question.

do if id = lag(id).
exe.