楼主: fgleric
19917 15

[学习心得] merge m:m vs joinby [推广有奖]

  • 5关注
  • 51粉丝

贵宾

副教授

38%

还不是VIP/贵宾

-

威望
1
论坛币
360000 个
通用积分
387.5053
学术水平
294 点
热心指数
310 点
信用等级
226 点
经验
18027 点
帖子
530
精华
0
在线时间
546 小时
注册时间
2007-3-16
最后登录
2020-10-4

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
之前一直对merge m:m不感冒,直到最近才发现它的好处。

废话少说,上log
set obs 300
egen id=seq()
gen firm=1
save "firmid"
clear

set obs 10000
egen id=seq()
replace id=int(id/100) if id>100*there will be firm id greater than 100
gen employ=id+100
save "employ"

*i plan to assign each employ value in eploy.dta to firid.dta
use firmid.dta
sort id
merge m:m id using employment
*in this case, all firm id are kept

clear
use firmid.dta
joinby id using employ.dta
*in this case, only id <=100 are kept.



唉,怪自己不认真那

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:joinby Merge join employment replace employment replace

已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
crystal8832 + 20 + 1 + 1 精彩帖子
Sunknownay + 100 + 10 + 1 + 1 + 1 鼓励积极发帖讨论

总评分: 经验 + 100  论坛币 + 30  学术水平 + 2  热心指数 + 2  信用等级 + 1   查看全部评分

沙发
ermutuxia 发表于 2012-10-16 16:22:50 |只看作者 |坛友微信交流群
感谢分享!

使用道具

藤椅
改革同步 发表于 2012-12-12 09:12:11 |只看作者 |坛友微信交流群
学习了

使用道具

板凳
lynnyang606 发表于 2012-12-19 16:02:31 |只看作者 |坛友微信交流群
学习了

使用道具

报纸
peyzf 发表于 2012-12-20 07:55:40 |只看作者 |坛友微信交流群
learning.

使用道具

地板
brease 发表于 2013-4-28 21:46:48 |只看作者 |坛友微信交流群
这是一种什么学习精神?joinby有选项

joinby id using employ.dta, unmatched(master)
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Stakiny + 2 + 2 + 2 鼓励积极发帖讨论

总评分: 学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

使用道具

7
xiangbow 发表于 2014-2-12 00:37:32 |只看作者 |坛友微信交流群
楼主这种情况下不会报错是因为只有一个variable id
如果你做出两个 id1 和 id2
情况会大不一样
实际数据操作中很少有这么简单的merge
已有 1 人评分论坛币 热心指数 收起 理由
crystal8832 + 5 + 1 分析的有道理

总评分: 论坛币 + 5  热心指数 + 1   查看全部评分

使用道具

8
SpencerMeng 在职认证  发表于 2014-5-9 13:36:49 |只看作者 |坛友微信交流群
楼主 您的code有小问题哦
merge m:m id using employment
应该是merge m:m id using employ
已有 1 人评分论坛币 热心指数 收起 理由
crystal8832 + 5 + 1 鼓励积极发帖讨论

总评分: 论坛币 + 5  热心指数 + 1   查看全部评分

有问题来发帖,来发帖没问题!
我尊重版规,一切为了学术!
Stata专版版规:https://bbs.pinggu.org/thread-1651470-1-1.html

使用道具

9
xingxf 发表于 2014-5-13 06:37:40 |只看作者 |坛友微信交流群
楼主的操作有问题啊。看看Stata自己的解释吧:
“m:m specifies a many-to-many merge and is a bad idea. In an m:m merge, observations are matched
within equal values of the key variable(s), with the first observation being matched to the first; the
second, to the second; and so on. If the master and using have an unequal number of observations
within the group, then the last observation of the shorter group is used repeatedly to match with
subsequent observations of the longer group. Thus m:m merges are dependent on the current sort
order—something which should never happen.
Because m:m merges are such a bad idea, we are not going to show you an example. If you think
that you need an m:m merge, then you probably need to work with your data so that you can use a
1:m or m:1 merge.”

说的很清楚,merge m:m 是要避免使用的
已有 2 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
MRchesian + 1 + 1 + 1 精彩帖子
crystal8832 + 10 + 1 + 1 观点有启发

总评分: 论坛币 + 10  学术水平 + 2  热心指数 + 2  信用等级 + 1   查看全部评分

使用道具

10
零点晓敏 学生认证  发表于 2014-8-15 21:15:29 |只看作者 |坛友微信交流群
xingxf 发表于 2014-5-13 06:37
楼主的操作有问题啊。看看Stata自己的解释吧:
“m:m specifies a many-to-many merge and is a bad idea. ...
我在进行merge的时候也出现了这个问题,用来合并的关键变量在两个文件中都有重复,成了多对多合并了,请问这种情况下一定要修改一下数据吗?

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-4 21:17