楼主: zlqs1985
2853 7

[数据管理求助] 合并截面数据时id名称值不一致产生缺漏值怎么办? [推广有奖]

  • 2关注
  • 17粉丝

已卖:32份资源

副教授

2%

还不是VIP/贵宾

-

威望
0
论坛币
1020 个
通用积分
12.0990
学术水平
2 点
热心指数
6 点
信用等级
2 点
经验
8730 点
帖子
323
精华
0
在线时间
815 小时
注册时间
2008-9-18
最后登录
2023-1-16

楼主
zlqs1985 发表于 2014-11-10 17:34:19 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
这段时间整理数据遇到一个对我来说比较困惑也比较棘手的问题,我想用append命令把几年的截面数据合并成一个面板,但是合并下来显示有缺漏值,而事实上这些所谓的缺漏值在原数据里面都能找到,原因是id name的值在有些年份对不上(我已经用rencode命令把id转成了数字文字对应表),我不知道为什么产生这个原因,因为个年id 名都是一样的。我猜想会不会是使用中文作为id名称的关系,可是在大部分情况下还是能够合并成功的。下面是我在statalist上提的问题(比较长就不翻译了,大家都能看的懂),stata专版上高手大大也很多,希望不吝赐教,小弟已经在这个问题上被卡了一个周末了
---------------------------------------
Hi, I have several cross-section data which id(here named region) and year variable, I want to append them togather to form a panel. When trying to achieve this goal with --append-- command, I encouter series problem that some observations were lost for certain year(s)t, but they are not really missing observation as I can see them in the raw data. So I check the cross-section data sets seperately and find in the these certain year the value of int type variable region is different from other years (I use --recode-- code command to convert "region" from string to int) .For example,the value of region name "哈尔滨"in 5 of 6 data sets are 65 but in year2012 it's 63 so there is a inconsistency. I don't know what cause the inconsistent, the variable type is uniform for all region names and I didn't give them any (value or variable) label before appending. Using the -xtdes- command, I found about 80% of my observations are balanced with the missing of id names concentrated at two years,2012and2006,see below



Freq.  Percent    Cum.   Pattern
---------------------------+----------
262     80.62   80.62   11111111
19      5.85   86.46   1111111.
10      3.08   89.54   1.111111
6      1.85   91.38   .1111111
5      1.54   92.92   ..111111
3      0.92   93.85   11111.11
2      0.62   94.46   ..1.111.
2      0.62   95.08   11.1...1
1      0.31   95.38   ......1.
15      4.62  100.00  (other patterns)
---------------------------+----------
325    100.00           XXXXXXXX



I highly suspect that this problem is due to some kinds of differences of id names (region in this case) between different cross-section data sets. In principle, the --encode-- command attach unique code to a id name, regardless its relative position. But even I tried to copy the  id names of master datasets to substitute the corresponding ones in certain years, the problem remained.That really confuse me. Is that possible that my id names are in chinese characters (b/c they are chinese data) cause this problems ? I don't know. , but it worked just fine in the most
cases and I have too many of them so give id a english names is extremely cubersome
I have stucked by this problem for 2 days and still have no hope, I feel it may due to some stupid reasons that I cannot find. The worst thing is that I have no one to seek for help nearby. So specialists on statalist,please check it and give me some clue, Thank you in advance. Here I pose the raw data, cross-section data and my appended panel data
二维码

扫码加我 拉你入群

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

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

关键词:截面数据 怎么办 缺漏值 observations concentrated achieve several trying 中文 我不知道

沙发
蓝色 发表于 2014-11-10 18:09:45
说那么多,不如把你数据上传部分

藤椅
lili1980 发表于 2014-11-10 18:13:38
说的很有道理!

板凳
zlqs1985 发表于 2014-11-10 18:42:01
蓝色 发表于 2014-11-10 18:09
说那么多,不如把你数据上传部分
dofile.rar (1.03 KB) 本附件包括:
  • dofile.do

panel.rar (12.99 KB) 本附件包括:
  • nut_growth_2005_2012.dta

crosssection.rar (26.27 KB) 本附件包括:
  • nut_growth_2009.dta
  • nut_growth_2010.dta
  • nut_growth_2011.dta
  • nut_growth_2012.dta
  • nut_growth_2005.dta
  • nut_growth_2006.dta
  • nut_growth_2007.dta
  • nut_growth_2008.dta

rawdata.rar (206.71 KB) 本附件包括:
  • 2005_人口.xls
  • 2006_人口.xls
  • 2007_人口.xls
  • 2008_人口.xls
  • 2009_人口.xls
  • 2010_人口.xls
  • 2011_人口.xls
  • 2012_人口.xls

蓝色版主说的极是,我已经上传了,烦请帮我看看问题出在哪里,感激

报纸
lili1980 发表于 2014-11-10 19:19:43
非常有用感谢分享!

地板
蓝色 发表于 2014-11-10 21:17:29
1、你的excel数据本身就存在缺失的
2、excel中的 哪些负数前面的“-” 并不是减号的那个"-",导致转换的时候也会变成缺失

你就这几年的数据,你还是直接在excel里面整理好会更加省时间
已有 1 人评分论坛币 学术水平 热心指数 收起 理由
SpencerMeng + 12 + 1 + 1 观点有启发

总评分: 论坛币 + 12  学术水平 + 1  热心指数 + 1   查看全部评分

7
zlqs1985 发表于 2014-11-11 09:32:59
蓝色 发表于 2014-11-10 21:17
1、你的excel数据本身就存在缺失的
2、excel中的 哪些负数前面的“-” 并不是减号的那个"-",导致转换的时 ...
  谢谢版主回复,我知道数据本身有缺失,另外您说的前面有"-"的情况,我在导入stata之前已经把格式转成数值型了,而且也不是所有的负值都被显示成缺漏值,有的正值也显示成缺漏。我给您的只是一个示例,实际上有20多个变量,全部在excel里处理比较笨拙,而且也不能保证导入stata后不出现问题。

8
蓝色 发表于 2014-11-11 10:23:07
1、stata循环导入数据更加容易出错,你必须保证每个excel数据都是没有问题的才能用循环。你现在就是用的循环,明显就有许多错误。即使20个变量,在excel中先整理好,也比在stata中删除了省许多时间。
因为,你在stata中发现了错误,还的需要到原始的excle中找错误在哪里啊。

笨 有时候是最有效的办法

2、你的那个不是负数,前面的 负号  是一个比 减号  更长的一个 ,因此,在stata中认为那个不是负号

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-4 18:55