全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
7237 8
2019-07-25
有个困惑,假设数据如下

duplicates drop year code,force
那么,删除的是哪一条观测值呢? stata 是根据什么来drop的呢?谢谢~


二维码

扫码加我 拉你入群

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

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

全部回复
2019-7-25 15:29:11
一个code year可以定位到唯一的一个相应数据,如果某code year有n个相同的数据,xtset code year就会显示红字"数据有重复值",duplicates drop就是把相同的n个数据只保留唯一一个。
我个人来说,重复值出现的原因有二:一是数据库本身有重复值;二是公司-年度层面数据是由个体-年度层面数据处理得来。
二维码

扫码加我 拉你入群

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

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

2019-7-25 15:43:00

crup.com.cn/PerCenter/Certificate
the duplicates drop command to drop the duplicate observations.  The command drops all observations except the first occurrence of each group with duplicate observations.


简单例子测试
复制代码


二维码

扫码加我 拉你入群

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

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

2019-7-25 15:45:40
命令帮助里面也写了

[D] duplicates -- Report, tag, or drop duplicate observations
                  (View complete PDF manual entry)
Syntax

    Drop duplicates
        duplicates drop [if] [in]
        duplicates drop varlist [if] [in] , force

Description

    duplicates reports, displays, lists, tags, or drops duplicate observations,
    depending on the subcommand specified.  Duplicates are observations with
    identical values either on all variables if no varlist is specified or on a
    specified varlist.

    duplicates report produces a table showing observations that occur as one or
    more copies and indicating how many observations are "surplus" in the sense
    that they are the second (third, ...) copy of the first of each group of
    duplicates.

    duplicates tag generates a variable representing the number of duplicates for each observation.  This will be 0 for all unique observations.

    duplicates drop drops all but the first occurrence of each group of duplicated observations.  The word drop may not be abbreviated.


    Any observations that do not satisfy specified if and/or in conditions are
    ignored when you use report, examples, list, or drop.  The variable created
    by tag will have missing values for such observations.

二维码

扫码加我 拉你入群

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

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

2019-7-25 17:36:22
duplicates drop drops all but the first occurrence of each group of duplicated observations.  The word drop may not be abbreviated.
谢谢各位!简单用例子 stata试验了下。 一组code 与 year duplicates只保留第一个。
二维码

扫码加我 拉你入群

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

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

2019-7-25 17:39:40
那么问题来了。假设我的data中,code与year相同的记录,其他var有的空值有的非空,那么 在duplicates drop 后,如何实现 后续var非空最多的记录呢? 也就是最为完整的。  谢谢谢谢! @蓝色
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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