Consider this toy situation:
Now if I run
where the assertion of course fails, the resulting dataset looks like this:
That is, it has not obeyed my desire to keep only the _merge == 3 observations, but it has chosen to drop the _merge == 2 observations while retaining the _merge == 1 observation.
On the other hand, if I had done just
then we get
i.e. Stata keeps all observations, matched or unmatched in any direction.
This is not making sense to me. Either the presence of the -keep- option should have made Stata only keep the desired result, or it should keep all observations (as it does when -keep- is not specified).
I am on Stata 18/MP, but I have tested this on the most updated version of Stata 16/MP, and I see the same behaviour. I don't recall ever encountering this before, so I don't know if this is the result of some relatively recent update to -merge-.
Code:
clear input byte(id num) 1 10 2 20 3 30 4 40 end tempfile using save `using' clear input byte(id numnum) 1 1 2 2 5 5 end
Code:
merge 1:1 id using `using', assert(1 3) keep(3)
Code:
. list +-------------------------------------+ | id numnum num _merge | |-------------------------------------| 1. | 1 1 10 matched (3) | 2. | 2 2 20 matched (3) | 3. | 5 5 . master only (1) | +-------------------------------------+
On the other hand, if I had done just
Code:
merge 1:1 id using `using', assert(1 3)
Code:
. list +-------------------------------------+ | id numnum num _merge | |-------------------------------------| 1. | 1 1 10 matched (3) | 2. | 2 2 20 matched (3) | 3. | 5 5 . master only (1) | 4. | 3 . 30 using only (2) | 5. | 4 . 40 using only (2) | +-------------------------------------+
This is not making sense to me. Either the presence of the -keep- option should have made Stata only keep the desired result, or it should keep all observations (as it does when -keep- is not specified).
I am on Stata 18/MP, but I have tested this on the most updated version of Stata 16/MP, and I see the same behaviour. I don't recall ever encountering this before, so I don't know if this is the result of some relatively recent update to -merge-.
Comment