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
multicollinearity test variables in a panel dataHi, how can I run a multicollinearity test in Stata 12 between variables in a panel data? Thanks! …
Nested forvalue loops - referring to previous macros in a relevant macroGood afternoon. Could anyone help me decipher what syntax error I am producing in the below command…
Solve Macroeconometrics Model and ForecastI am trying to solve a macroeconometrics model of my country using STATA. Model has 7 endogenous var…
Why the different bootstrap errors in panel data random effects?Hi, in help xt_vce_options I found the following recommendation: When working with panel-data mode…
T Tests and Wilcoxon Tests export to MS Word or MS ExcelHello Members I had been working on EViews for some time, I shifted to Stata now, since I am new, I…
Subscribe to:
Post Comments (Atom)
0 Response to Dropping individuals when missing observations and change in variable
Post a Comment