Hello,
I am facing problems with a quite simple operation in Stata. For each individual, I have two columns : one for the mothers, and one for the fathers. Each column contains the unique identifier of their first child. Of course, if my individual is a mother, I have a point in the father column, and if the individual is a father, I have a point in the mother column. So it looks like this
ID SEX id_child_m id_child_f
Paul M . John
Mary F John .
What I would like to is to create a column id_child which takes the value of the column id_child_m or id_child_f, depending on the sex of my individual, and so it would like this:
ID SEX id_child
Paul M John
Mary F John
However, it doesn't work. My id_child_m and id_child_f are not "John" but some 8-digits-identifiers, and when I use the following piece of code, the identifier changes a bit. For example, 11111112 becomes 11111113. I have asbolutely no idea why .... I made sure the formats of the columns is the same, but it seems not to be the cause of the mistake.
Could anyone please help me? (making the sum of the two columns or using the command "rowtotal" leads to the same result)
Thanks a lot in advance,
Quentin
Code: forvalues v = 1 (1) 24 {
format id_child_m`v' id_child_f`v' %9.0g
recast float id_child_m`v' id_child_f`v', force
gen id_children`v' = id_child_m`v'
replace id_children`v' = id_child_f`v' if missing(id_children`v')
}
I am facing problems with a quite simple operation in Stata. For each individual, I have two columns : one for the mothers, and one for the fathers. Each column contains the unique identifier of their first child. Of course, if my individual is a mother, I have a point in the father column, and if the individual is a father, I have a point in the mother column. So it looks like this
ID SEX id_child_m id_child_f
Paul M . John
Mary F John .
What I would like to is to create a column id_child which takes the value of the column id_child_m or id_child_f, depending on the sex of my individual, and so it would like this:
ID SEX id_child
Paul M John
Mary F John
However, it doesn't work. My id_child_m and id_child_f are not "John" but some 8-digits-identifiers, and when I use the following piece of code, the identifier changes a bit. For example, 11111112 becomes 11111113. I have asbolutely no idea why .... I made sure the formats of the columns is the same, but it seems not to be the cause of the mistake.
Could anyone please help me? (making the sum of the two columns or using the command "rowtotal" leads to the same result)
Thanks a lot in advance,
Quentin
Code: forvalues v = 1 (1) 24 {
format id_child_m`v' id_child_f`v' %9.0g
recast float id_child_m`v' id_child_f`v', force
gen id_children`v' = id_child_m`v'
replace id_children`v' = id_child_f`v' if missing(id_children`v')
}

Comment