Dear Statalisters,
I am dealing with the following data, where pidnew denotes the identification variable of the respondent, wave the wave of the survey, mach the change in marital status and marital the marital status.
I would like to create a new ID in a new column (pid2) which modifies every time there is a change in the marital status, such that data become this way:
I tried several times by constructing some indicators (
xtset pidnew wave
by pidnew: egen transitions=max(mach==25|mach==54), but I am getting stuck.
If you could help me with this issue, this would be very helpful.
Thank you very much,
Lydia
I am dealing with the following data, where pidnew denotes the identification variable of the respondent, wave the wave of the survey, mach the change in marital status and marital the marital status.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long pidnew float(wave mach) byte marital 100022 1 . 1 100044 1 . 1 100044 2 11 1 100045 1 . 1 100045 2 11 1 100045 3 11 1 100078 1 . 4 100078 2 44 4 100078 3 44 4 100078 8 44 4 100078 9 44 4 100078 10 44 4 100078 11 44 4 100168 1 . 2 100168 2 22 2 100168 3 22 2 100168 4 22 2 100168 7 25 5 100168 8 55 5 100168 9 55 5 100168 10 55 5 100168 12 55 5 100168 14 54 4 end label values pidnew pid label values mach mach label def mach 11 "single->single", modify label def mach 13 "single->cohabiter", modify label def mach 22 "married->married", modify label def mach 25 "married ->divorced", modify label def mach 32 "cohabitor->married", modify label def mach 33 "cohabitor->cohabiter", modify label def mach 44 "widowed->widowed", modify label def mach 53 "divorced->cohabiter", modify label def mach 54 "divorced->widowed", modify label def mach 55 "divorced->divorced", modify label values marital marital label def marital 1 "Never married", modify label def marital 2 "Married", modify label def marital 3 "Living as a couple", modify label def marital 4 "Widowed", modify label def marital 5 "Split", modify
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long pidnew float(wave mach) byte marital pid2 100022 1 . 11 100044 1 . 12 100044 2 11 12 100045 1 . 13 100045 2 11 13 100045 3 11 13 100078 1 . 43 100078 2 44 43 100078 3 44 43 100078 8 44 43 100078 9 44 43 100078 10 44 43 100078 11 44 43 100168 1 . 24 100168 2 22 24 100168 3 22 24 100168 4 22 24 100168 7 25 54 100168 8 55 55 100168 9 55 55 100168 10 55 55 100168 12 55 55 100168 14 54 45 end label values pidnew pid label values mach mach label def mach 11 "single->single", modify label def mach 13 "single->cohabiter", modify label def mach 22 "married->married", modify label def mach 25 "married ->divorced", modify label def mach 32 "cohabitor->married", modify label def mach 33 "cohabitor->cohabiter", modify label def mach 44 "widowed->widowed", modify label def mach 53 "divorced->cohabiter", modify label def mach 54 "divorced->widowed", modify label def mach 55 "divorced->divorced", modify label values marital marital label def marital 1 "Never married", modify label def marital 2 "Married", modify label def marital 3 "Living as a couple", modify label def marital 4 "Widowed", modify label def marital 5 "Split", modify
xtset pidnew wave
by pidnew: egen transitions=max(mach==25|mach==54), but I am getting stuck.
If you could help me with this issue, this would be very helpful.
Thank you very much,
Lydia
Comment