楼主: myq9861
8840 19

[讨论]如何把数据表中的重复数据项删去 [推广有奖]

11
蓝色 发表于 2008-5-21 07:19:00
以下是引用永恒的凤凰木在2008-5-21 0:28:00的发言:

的确,STATA的基础数据处理能力还不及EXCEL和SPSS方便~~

不见的啊

关键是对stata是否掌握了

我不知道你从那个方面说不如excel和spss。

12
Leokeeper 发表于 2008-5-21 17:11:00

呵呵,

stata的长处之一就是数据处理,很强大的。

可能是你还没有熟练掌握吧

http://www.soudoc.com/bbs/?u=135811

13
myq9861 发表于 2008-5-21 22:42:00

新的问题(同类)又出现了:

在删除重复数据的过程中要指定被删的数据的类型,比如我找了一个数据表,里面的数据有三种值:0,1,2,且每个变量的Format都是%17s。由于是问卷调查,有三种可能,0:没有数据,1:是,2否,所以有些企业在调查过程中没有数据,往往都六个变量都没有数据,我现在要做的就是把这些变量值为0的observations全部去掉,再统计每个变量的1和2各有多少个。

我用了duplicates drop if var1==0

                                                 0.0

                                                 (什么都不输入)  都不行,我想问题出在当变量的Format都是%17s时,数据表的那一栏为空的怎么表示出来?谢谢各位!

14
richardqmul 发表于 2008-5-23 18:34:00

我一直都没用过duplicates 命令. 现在发现确实好用. 

我一般都用: 

by varable , sort: keep if varable~= varable[_N-1]

15
richardqmul 发表于 2008-5-23 18:44:00

去掉0的observations不难. 假设你有六个变量, 分别是var1, var2, var3, var4, var5, var6.

compress

forvalue m=1/6 {

   drop if var`m'==0

   by var`m', sort: count 

  dis "-------------------------------------"

}

已有 1 人评分论坛币 学术水平 热心指数 收起 理由
crystal8832 + 10 + 1 + 1 热心帮助其他会员

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

16
myq9861 发表于 2008-5-25 09:47:00

谢谢高手指导,试过了,这样可以让每一行全为了0的observation去掉,但是有个小问题:如果我的某一个样本数据中的若干个变量中只有一个变量值为0的话,那么运行上一段程序后,这一行的数据就全部被删了,不知道我试的对不对,而在实际操作中这样的数据是不是就被删了,还是保留估计也没有一个标准,可能有时候还是要留下来,如果样本数量少的话,呵呵~

感谢各位高手指点。

17
richardqmul 发表于 2008-5-25 16:21:00

用以下的命令

count

compress

drop if (var1==0)*(var2==0)*(var3==0)*(var4==0)*(var5==0)*(var6==0) in 1/l

count

18
myq9861 发表于 2008-5-25 17:50:00

感谢您的解答,刚刚试过,很好用。

这边又有一个问题:我有一组变量(六个),样本数据有9个,但这9个样本之间有一定的相关性,因为是扫描同一个数据库里的数据,不同的标准来统计的。数据如下,我的问题是如何用Pearson相关系数来反应,我用了correlate ,但得到的结果与文章中的不同,望指点。谢谢

table 1

                                                                      IntRD          ExtRD         Machi       Techno      Trial          Market  
Overall sample                                              37.2           17.4             73.4           29.2           19.9          28.3  
Using appropriation instruments                    25.7            14.7            76.2           27.3           15.0          20.6  
Not using them                                               55.9            21.7           69.0           32.3           27.7         40.8  
Using legal appropriation instruments            57.3           23.5            68.6            36.1          30.0          45.7  
Using strategic appropriation instruments      63.7           24.1            71.0           29.4           29.0          40.3  
Manufacturing                                                42.4           18.4            73.4           23.5           21.6          27.3  
Services                                                        26.6            15.2           73.4            41.0           16.2         30.4  
Low-technology/knowledge content               29.3            16.5           76.8           29.7           18.6          26.6  
High-technology/knowledge content              59.9            19.8           64.0           27.9           23.3          33.0  

table 2书上的结果

Association between the different types of expenditure (Pearson’s φ)  
               IntRD         ExtRD  Machi     Techno     Trial     Market  
IntRD      1.000       0.179      −0.225  −0.012     0.119     0.129  
ExtRD     0.179     1.000     −0.036     0.050     0.020    0.109  
Machi     −0.225    −0.036   1.000      0.142     −0.101    −0.004  
Techno    −0.012   0.050   0.142       1.000     0.072     0.149  
Trial         0.119   0.020    −0.101       0.072     1.000     0.255  
Market     0.129    0.109  −0.004        0.149     0.255     1.000  

我的结果:(var 2到7依次是上表中的IntRD等等)我用的命令是:corre


             |     IntRD         ExtRD  Machi     Techno     Trial     Market   

      IntRD |   1.0000
       ExtRD|   0.9413   1.0000
      Machi |  -0.8302  -0.6511    1.0000
      Techno|  -0.0949   0.0310  -0.0970   1.0000
        Trial     |   0.9274   0.9919  -0.6589   0.0570   1.0000
        Market |   0.8195   0.9109  -0.6661   0.4202   0.9288   1.0000

有关的一段说明如下:

The first line of Table 1 shows the proportion of firms
that had some expenditure on the different types of innovation
activity.
Clustering innovation activities will help us simplify
our models that aim to predict their occurrence. In order
to find groups of activities which are conceptually complementary
and actually done together by a substantial
number of firms, we estimate the relationships between
all possible pairs of binary variables indicating if the firm
carried out the different innovation activities. The Pearson’s
φ statistic was used. For 2×2 tables, it is bounded
between−1 and +1 and thus interpreted like a correlation
(Table 2).

谢谢高手指点

19
richardqmul 发表于 2008-5-28 01:29:00

大家帮忙看看....

20
随忆LSQ 发表于 2020-4-10 11:13:24
完整命令: duplicates drop XXX,force,谢谢

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-28 15:23