全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
3616 6
2008-06-16

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

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

二维码

扫码加我 拉你入群

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

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

全部回复
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!

二维码

扫码加我 拉你入群

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

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

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.
二维码

扫码加我 拉你入群

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

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

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编辑过]

二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群