楼主: heartLisa_
2622 3

[数据管理求助] [数据管理求助] stata中用merge m:1 匹配后存在部分数据匹配错误 [推广有奖]

  • 1关注
  • 0粉丝

等待验证会员

大专生

8%

还不是VIP/贵宾

-

威望
0
论坛币
358 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
126 点
帖子
5
精华
0
在线时间
78 小时
注册时间
2015-8-2
最后登录
2022-11-22

楼主
heartLisa_ 发表于 2020-1-3 17:20:29 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
求问,stata中用merge m:1 匹配后存在部分数据匹配错误是什么原因?如何解决?
面板数据,辅表是公司-年度数据(Year),主表是公司-月度数据(Month),要把年度数据merge到月度数据表格中,唯一标识是ID,为股票代码和年份(例如ID=“0000022009”),打开月度数据文件,stata代码如下
微信图片_20200103171012.png
主表(Month)部分数据如下


----------------------- copy starting from the next line -----------------------
[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input str6 Code str4 Year1 int t str10 ID double(RFt MVet)
"000002" "2009" 17928 "0000022009"             .010006  915.6069708564543
"000002" "2009" 17956 "0000022009"             .009605  1055.846662409969
"000002" "2009" 17987 "0000022009"              .00981 1364.0598223200764
"000002" "2009" 18017 "0000022009"             .016408  1421.957501604218
"000002" "2009" 18048 "0000022009"             .016023 1014.2458197351197
"000002" "2009" 18078 "0000022009"             .014455 1121.5360154185607
"000002" "2009" 18109 "0000022009" .015170999999999999 1226.2244715475588
"000002" "2009" 18140 "0000022009" .014820999999999999 1230.8107573852722
"000002" "2009" 18170 "0000022009" .014953000000000001 1159.0886991472096
"000002" "2009" 18201 "0000022009" .016529000000000002  995.2635567267103
"000002" "2009" 18231 "0000022009"             .016294  1008.700347360728
"000002" "2009" 18262 "0000022009" .015501000000000001  1022.635842809829
"000002" "2010" 18293 "0000022010"             .015892  842.3311966129778
"000002" "2010" 18321 "0000022010"             .018162  789.2383711195743
"000002" "2010" 18352 "0000022010" .021345999999999997  750.2731847096659
"000002" "2010" 18382 "0000022010"             .019318  918.9252458095446
"000002" "2010" 18413 "0000022010"             .019163  924.4181010429487
"000002" "2010" 18443 "0000022010"             .019459  924.5291320019117
"000002" "2010" 18474 "0000022010"              .02043 1065.1108630687625
"000002" "2010" 18505 "0000022010"             .027925  897.8020962345086
"000002" "2010" 18535 "0000022010"                .033  903.1347058629831
"000002" "2010" 18566 "0000022010"             .031527  901.3041669397354
"000002" "2010" 18596 "0000022010"                 .03  890.9692864018114
"000002" "2010" 18627 "0000022010" .028734000000000003  954.1813045531461
"000002" "2011" 18658 "0000022011"             .028094  941.8653192268572
"000002" "2011" 18686 "0000022011"             .030348  876.2309443781596
"000002" "2011" 18717 "0000022011"             .034742  932.5848606830472
"000002" "2011" 18747 "0000022011" .037339000000000004  905.8379363103577
"000002" "2011" 18778 "0000022011"             .039174   896.665858929964
"000002" "2011" 18808 "0000022011"             .036069   773.224047786045
"000002" "2011" 18839 "0000022011"             .031398  868.4465311005226
"000002" "2011" 18870 "0000022011"             .027366  762.7309496250799
"000002" "2011" 18900 "0000022011"             .027167  804.9864715843038
"000002" "2011" 18931 "0000022011" .027658000000000002  831.2659244129657
"000002" "2011" 18961 "0000022011" .029474999999999998   908.210060329776
"000002" "2011" 18992 "0000022011"             .028355  899.6983838293878
"000002" "2012" 19023 "0000022012" .028561999999999997  979.5264206812299
"000002" "2012" 19052 "0000022012"             .022307 1004.4180245119776


辅表(Year)部分数据如下
----------------------- copy starting from the next line -----------------------
[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input str6 Code str4 Year str10 ID double Et
"000002" "2009" "0000022009"        46.3986915273
"000002" "2010" "0000022010"    64.30007538689999
"000002" "2011" "0000022011"    88.39610505040001
"000002" "2012" "0000022012"       115.9960621177
"000002" "2013" "0000022013"       156.6258842306
"000002" "2014" "0000022014"   182.97549871240003
"000002" "2015" "0000022015"   192.87524028080003
"000002" "2016" "0000022016"       259.4943802631
"000002" "2017" "0000022017"       283.5025548066
"000002" "2018" "0000022018"       372.0838733007
"000002" "2019" "0000022019"       492.7229453461
"000004" "2009" "0000042009"  -.11484191490000001
"000004" "2011" "0000042011"   .20201272920000002
"000004" "2012" "0000042012"          .0919306782
"000004" "2013" "0000042013"          .0781422529
"000004" "2014" "0000042014"          .0579674979
"000004" "2015" "0000042015"          .1562481356
"000004" "2016" "0000042016"   .06857151709999999
"000004" "2017" "0000042017"          .3971631622
"000004" "2018" "0000042018"          .0589224141
"000004" "2019" "0000042019"  -.21612682100000002
"000005" "2009" "0000052009"          .1049971992
"000005" "2010" "0000052010"         -.4891952898
"000005" "2011" "0000052011" -.044263870999999996
"000005" "2013" "0000052013"          .2202161789
"000005" "2014" "0000052014"  -.42344755219999997
"000005" "2015" "0000052015"   .43163944159999995
"000005" "2016" "0000052016"          -.540317165
"000005" "2017" "0000052017"         1.1696241987
"000005" "2018" "0000052018"          .2293599194
"000005" "2019" "0000052019"   1.5674862608000002
"000006" "2009" "0000062009"         1.5021106891
"000006" "2010" "0000062010"   3.3522296907999998
"000006" "2011" "0000062011"         4.9646507546
"000006" "2012" "0000062012"         4.3411700789
"000006" "2013" "0000062013"         6.2956537996
"000006" "2014" "0000062014"           6.98009106
"000006" "2015" "0000062015"         5.1245355951
"000006" "2016" "0000062016"         4.3878591509
"000006" "2017" "0000062017"         8.0387652551
"000006" "2019" "0000062019"         9.2312739615
"000007" "2009" "0000072009"         -.6500725877
"000007" "2010" "0000072010"   .20420709850000002
"000007" "2011" "0000072011"          .2170015805
"000007" "2012" "0000072012"          .0831053862
"000007" "2013" "0000072013"  .044332963899999994
"000007" "2014" "0000072014"          .1883060346
"000007" "2015" "0000072015"         -.3338264702
"000007" "2016" "0000072016"          .1323887222
"000007" "2017" "0000072017"           .815679611
"000007" "2019" "0000072019"  -1.9620020149000001
"000008" "2009" "0000082009" .0074803714000000006
"000008" "2010" "0000082010"          .0031348874
"000008" "2011" "0000082011"          .0088894826
"000008" "2012" "0000082012" -.005394518199999999
"000008" "2013" "0000082013"          .3912903059
"000008" "2014" "0000082014"          .2275795394
"000008" "2015" "0000082015"          .0776640264
"000008" "2016" "0000082016"   1.8990915959999999
"000008" "2017" "0000082017"         5.3054164136
"000008" "2018" "0000082018"         8.8960989013
"000008" "2019" "0000082019"         3.4188969813
"000009" "2009" "0000092009"   2.7154491923000004
"000009" "2010" "0000092010"         4.0859440942
"000009" "2011" "0000092011"         4.4159406586
"000009" "2012" "0000092012"   3.8043540827999998
"000009" "2013" "0000092013"         3.0730112667
合并后部分数据如下,含有部分匹配错误,变成重复值的数据(从"0000022011"开始往下Et都是错误数据,第二、三行的RFt、第四、五、八、九、十行的MVet等等也都是错误数据)

----------------------- copy starting from the next line -----------------------
[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input str6 Code2 str4 Year1 int t str10 ID double(Et RFt MVet)
"000002" "2009" 17928 "0000022009"     46.3986915273             .010006  915.6069708564543
"000002" "2009" 17956 "0000022009"     46.3986915273             .010006  1055.846662409969
"000002" "2009" 17987 "0000022009"     46.3986915273             .010006             1125.3
"000002" "2009" 18017 "0000022009"     46.3986915273             .016408             1125.3
"000002" "2009" 18048 "0000022009"     46.3986915273             .016023 1014.2458197351197
"000002" "2009" 18078 "0000022009"     46.3986915273             .014455 1121.5360154185607
"000002" "2009" 18109 "0000022009"     46.3986915273 .015170999999999999             1125.3
"000002" "2009" 18140 "0000022009"     46.3986915273 .014820999999999999             1125.3
"000002" "2009" 18170 "0000022009"     46.3986915273 .014953000000000001             1125.3
"000002" "2009" 18201 "0000022009"     46.3986915273 .016529000000000002  995.2635567267103
"000002" "2009" 18231 "0000022009"     46.3986915273             .016294  1008.700347360728
"000002" "2009" 18262 "0000022009"     46.3986915273 .015501000000000001  1022.635842809829
"000002" "2010" 18293 "0000022010" 64.30007538689999             .015892  842.3311966129778
"000002" "2010" 18321 "0000022010" 64.30007538689999             .018162  789.2383711195743
"000002" "2010" 18352 "0000022010" 64.30007538689999 .021345999999999997  750.2731847096659
"000002" "2010" 18382 "0000022010" 64.30007538689999             .019318  918.9252458095446
"000002" "2010" 18413 "0000022010" 64.30007538689999             .019163  924.4181010429487
"000002" "2010" 18443 "0000022010" 64.30007538689999             .019459  924.5291320019117
"000002" "2010" 18474 "0000022010" 64.30007538689999              .02043 1065.1108630687625
"000002" "2010" 18505 "0000022010" 64.30007538689999             .027925  897.8020962345086
"000002" "2010" 18535 "0000022010" 64.30007538689999                .033  903.1347058629831
"000002" "2010" 18566 "0000022010" 64.30007538689999             .031527  901.3041669397354
"000002" "2010" 18596 "0000022010" 64.30007538689999                 .03  890.9692864018114
"000002" "2010" 18627 "0000022010" 64.30007538689999 .028734000000000003  954.1813045531461
"000002" "2011" 18658 "0000022011"       78.60411559             .028094  941.8653192268572
"000002" "2011" 18686 "0000022011"       78.60411559             .030348  876.2309443781596
"000002" "2011" 18717 "0000022011"       78.60411559             .034742  932.5848606830472
"000002" "2011" 18747 "0000022011"       78.60411559 .037339000000000004  905.8379363103577
"000002" "2011" 18778 "0000022011"       78.60411559             .039174   896.665858929964
"000002" "2011" 18808 "0000022011"       78.60411559             .036069   773.224047786045
"000002" "2011" 18839 "0000022011"       78.60411559             .031398  868.4465311005226
"000002" "2011" 18870 "0000022011"       78.60411559             .027366  762.7309496250799
"000002" "2011" 18900 "0000022011"       78.60411559             .027167  804.9864715843038
"000002" "2011" 18931 "0000022011"       78.60411559 .027658000000000002  831.2659244129657
"000002" "2011" 18961 "0000022011"       78.60411559 .029474999999999998   908.210060329776
"000002" "2011" 18992 "0000022011"       78.60411559             .028355  899.6983838293878
"000002" "2012" 19023 "0000022012"       78.60411559 .028561999999999997  979.5264206812299
"000002" "2012" 19052 "0000022012"       78.60411559             .022307 1004.4180245119776
"000002" "2012" 19083 "0000022012"       78.60411559              .02342  971.4236626818927
"000002" "2012" 19113 "0000022012"       78.60411559             .023077 1000.5302180347118
"000002" "2012" 19144 "0000022012"       78.60411559             .026806    880.69671403434
"000002" "2012" 19174 "0000022012"       78.60411559             .027921  920.8966713068766
"000002" "2012" 19205 "0000022012"       78.60411559 .029327000000000002  913.4670746436292
"000002" "2012" 19236 "0000022012"       78.60411559             .028834  975.0726540988401
"000002" "2012" 19266 "0000022012"       78.60411559              .02905  1112.955437333475
"000002" "2012" 19297 "0000022012"       78.60411559             .028047             1125.3
"000002" "2012" 19327 "0000022012"       78.60411559             .027612             1125.3
"000002" "2012" 19358 "0000022012"       78.60411559 .026789999999999998             1125.3
"000002" "2013" 19389 "0000022013"       78.60411559             .027842             1125.3
"000002" "2013" 19417 "0000022013"       78.60411559             .028682             1125.3
"000002" "2013" 19448 "0000022013"       78.60411559 .034811999999999996 1100.3169535854206
"000002" "2013" 19478 "0000022013"       78.60411559             .034908 1071.0416926807593
"000002" "2013" 19509 "0000022013"       78.60411559 .036185999999999996  1080.935173125802
"000002" "2013" 19539 "0000022013"       78.60411559             .035451 1033.5457327137774


谢谢各位大神

二维码

扫码加我 拉你入群

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

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

关键词:stata数据分析merge使用方法

沙发
震震果实 发表于 2020-1-3 18:04:31
  1. merge m:1 Code Year using cs2
复制代码

藤椅
heartLisa_ 发表于 2020-1-3 19:14:32
震震果实 发表于 2020-1-3 18:04
谢谢!我的ID变量就是Code+Year,刚才又试了一遍发现merge没问题了

板凳
湘江之水 发表于 2020-8-20 15:45:04

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-2-8 02:32