Hi all,
I am trying to drop duplicate observations under certain conditions.
My data looks something like the following:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str8 childid float round
"IN010001" 2
"IN010001" 3
"IN010001" 4
"IN010001" 4
"IN010001" 4
"IN010001" 5
"IN010001" 5
"IN010001" 5
"IN010002" 2
"IN010002" 3
"IN010002" 4
"IN010002" 4
"IN010002" 4
"IN010002" 5
"IN010002" 5
"IN010002" 5
"IN010003" 2
"IN010003" 3
"IN010003" 4
"IN010003" 4
"IN010003" 4
"IN010003" 5
"IN010003" 5
"IN010003" 5
"IN010004" 2
"IN010004" 3
"IN010004" 4
"IN010004" 4
"IN010004" 4
"IN010004" 5
"IN010004" 5
"IN010004" 5
"IN010005" 2
"IN010005" 3
"IN010005" 4
"IN010005" 4
"IN010005" 4
"IN010005" 5
"IN010005" 5
"IN010005" 5
"IN010006" 2
"IN010006" 3
"IN010007" 2
"IN010007" 3
"IN010007" 4
"IN010007" 4
"IN010007" 4
"IN010007" 5
"IN010007" 5
"IN010007" 5
"IN010008" 2
"IN010008" 3
"IN010008" 4
"IN010008" 4
"IN010008" 4
"IN010008" 5
"IN010008" 5
"IN010008" 5
"IN010009" 2
"IN010009" 3
"IN010009" 4
"IN010009" 4
"IN010009" 4
"IN010009" 5
"IN010009" 5
"IN010009" 5
"IN010010" 2
"IN010010" 3
"IN010010" 4
"IN010010" 4
"IN010010" 4
"IN010010" 5
"IN010010" 5
"IN010010" 5
"IN010011" 2
"IN010011" 3
"IN010011" 4
"IN010011" 4
"IN010011" 4
"IN010011" 5
"IN010011" 5
"IN010011" 5
"IN010012" 2
"IN010012" 3
"IN010012" 4
"IN010012" 4
"IN010012" 4
"IN010012" 5
"IN010012" 5
"IN010012" 5
"IN010013" 2
"IN010013" 3
"IN010013" 4
"IN010013" 4
"IN010013" 4
"IN010013" 5
"IN010013" 5
"IN010013" 5
"IN010014" 2
"IN010014" 3
end
As can be seen, for rounds 4 and 5, each childid appears thrice. I want to drop the duplicates for rounds 4 and 5 so that each childid appears only once, as in rounds 2 and 3.
I have tried the following code:
Code:
duplicates tag childid, gen(flag)
drop if flag & (round==4|round==5)
which removes all observations from rounds 4 and 5.

I have also tried
Code:
forvalues i=4/5{
duplicates tag childid, gen(flag) if round==`i'
drop if flag
}
.
which generates the error
Code:
option if not allowed
What I am looking for is duplicates drop code that works only on rounds 4 and 5 but have been unable to figure it out.

Any help from the community would be greatly appreciated.

Regards,
Titir