sergiocorreia / ftools

Fast Stata commands for large datasets
MIT License
134 stars 41 forks source link

fmerge / join changes using-keys>100 to missing #29

Open cg89x opened 4 years ago

cg89x commented 4 years ago

Hi Sergio,

I found a rather weird bug in the fmerge/join command:

Let's say I have a numeric ID ranging from 1 to X where X>100. In the Master data, the ID is always <100 but in the _Using_ data the ID can be > 100. The fmerge/join works, however, it will change all IDs > 100 to missing in the final data. This behavior does happen in all join into/from combinations.

I attached an example code and data.

Best,

Chris

bugexample.zip

(ftools header: ! version 2.37.0 16aug2019, join header: ! version 2.36.1 13feb2019, fmerge header: *! version 2.10.0 3apr2017, stata version 15 mp, mac osx )

sergiocorreia commented 4 years ago
clear all
set obs 3
gen int id = _n
replace id = 200 in 3
gen y = 10 * _n
li
tempfile using
save "`using'"

clear
set obs 3
gen byte id = _n + 1
gen z = 100 * _n
li

de
fmerge 1:1 id using "`using'"
li
de

I could replicate it. This is what's happening:

It should be an easy fix, but a quick workaround would be to do e.g. recast int id (where id is your identifier) right before merging.