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
Related Posts with Dropping individuals when missing observations and change in variable
Data Arrangement for Categorical RegressionHello, I would like to analyse whether a person's political opinion is changed after the loss of a p…
Food price seasonality and volatility analysisI would want to do an analysis on food price seasonality and volatility using trigonometric and sawt…
Histograms - X AxisHi everyone! I would like to know, whether there is a way to remove the minor ticks and numbers tha…
looping over variables in a local macroDear members of the Statalist community, I am a grad student with experience in R, currently workin…
Controls, fixed effect models, and an issueDear Statalist, I am estimating the effect of parental separation on the amount of time a child spe…
Subscribe to:
Post Comments (Atom)
0 Response to Dropping individuals when missing observations and change in variable
Post a Comment