楼主: 小痴
3657 6

[求助]merge两个database [推广有奖]

  • 1关注
  • 2粉丝

已卖:94份资源

本科生

65%

还不是VIP/贵宾

-

威望
0
论坛币
341 个
通用积分
2.8309
学术水平
7 点
热心指数
8 点
信用等级
2 点
经验
589 点
帖子
63
精华
0
在线时间
118 小时
注册时间
2005-4-6
最后登录
2024-2-26

楼主
小痴 发表于 2008-6-16 23:49:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币

都有同一个variable,但一个database是unique的,另一个不是unique。相应地obs数目也不同。

希望能merge到那个非unique的dataset里。请问该用什么命令?Thanks!

二维码

扫码加我 拉你入群

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

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

关键词:database Merge Base Data ABA database Merge

沙发
shendu 发表于 2008-6-17 00:04:00

To use -merge-, the two datasets SHOULD be unique and sorted by an index variable. In your stituation, I guess,

index   var1

1           14

2           18

3            23

Index     var2

1              10

1              12

2               2

2              4

....

For the non-unique dataset, you are supposedto  FIRSLTY know WHY YOU ARE MERGING THEM. To generate a unique dataset, you may use -collapse- or -reshape- to calculate the mean, sum, median . . . .. Then merge the two after sorting.

Lastly, one suggestion for those raising questions: describe your question(s) with example rather than just throwing questions out. The more detailed, the more likely people help you out.        

藤椅
小痴 发表于 2008-6-17 00:54:00

Thank you so much.

My question is: one database is about hospitals in California, with "county_name" which is not unique. I have to input county population data from another dataset, in which "county_name" is unique. Like this:

1. hospital  county_name other variables...

    XX          AA                   XXXXX

    xxxx        AA                    XXXXX

    XXX        BB                    XXXXX

......

2. county_name  population

    AA                   123345

    BB                    54321

......

I have to state market population(in this case county population) for every hospital. Thanks!

板凳
whgyu 发表于 2008-6-17 08:04:00
you can merge directly. Stata does not require the common varible to have unique values per observation.

. use data1, clear
. sort county_name
. save, replace

. use data2, clear
. sort county_name
. merge county_name using data1

Let me know if there is any problem

报纸
小痴 发表于 2008-6-17 22:50:00
no, it does not work, just as #2 said. index should be unique to merge datasets.

地板
shendu 发表于 2008-6-17 23:13:00
以下是引用小痴在2008-6-17 0:54:00的发言:

......

I have to state market population(in this case county population) for every hospital. Thanks!

In this case, you do not have to merge in a matching way. The way #4 suggested is supposed to be workable. Make sure you use the first dataset as the MASTER dataset.  If it still does not work, I guess the problem might be that the country_name is not consistently numeric. Make sure country_name has uniform label values.

[此贴子已经被作者于2008-6-17 23:17:54编辑过]

7
lavendercao 发表于 2011-8-3 09:06:54
谢谢朋友们哦,讲解得很详细。

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

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