Hello everyone. I'm trying to create an event variable for my analysis. My objective is to gen a variable that is 1 when a person has a posterior admission, and 0 if has not.
i tried
bysort hash_key: gen event=1
bysort hash_key: replace event=0 if event[_n+1]!=.
but is not working. I need something like this.
id event
1 0
2 1
2 1
2 0
3 1
Thank you very much for your time.