generating new var and assigning values

Hi there!

I would like to generate a new variable and assign it some values.
I have a huge data set and I would like to see how and if the education level of the headfamily affects the children participation to school.
I have two separate variables, one is Relation to head and the other one is education obtained. I would like to combine both of them together, so that I can have a variable that refers only to the level of education obtained of the head family.

I have firstly tried with

gen headeduc = Relationtohead == 1

And then

replace headeduc = 1 if educ_obtained ==1
replace headeduc = 1 if educ_obtained == 2
and so on but it does not work. It ends up with doing this for every person of the sample while I want this to happen only for the head family.

Is there any option to do it?

Thanks a lot!


Im a bit confused about what your trying to do, but I think an '&' might solve it.

replace headeduc = 1 if educ_obtained ==1 & headeduc==1
Thanks but unfortunately it does not work!
Will try to explain you what I intend to do: I want to create a variable which gives me information about the education of the head family.
I have two variables: one is level_of_education obtained by anyone who is in the sample and the other one is Relationtohead which gives me the titile of the persons in the family (like head, spouse of the head, married child, unmarried chil and so on). Since I want to see the impact of the head of the family on the education of a child, I want to create a new variable which gives me the educational level only of the head of the family.
I tried what you told me but it does not work as it keeps on giving me the educational level of everyone in the family.

But actually I have just seen it works! I have just run correlation and I have seen that if I write : pwcorr attending_school headeduc if Relationtohead ==1 it works! I thought I did have to have a single variable for the correlation, without giving further specification such as if. But apparently works!
Ah okay! Yes thankfully as you've found out regression and most commands can be combined with an if statement at the end which is very handy :)