楼主: yummyhpy
27940 10

[数据管理求助] 【求助】stata中如何merge面板数据? [推广有奖]

  • 3关注
  • 0粉丝

大专生

13%

还不是VIP/贵宾

-

威望
0
论坛币
903 个
通用积分
1.0102
学术水平
2 点
热心指数
2 点
信用等级
0 点
经验
49 点
帖子
5
精华
0
在线时间
82 小时
注册时间
2012-3-30
最后登录
2019-9-17

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
有两个database,都是面板数据,第一个database里有country,year,kaopen,第二个database里有country,year,fdi, nfa.
有很多国家,每一个国家又对应多个年份的数据。请问怎么在stata中进行merge呢?

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

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

扫码加我 拉你入群

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

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

关键词:Merge Stata 面板数据 tata database 数据 面板 database 不胜感激 country

沙发
yuedragon 在职认证  发表于 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).

已有 1 人评分学术水平 信用等级 收起 理由
SpencerMeng + 1 + 1 好的意见建议

总评分: 学术水平 + 1  信用等级 + 1   查看全部评分

使用道具

藤椅
sewind_tj 发表于 2012-3-30 23:33:26 |只看作者 |坛友微信交流群
merge 1:1 country year using .dta, nogen
善待你一生!
让网络基于真人的故事!

使用道具

板凳
qiaqiao 发表于 2012-3-31 14:28:24 |只看作者 |坛友微信交流群
我遇到多项合并, 用 merge 1:1 stkcd ym using ""
会提示错误,
variables stkcd ym do not uniquely identify observations in the master data

使用道具

报纸
bbs0805 发表于 2012-4-1 08:28:43 |只看作者 |坛友微信交流群
merge 1:1 country year using ,nogen
如果出错,那是你的数据有误:同一年度同一国家出现两次或两次以上的观测

使用道具

地板
yummyhpy 学生认证  发表于 2012-4-4 00:54:52 |只看作者 |坛友微信交流群
谢谢各位!!已经解决好了!就直接用的merge country year using **.dta  在合并之前要对master和using数据都按country year 要sort一下!
已有 2 人评分学术水平 热心指数 收起 理由
hey_na2009 + 1 + 1 精彩帖子
magicmm + 1 + 1 精彩帖子

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

使用道具

7
leesisi 发表于 2015-1-27 15:24:23 |只看作者 |坛友微信交流群
yummyhpy 发表于 2012-4-4 00:54
谢谢各位!!已经解决好了!就直接用的merge country year using **.dta  在合并之前要对master和using数据 ...
就这样?不用1:1令它一一对应也可以吗?

使用道具

8
6002the_micky 发表于 2015-3-25 20:19:00 |只看作者 |坛友微信交流群
上面的方法试过,都不行。。怎么办

使用道具

9
yuxinyang88 学生认证  发表于 2018-2-9 16:33:20 |只看作者 |坛友微信交流群
bbs0805 发表于 2012-4-1 08:28
merge 1:1 country year using ,nogen
如果出错,那是你的数据有误:同一年度同一国家出现两次或两次以上的 ...
大神好厉害!

使用道具

10
六小妖 学生认证  发表于 2018-12-27 11:50:47 |只看作者 |坛友微信交流群
leesisi 发表于 2015-1-27 15:24
就这样?不用1:1令它一一对应也可以吗?
能说下具体的命令吗?

使用道具

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

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

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

GMT+8, 2024-10-6 16:45