Sorry in advance for the long and convoluted question.
I have a series of variables that represent various family members (the 'b' variables in the data example below) and their occupation (the 'e' variables). So in the data example, fl1b represents Family Member 1's specific relation to the subject (coded 1-9 for mother, sibling, cousin, etc.) and fl1e represents Family Member 1's occupation (coded 1-5 for various occupational categories).
What I have been trying to do is generate new variables that pulls out only parent occupation.
So, the new variable would be something like parent_occupation and its values would be the 1-5 values from the 'e' variables. My first attempt was something like this (in the 'b' variables, parents are represented with values 1 - 4):
I was basically trying to tell Stata to pull out the 'e' variable value only if its corresponding 'b' variable value is between 1 and 4 (i.e., if it's a parent), but I think I may need a loop within that loop in order to do that?
One additional challenge is that there are subjects with multiple parents represented in the data (the first subject in the data below, for example, has 3 different parents represented because step-parents are included), and therefore I'd need some way to generate multiple parent_occupation variables, which I have not figured out as of yet.
Here is a bit of my data. If anyone has any advice I would be very greatful!
I have a series of variables that represent various family members (the 'b' variables in the data example below) and their occupation (the 'e' variables). So in the data example, fl1b represents Family Member 1's specific relation to the subject (coded 1-9 for mother, sibling, cousin, etc.) and fl1e represents Family Member 1's occupation (coded 1-5 for various occupational categories).
What I have been trying to do is generate new variables that pulls out only parent occupation.
So, the new variable would be something like parent_occupation and its values would be the 1-5 values from the 'e' variables. My first attempt was something like this (in the 'b' variables, parents are represented with values 1 - 4):
Code:
gen parent_occupation = . foreach v of var fl*b { replace parent_occupation = fl*e if inrange(`v', 1, 4) }
One additional challenge is that there are subjects with multiple parents represented in the data (the first subject in the data below, for example, has 3 different parents represented because step-parents are included), and therefore I'd need some way to generate multiple parent_occupation variables, which I have not figured out as of yet.
Here is a bit of my data. If anyone has any advice I would be very greatful!
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long id byte(fl1b fl1e fl2b fl2e fl3b fl3e) 777851 1 3 1 1 1 4 777834 2 2 1 5 5 5 777852 3 1 1 1 7 4 777835 2 5 7 4 8 1 777853 2 4 8 1 9 4 777836 1 3 9 5 1 4 777854 2 3 1 2 1 4 777837 3 5 7 5 8 5 777855 4 4 8 2 3 2 777838 7 2 3 5 4 1 777856 6 1 4 4 3 4 777839 7 2 3 5 4 1 777857 8 3 2 5 2 2 777840 9 3 2 5 3 2 777858 1 3 6 3 2 2 777841 8 2 7 2 1 5 777859 8 5 8 2 7 1 777842 3 2 9 5 8 1 777860 4 4 7 3 9 2 777843 3 5 2 3 1 3 777861 2 4 8 1 3 3 777844 2 5 3 4 2 3 777862 1 1 1 5 3 3 777845 3 2 3 2 4 2 777863 7 5 2 1 3 1 end
Comment