I have data where children within a family (i.e., siblings) can be connected via their shared mother's ID. So in the data below, children 201 and 202 are siblings and share a mother. Same with 301 and 302.
I then have a series of variables about one's own experiences (cjc and alc being two example vars below). What I'm hoping to do is then create a variable that indicates if one's *sibling* has experienced something. So if child 202 experienced cjc_SELF in 2014, I'd then want to create a var called cjc_SIB that =1 for child 201 in 2014. Does that make sense? My initial attempts with -bysort (max)- did not work out the way I was hoping.
I then have a series of variables about one's own experiences (cjc and alc being two example vars below). What I'm hoping to do is then create a variable that indicates if one's *sibling* has experienced something. So if child 202 experienced cjc_SELF in 2014, I'd then want to create a var called cjc_SIB that =1 for child 201 in 2014. Does that make sense? My initial attempts with -bysort (max)- did not work out the way I was hoping.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long child_id int(mother_id year) float(cjc_SELF alc_SELF) 201 2 2010 0 . 201 2 2012 0 . 201 2 2014 0 . 201 2 2016 0 . 201 2 2018 0 . 201 2 2020 0 . 202 2 2010 0 . 202 2 2012 0 0 202 2 2014 1 0 202 2 2016 0 0 202 2 2018 0 0 202 2 2020 0 0 301 3 2010 0 . 301 3 2012 0 1 301 3 2014 0 0 301 3 2016 0 0 301 3 2018 1 0 301 3 2020 0 0 302 3 2010 0 . 302 3 2012 0 0 302 3 2014 0 1 302 3 2016 0 0 302 3 2018 1 1 302 3 2020 0 . 303 3 2010 0 0 303 3 2012 0 1 303 3 2014 0 0 303 3 2016 0 0 303 3 2018 0 . end

Comment