Hi all,

I am working with panel data and I need some helping filtering out the cases I can use. Every household (nohhold) is followed over multiple years, kid4 and kid12 tell me whether the household contains children below 4 and 12 respectively and positie tells me the position in the household (1=head of household). What I need is to only keep the head of households that have kids below 4 and 12, but I cannot figure out how to select these. I cannot use a code like "keep if kid4==1" since that means keeping the child and not the head of the household. I hope the question and the data are clear, please let me know if clarification is needed.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double(nohhold nomem) float year double positie float(kid4 kid12)
  4 1 2010 1 0 0
  4 2 2010 2 0 0
  4 1 2010 1 0 0
  4 2 2010 2 0 0
  4 2 2011 2 0 0
  4 1 2011 1 0 0
  4 1 2013 1 0 0
  4 2 2013 2 0 0
  4 1 2015 1 0 0
  4 2 2015 2 0 0
  4 1 2016 1 0 0
  4 2 2016 2 0 0
  4 2 2017 2 0 0
  4 1 2017 1 0 0
  6 2 2010 2 0 0
  6 2 2010 2 0 0
  6 1 2010 1 0 0
  6 1 2010 1 0 0
  6 1 2011 1 0 0
  6 2 2011 2 0 0
  6 2 2012 2 0 0
  6 1 2012 1 0 0
  6 2 2013 2 0 0
  6 1 2013 1 0 0
  6 2 2014 2 0 0
  6 1 2014 1 0 0
  6 1 2015 1 0 0
  6 2 2015 2 0 0
  6 1 2016 1 0 0
  6 2 2016 2 0 0
  6 2 2017 2 0 0
  6 1 2017 1 0 0
 21 2 2010 2 0 0
 21 1 2010 1 0 0
 21 1 2010 1 0 0
 21 2 2010 2 0 0
 21 2 2011 2 0 0
 21 1 2011 1 0 0
 21 1 2012 1 0 0
 21 2 2012 2 0 0
 21 1 2013 1 0 0
 21 2 2013 2 0 0
 21 2 2014 2 0 0
 21 1 2014 1 0 0
 21 2 2015 2 0 0
 21 1 2015 1 0 0
 21 1 2016 1 0 0
 21 2 2016 2 0 0
 21 1 2017 1 0 0
 21 2 2017 2 0 0
 38 1 2010 1 0 0
 38 2 2010 2 0 0
 38 1 2010 1 0 0
 38 2 2010 2 0 0
 38 1 2011 1 0 0
 38 2 2011 2 0 0
 38 1 2012 1 0 0
 38 2 2012 2 0 0
 38 1 2013 1 0 0
 38 2 2013 2 0 0
 38 1 2014 1 0 0
 38 2 2014 2 0 0
 38 2 2015 2 0 0
 38 1 2015 1 0 0
 38 2 2016 2 0 0
 38 1 2016 1 0 0
 38 2 2017 2 0 0
 38 1 2017 1 0 0
106 4 2010 5 0 1
106 2 2010 2 0 0
106 4 2010 5 0 1
106 1 2010 1 0 0
106 1 2010 1 0 0
106 3 2010 5 0 0
106 2 2010 2 0 0
106 3 2010 5 0 0
106 3 2011 5 0 0
106 1 2011 1 0 0
106 2 2011 2 0 0
106 4 2011 5 0 1
106 4 2012 5 0 1
106 2 2012 2 0 0
106 1 2012 1 0 0
106 3 2012 5 0 0
106 2 2013 2 0 0
106 3 2013 5 0 0
106 4 2013 5 0 0
106 1 2013 1 0 0
106 2 2014 2 0 0
106 4 2014 5 0 0
106 3 2014 5 0 0
106 1 2014 1 0 0
106 1 2015 1 0 0
106 3 2015 5 0 0
106 2 2015 2 0 0
106 4 2015 5 0 0
106 1 2016 1 0 0
106 3 2016 5 0 0
106 4 2016 5 0 0
106 2 2016 2 0 0
end
label values positie positie
label def positie 1 "head of the household", modify
label def positie 2 "spouse", modify
label def positie 5 "child living at home", modify