Hi all,
Quite a silly question, but somehow I can't get what I want from Stata.
My data:
I would like to create a dummy assuming the value of 1 if within token1, there is variation in canton. This new dummy, let's call it
should therefore be equal to 1 for tokens 1 and 10, but equal to 0 for token 8.
The code I've written is
(My data are not xtset so I cannot use the lag operator)
But this code just gives me 1s everywhere, even when there is in fact no variation of canton within token.
Could anyone highlight the mistake I'm making?
Quite a silly question, but somehow I can't get what I want from Stata.
My data:
Code:
input float(token1 time) byte canton 1 2 4 1 3 21 1 11 23 8 12 6 8 14 6 8 15 6 8 17 6 8 18 6 8 23 6 8 24 6 10 11 6 10 13 6 10 14 6 10 17 6 10 25 5
Code:
var_canton_within_tok
The code I've written is
Code:
bys token1: g var_canton_within_tok=cond(canton[_n]!=canton[_n-1],1,0)
But this code just gives me 1s everywhere, even when there is in fact no variation of canton within token.
Could anyone highlight the mistake I'm making?

Comment