I have data set up like the below (but with many more variables) where the middle part of the variable name changes when a child ages into a new age group.
So "C23" would be the naming root when children are ages 4-12, and once they turn 13 the variable name changed (for whatever reason) and the root becomes "D22". The letter that follows is what connects them--so in constructing a cohesive panel, you'd want to combine "C23A" and "D22A" into one variable.
I can obviously just brute force this for each of my dozen variables, but I was wondering if anyone could come up with a clever loop that would accomplish this more efficiently?
So "C23" would be the naming root when children are ages 4-12, and once they turn 13 the variable name changed (for whatever reason) and the root becomes "D22". The letter that follows is what connects them--so in constructing a cohesive panel, you'd want to combine "C23A" and "D22A" into one variable.
I can obviously just brute force this for each of my dozen variables, but I was wondering if anyone could come up with a clever loop that would accomplish this more efficiently?
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(year child_id HOME_C23A_ HOME_D22A_ HOME_C23B_ HOME_D22B_) 2000 100 1 . 1 . 2002 100 0 . 1 . 2004 100 . 1 . 0 2006 100 . 1 . 0 2008 100 . 1 . 1 2000 200 1 . 1 . 2002 200 . 1 . 1 2004 200 . 0 . 1 2006 200 . 0 . 0 2008 200 . 1 . 0 end

Comment