Hi,
I am running panel data analysis in Stata and work with Survey data from Germany. The period covered is 1984-2015. I have generated a variable that indicated personal identification number and missing observation of the ‘surveyed year’ variable.
xtset pid syear
sort pid syear
egen max_gap=max(syear - syear[_n-1]), by(pid)
I also have the marital status variable that ranger between 1-5. (1= married, 2=single, 4= divorced, 5= separated).
I have already dropped the married people with missing observation in two or more years:
drop if max_gap>2 & marstatus==1
However I want to drop all missing observation in 2 or more years but for people who have changed their marital status such as - if a person doesn’t report any marital status in two consequences years and on the third year the status has changed - he is dropped form the sample.
My approach was to create variable for those who have change in marital status over time and then drop it when max_gap is 2 or more years:
gen change = ((marstatus==1 & syear[_n]) & (marstatus !=1 & syear[_n+1]))
drop if max_gap>2 & change
However 0 observations are dropped which cannot be the case.
I would like to know what is wrong with my approach, maybe I need to use loops ?
Regards,
Gabriela
I am running panel data analysis in Stata and work with Survey data from Germany. The period covered is 1984-2015. I have generated a variable that indicated personal identification number and missing observation of the ‘surveyed year’ variable.
xtset pid syear
sort pid syear
egen max_gap=max(syear - syear[_n-1]), by(pid)
I also have the marital status variable that ranger between 1-5. (1= married, 2=single, 4= divorced, 5= separated).
I have already dropped the married people with missing observation in two or more years:
drop if max_gap>2 & marstatus==1
However I want to drop all missing observation in 2 or more years but for people who have changed their marital status such as - if a person doesn’t report any marital status in two consequences years and on the third year the status has changed - he is dropped form the sample.
My approach was to create variable for those who have change in marital status over time and then drop it when max_gap is 2 or more years:
gen change = ((marstatus==1 & syear[_n]) & (marstatus !=1 & syear[_n+1]))
drop if max_gap>2 & change
However 0 observations are dropped which cannot be the case.
I would like to know what is wrong with my approach, maybe I need to use loops ?
Regards,
Gabriela
Comment