Dropping observations in Stata based on age and panel round -



Dropping observations in Stata based on age and panel round -

i have panel dataset , want drop respondents aged 40 years , on in first round of survey.

i tried doingdrop if age>40 , drop if age>40 & t==1 t identifier of survey wave person in. when sec left people on age of 40.

here illustration of how info looks like:

pid age wave year of survey 1 20 1 2005 1 21 2 2006 1 22 3 2007 1 23 4 2008 2 37 1 2006 2 38 2 2007 2 39 3 2008 2 40 4 2009 3 40 1 2008 3 41 2 2009 3 42 3 2010 3 43 4 2011

my aim not lose 3rd respondent given he/she within target age grouping when first surveyed not in next survey years (rather beingness left his/her first wave of info , dropping other 3 beingness done if drop if age<=40).

is there way left people age of 40 while keeping 40 in first wave if turn 41, 42 etc in subsequent waves? want constrain panel 40 years of age grouping while keeping 40 in wave might on 40 in subsequent waves (i have 4 waves).

stata gives you're asking for. drop if age > 40 lose any observation age > 40. drop if age > 40 & wave == 1 add together additional condition: drop if simultaneously has wave == 1. think that's clear.

i find explanation contradictory. don't want lose observation respondent 3 because in first wave she's not on 40, although in next waves. want left people age of 40.

the next drops observations person in first wave on 40. allow know if not seek.

clear set more off input /// pid age wave survyear 1 20 1 2005 1 21 2 2006 1 22 3 2007 1 23 4 2008 2 37 1 2006 2 38 2 2007 2 39 3 2008 2 40 4 2009 3 40 1 2008 3 41 2 2009 3 42 3 2010 3 43 4 2011 4 42 1 2009 4 43 2 2010 4 44 3 2011 4 45 4 2012 end list, sepby(pid) *----- bysort pid (age): drop if age[1] > 40 list, sepby(pid)

you want read speaking stata: how move step by: step, nick cox. see help subscripting.

edit

with no knowledge of database structure, sorting wave should more general approach. involves bysort pid (wave): ... in previous code. imagine case person has same age 2 consecutive waves. if so, sorting age not give consistent results. wave variable 1 uniquely identifies cases, each person. read help sort , help isid carefully, including manual entries.

panel stata

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -