楼主: _____J.
1516 2

[数据管理求助] 关于merge的问题请教 [推广有奖]

  • 0关注
  • 0粉丝

高中生

92%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
912 点
帖子
6
精华
0
在线时间
67 小时
注册时间
2011-9-28
最后登录
2015-12-25

楼主
_____J. 发表于 2014-4-26 10:45:26 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
请问,merge合并中,两张表在合并的时候,分别用1:m与m:1的结果为什么不一样?
二维码

扫码加我 拉你入群

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

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

关键词:Merge

沙发
丛林的风 发表于 2014-5-10 14:57:35
没有人给予解答吗?

藤椅
╰不滅信念 学生认证  发表于 2014-5-10 17:23:34

摘自

STATADATAMANAGEMENT
REFERENCEMANUAL
RELEASE 12

m:1 merges

In an m:1 merge, the key variable or variables uniquelyidentify the observations in the using data, but not necessarily in the master data.Suppose you had person-level data within regions and you wished to bring in regionaldata. Here is an example:

. mergem:1 region using filename

master              +             using              =                       merged result

  

id

  
  

region

  
  

a

  
  

  
  

region

  
  

x

  
  

  
  

id

  
  

region

  
  

a

  
  

x

  
  

_merge

  
  

1

  
  

2

  
  

26

  
  

  
  

1

  
  

15

  
  

  
  

1

  
  

2

  
  

26

  
  

13

  
  

3

  
  

2

  
  

1

  
  

29

  
  

  
  

2

  
  

13

  
  

  
  

2

  
  

1

  
  

29

  
  

15

  
  

3

  
  

3

  
  

2

  
  

22

  
  

  
  

3

  
  

12

  
  

  
  

3

  
  

2

  
  

22

  
  

13

  
  

3

  
  

4

  
  

3

  
  

21

  
  

  
  

4

  
  

11

  
  

  
  

4

  
  

3

  
  

21

  
  

12

  
  

3

  
  

5

  
  

1

  
  

24

  
  

  
  

  
  

  
  

  
  

5

  
  

1

  
  

24

  
  

15

  
  

3

  
  

6

  
  

5

  
  

20

  
  

  
  

  
  

  
  

  
  

6

  
  

5

  
  

20

  
  

.

  
  

1

  
  

  
  

  
  

  
  

  
  

  
  

  
  

  
  

.

  
  

4

  
  

.

  
  

11

  
  

2

  

To bring in the regional information, we need to mergeon region. The values of region identify individual observations in the using data,but it is not an identifier in the master data.

We show the merged dataset sorted by id because this makesit easier to see how the merged dataset was constructed. For each observation inthe master data, merge finds the corresponding observation in the using data. mergecombines the values of the variables in the using dataset to the observations inthe master dataset.




1:m merges

1:m merges are similarto m:1, except that now the key variablesidentify unique observations in the master dataset.Any datasets that can be merged using an m:1 merge may be merged using a 1:m merge by reversingthe roles of the master and using datasets. Here is the same example as used previously, with the master and using datasets reversed:

. merge 1:m region using filename

master          +               using                       =                         merged result

  

region

  
  

x

  
  

  
  

id

  
  

region

  
  

a

  
  

  
  

region

  
  

x

  
  

id

  
  

a

  
  

_merge

  
  

1

  
  

15

  
  

  
  

1

  
  

2

  
  

26

  
  

  
  

1

  
  

15

  
  

2

  
  

29

  
  

3

  
  

2

  
  

13

  
  

  
  

2

  
  

1

  
  

29

  
  

  
  

1

  
  

15

  
  

5

  
  

24

  
  

3

  
  

3

  
  

12

  
  

  
  

3

  
  

2

  
  

22

  
  

  
  

2

  
  

13

  
  

1

  
  

26

  
  

3

  
  

4

  
  

11

  
  

  
  

4

  
  

3

  
  

21

  
  

  
  

2

  
  

13

  
  

3

  
  

22

  
  

3

  
  

  
  

  
  

  
  

5

  
  

1

  
  

24

  
  

  
  

3

  
  

12

  
  

4

  
  

21

  
  

3

  
  

  
  

  
  

  
  

6

  
  

5

  
  

20

  
  

  
  

4

  
  

11

  
  

.

  
  

.

  
  

1

  
  

  
  

  
  

  
  

  
  

  
  

  
  

  
  

5

  
  

.

  
  

6

  
  

20

  
  

2

  

This merged result is identical to the merged result in the previous section, except for the sort order and the contentsof merge. This time, we show the merged result sorted by region rather than id. Reversing the roles of the files causes a reversal in the 1s and 2s for merge:where merge was previously 1, itis now 2, and vice versa. These exchangedmerge values reflect the reversed roles of the masterand using data.

For each observation in the master data,  merge found the corresponding observation(s) in the using data and then wrote down the matched or unmatched result.Once the master observations wereexhausted, merge wrote down any observations from the using data that were never used.



一言以蔽之,就是1:m
左边的变量的观测值是唯一的(不会出现重复值)
m:1
右边的变量的观测值是唯一的(不会出现重复值)

大概就这意思。。






已有 2 人评分学术水平 热心指数 信用等级 收起 理由
经济大菜鸟 + 1 + 1 + 1 精彩帖子
an你若成风 + 1 + 1 + 1 

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

where there is a will there is a way

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-31 14:23