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
Hello! How to create flowchart diagramm?My STATA version 13.0 …
Dialog box script: if condition on chosen combo box value?This is my first time creating a dialog box, and I am struggling to create conditions based on chose…
Help Generating Dummy Variable WestCoastDear all, I am using Stata 16, on mac. Here is a snapshot of my dataset which consists of populatio…
Repeated Measures mlogitHi there, I have been reading the forum on repeated measures/panel style data and the use of mlogit.…
Help Sorting Data by State and yearDear all, here is a screenshot of my data. My dataset includes GDP for all 50 states over a period …
Subscribe to:
Post Comments (Atom)
0 Response to Dropping individuals when missing observations and change in variable
Post a Comment