While the above code (which aims to measure the length of a relationship) achieves what I want most of the time, it does not if:
1) a person changes partner, the spell sequence and spell length variables continue to increase, when they should restart.
2) a person response is missing, the spell restarts, but in this instance I want to direct Stata to use the partner's response (and if the same partner (p_id), should continue to increase).
Obviously reflecting the limitation of my knowledge, not the code. Code below. Help is appreciated.
The link in #15 (above) provides sample data. (Note: marstat==1 - married; marstat==2 - de facto).
1) a person changes partner, the spell sequence and spell length variables continue to increase, when they should restart.
2) a person response is missing, the spell restarts, but in this instance I want to direct Stata to use the partner's response (and if the same partner (p_id), should continue to increase).
Obviously reflecting the limitation of my knowledge, not the code. Code below. Help is appreciated.
Code:
bys id (wave): gen byte begin = inlist(marstat, 1, 2) & marstat!= marstat[_n-1] bys id (wave): replace begin = inlist(p_marstat, 1, 2) if marstat == . bys id (wave): gen byte spell = sum(begin) bys id spell (wave): gen byte end = _n == _N & inlist(marstat, 1, 2) bys id (wave): replace end = inlist(p_marstat, 1, 2) if marstat== . bys id spell (wave): gen seq = cond(spell, _n, .) bys id (wave): replace seq = inlist(p_marstat, 1, 2) if marstat== . bys id spell (wave): gen length = _N bys id (wave): replace length = inlist(p_marstat, 1, 2) if marstat== .
Comment