I would like to be able to search through the waves of data (which I've already merged into a single file) to identify changes in an individual's self-rated life satisfaction over time based on the effect of certain life events or experiences throughout the panel data. While many of these related questions are asked annually, if the respondent experiences a given life event, they are asked for further information, such as the quarter in which the life event occurred so it would be good to factor this in if possible. Finally, I have data on both the respondent and their partner and this is represented in the naming of variables, such as lemarr (for the respondent) and p_lemarr (for the partner).
I have the following code which someone else helped me with for a different piece of work, but not sure if it is good code or if it is suitable for the task, so I appreciate any suggestions or guidance with this:
Code:
sort xwaveid wave cap drop droppout gen droppout = mi(mrcurr) cap drop change_to_* gen change_to_married = 0 if droppout == 0 bys id (wave): replace change_to_married = 1 if marstat == 1 & marstat[_n-1] != 1 & marstat[_n-1] != . & marstat != . // marstat - marital status gen change_to_sep = 0 if droppout == 0 bys id (wave): replace change_to_sep = 1 if marstat == 3 & marstat[_n-1] == 1 & marstat[_n-1] != . & marstat != . bys id (wave): egen change_to_married_N = sum(change_to_married) if droppout == 0 bys id (wave): egen change_to_sep_N = sum(change_to_sep) if droppout == 0 cap drop nwave gen nwave = -wave gen timeline_married = . replace timeline_married = 0 if change_to_married == 1 bys id (wave): replace timeline_married = timeline_married[_n-1] + 1 if timeline_married == . bys id (nwave): replace timeline_married = timeline_married[_n-1] - 1 if timeline_married == . order timeline_married, after(change_to_married) gen timeline_sep = . replace timeline_sep = 0 if change_to_sep == 1 bys id (wave): replace timeline_sep = timeline_sep_div[_n-1] + 1 if timeline_sep == . bys id (nwave): replace timeline_sep = timeline_sep[_n-1] - 1 if timeline_sep == . order timeline_sep, after(change_to_sep) gen time_single_married = timeline_single_married + 100 gen time_defacto_married = timeline_defacto_married + 100
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(lemar lebth lesep lefnw) 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 end label values lemar RLEME label values lesep RLEME label values lebth RLEME label values lefnw RLEME label def RLEME 1 "[1] No", modify label def RLEME 2 "[2] Yes", modify
I appreciate any support/guidance. Kind regards, Chris
0 Response to Identify life events in panel data
Post a Comment