Hi,
please consider the following sample data:
"id" corresponds to births by "mother". it is a combination of "mother" and "birthcol". Now, mother 11 has given birth three times and has birthyear recorded thrice. Mother 22 has given birth once. Mother 33 hasn't given birth ever.
Since mother 22 has given birth only once, I want to drop the irrelevant repetitions. But at the same time, I want to keep at least one observation for each mother because there are other outcome variables (unrelated to birth) that I want to look at. So I cant do a simple
I could try
which would keep all the relevant obs for mother 11 and keep one observation for mother 33 and 22. But it also keeps an additional observation for mother 22 where birthyear is missing.
Is there any way to delete observations to achieve a data that look like below?
Thanks
please consider the following sample data:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(id mother birthyear birthcol) 111 11 2003 1 112 11 2002 2 113 11 2001 3 221 22 2000 1 222 22 . 2 223 22 . 3 331 33 . 1 332 33 . 2 333 33 . 3 end
Since mother 22 has given birth only once, I want to drop the irrelevant repetitions. But at the same time, I want to keep at least one observation for each mother because there are other outcome variables (unrelated to birth) that I want to look at. So I cant do a simple
Code:
drop if missing(birthyear)
Code:
duplicates drop mother birthyear,force
Is there any way to delete observations to achieve a data that look like below?
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(id mother birthyear birthcol) 111 11 2003 1 112 11 2002 2 113 11 2001 3 221 22 2000 1 331 33 . 1 end

Comment