I need help creating variable W1 (shown below). The idea is, for each coder during a spell, he/she may get an I3=1. When this happens, for each coder during each spell, I want the W1 to equal 1 and then remain as 1 until the end of the spell.
For example, take coder 101417. He/she has two spells (1 and 2). During spell 1, the coder doesn't witness an I3=1 at all, so W1 stays as 0 throughout that spell. During spell 2 for that same coder, he/she does witness an I3=1 in the second instance. Therefore for that coder during that spell, the W1 variable needs to be 0 in the first instance (as of that time, the coder hadn't witnessed a I3=1 yet during that spell) and then W1 needs to be 1 in the second instance (because it is then that the coder did witness a I3=1 during that spell) and then W1 needs to be 1 in the third instance (because at that time, during that spell, the coder had already witnessed a I3=1, which happened in the second instance).
Any help would be greatly appreciated.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear coder_id dateno I3 spell W1 101287 58 0 1 0 101287 59 1 2 1 101287 60 0 2 1 101287 77 0 3 0 101287 80 0 4 0 101417 1 0 1 0 101417 109 0 1 0 101417 112 0 1 0 101417 113 0 1 0 101417 115 0 1 0 101417 116 0 1 0 101417 117 0 1 0 101417 135 0 1 0 101417 200 0 2 0 101417 209 1 2 1 101417 344 0 2 1 101446 22 0 1 0 101447 21 0 1 0 101447 37 0 1 0 101447 90 0 2 0 101447 91 1 2 1 101447 314 0 2 1 end
0 Response to Help creating a variable concerning spells
Post a Comment