I've found an odd bug with fcollapse that I can't figure out. I've reduced it to this example file.
Here's the code to test:
clear
input int p byte c float p2
237 0 0
41 0 5
31 1 6
end
sort p2
preserve
fcollapse (sum) c, by(p)
rename c fc
tempfile t
save `t'
restore
collapse (sum) c, by(p)
merge 1:1 p using `t'
quietly count if c!=fc
disp "Mismatches: `r(N)'"
However, if you add any of the following after the input statement and "sort p2", the problem goes away:
- drop p2
- sort p
- sort c
- gen n = _n; sort n
- rename p2 x
It has something to do with p2 starting with the same letters as p and p2 being sorted, but I couldn't figure out the problem.
Let me know if you need any more information to help figure it out.
I've found an odd bug with fcollapse that I can't figure out. I've reduced it to this example file.
Here's the code to test:
clear
input int p byte c float p2
237 0 0
41 0 5
31 1 6
end
sort p2
preserve
fcollapse (sum) c, by(p)
rename c fc
tempfile t
save `t'
restore
collapse (sum) c, by(p)
merge 1:1 p using `t'
quietly count if c!=fc
disp "Mismatches: `r(N)'"
However, if you add any of the following after the input statement and "sort p2", the problem goes away:
It has something to do with p2 starting with the same letters as p and p2 being sorted, but I couldn't figure out the problem.
Let me know if you need any more information to help figure it out.