全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
29035 10
2012-03-30
有两个database,都是面板数据,第一个database里有country,year,kaopen,第二个database里有country,year,fdi, nfa.
有很多国家,每一个国家又对应多个年份的数据。请问怎么在stata中进行merge呢?

我看好多都是merge variable using **.dta  但这里只有一个相同变量啊,比如我用country,但它对应了很多的year啊,这种情况怎么办呢?

新手求各位大侠解答!不胜感激!!
二维码

扫码加我 拉你入群

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

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

全部回复
2012-3-30 20:50:07
这个很简单!在stata中 运行 和help merge ,帮助中有有这样的例子!



    In some datasets, multiple variables are required to identify the
    observations.  Imagine data obtained by observing patients at specific
    points in time so that variables pid and time, taken together, identify
    the observations.  Below we have two such datasets and run a 1:1 merge on
    pid and time,
        . merge 1:1 pid time using filename
            master      +       using        =        merged result
        +-------------+     +-------------+     +-------------------------+
        |pid  time  x1|     |pid  time  x2|     |pid  time  x1  x2  _merge|
        |-------------|     |-------------|     |-------------------------|
        | 14     1   0|     | 14     1   7|     | 14     1   0   7       3|
        | 14     2   0|     | 14     2   9|     | 14     2   0   9       3|
        | 14     4   0|     | 16     1   2|     | 14     4   0   .       1|
        | 16     1   1|     | 16     2   3|     | 16     1   1   2       3|
        | 16     2   1|     | 17     1   5|     | 16     2   1   3       3|
        | 17     1   0|     | 17     2   2|     | 17     1   0   5       3|
        +-------------+     +-------------+     | 17     2   .   2       2|
                                                +-------------------------+
    This is a 1:1 merge because the combination of the values of pid and time
    uniquely identifies observations in both datasets.
    By default, there is nothing about a 1:1 merge that implies that all, or
    even any of, the observations match.  Above five observations matched,
    one observation was only in the master (subject 14 at time 4), and
    another was only in the using (subject 17 at time 2).

二维码

扫码加我 拉你入群

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

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

2012-3-30 23:33:26
merge 1:1 country year using .dta, nogen
二维码

扫码加我 拉你入群

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

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

2012-3-31 14:28:24
我遇到多项合并, 用 merge 1:1 stkcd ym using ""
会提示错误,
variables stkcd ym do not uniquely identify observations in the master data
二维码

扫码加我 拉你入群

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

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

2012-4-1 08:28:43
merge 1:1 country year using ,nogen
如果出错,那是你的数据有误:同一年度同一国家出现两次或两次以上的观测
二维码

扫码加我 拉你入群

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

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

2012-4-4 00:54:52
谢谢各位!!已经解决好了!就直接用的merge country year using **.dta  在合并之前要对master和using数据都按country year 要sort一下!
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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