楼主: llf2000
27412 15

[数据管理求助] stata如何筛选日期? [推广有奖]

  • 0关注
  • 0粉丝

已卖:257份资源

本科生

21%

还不是VIP/贵宾

-

威望
0
论坛币
3897 个
通用积分
3.3810
学术水平
0 点
热心指数
8 点
信用等级
4 点
经验
539 点
帖子
52
精华
0
在线时间
97 小时
注册时间
2005-6-9
最后登录
2022-3-19

楼主
llf2000 发表于 2016-9-7 16:36:30 |AI写论文
20论坛币

stata如何筛选日期?


本人要处理的数据如下:是一支股票自1992年至2016年的每天交易情况,而我只想要2015年1月1号到2016年2月1号的数据,请问如何筛选???需要什么命令?(请注意日期的格式)注:本人是用的cntrade命令得到的数据。

急需,可加币


关键词:Stata tata Trade cnt stata stata软件 stata如何筛选日期

本帖被以下文库推荐

沙发
llf2000 发表于 2016-9-7 16:38:19
忘了加图,如下图。。。。。。。

719E.jpg.png (38.98 KB)

719E.jpg.png

藤椅
llf2000 发表于 2016-9-7 16:47:38
请大家帮助我

板凳
黃河泉 在职认证  发表于 2016-9-7 17:20:54
llf2000 发表于 2016-9-7 16:47
请大家帮助我
简单作法之一为
  1. gen t = _n
复制代码
然后看看你要的日期所对应的 t (假设分别为 135 与 258),试试
  1. drop if t<135 | t>258
复制代码

报纸
黃河泉 在职认证  发表于 2016-9-7 17:24:11
llf2000 发表于 2016-9-7 16:47
请大家帮助我
你的 rit 是文字哦!小心一點!
已有 1 人评分热心指数 收起 理由
夏目贵志 + 1 热心帮助其他会员

总评分: 热心指数 + 1   查看全部评分

地板
llf2000 发表于 2016-9-7 23:38:22
黃河泉 发表于 2016-9-7 17:20
简单作法之一为然后看看你要的日期所对应的 t (假设分别为 135 与 258),试试
我要处理面板数据呢?这么弄太麻烦了吧,我要是append100支股票,这么筛选太麻烦呢,您觉得呢?

7
蓝色 发表于 2016-9-8 07:45:26
看看函数function里面的日期相关的函数把


Title

    [D] functions -- Functions


Description

    This is a quick reference for the time-series functions.  See [TS] time series for an introduction to the time-series analysis commands.  See [D]
    datetime concerning date and time functions.  For help on all functions, see [D] functions.

    Stata also provides lag, lead, and difference operators; see [U] 11.4 varlists.


Selecting time spans

    tin(d1, d2)
       Domain d1:    data or time literals recorded in units of t previously tsset
       Domain d2:    data or time literals recorded in units of t previously tsset
       Range:        0 and 1, 1 means true
       Description:  true if d1 < t < d2, where t is the time variable previously tsset.

                     You must have previously tsset the data to use tin().  When you tsset the data, you specify a time variable t, and the format on t
                     states how it is recorded.  You type d1 and d2 according to that format.

                     If t has a %tc format, you could type tin(5jan1992 11:15, 14apr2002 12:25).

                     If t has a %td format, you could type tin(5jan1992, 14apr2002).

                     If t has a %tw format, you could type tin(1985w1, 2002w15).

                     If t has a %tm format, you could type tin(1985m1, 2002m4).

                     If t has a %tq format, you could type tin(1985q1, 2002q2).

                     If t has a %th format, you could type tin(1985h1, 2002h1).

                     If t has a %ty format, you could type tin(1985, 2002).

                     Otherwise, t is just a set of integers, and you could type tin(12, 38).

                     The details of the %t format do not matter.  If your t is formatted %tdnn/dd/yy so that 5jan1992 displays as 1/5/92, you would still
                     type the date in day-month-year order:  tin(5jan1992, 14apr2002).

    twithin(d1, d2)
       Domain d1:    date or time literals recorded in units of t previously tsset
       Domain d2:    date or time literals recorded in units of t previously tsset
       Range:        0 and 1, 1 means true
       Description:  true if d1 < t < d2, where t is the time variable previously tsset; see the tin() function; twithin() is similar, except the range
                         is exclusive.
已有 3 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
眼樟预案诸 + 1 + 1 + 1 精彩帖子
夏目贵志 + 10 有帮助
黃河泉 + 2 + 2 + 2 好的意见建议

总评分: 论坛币 + 10  学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

8
黃河泉 在职认证  发表于 2016-9-8 07:50:36
llf2000 发表于 2016-9-7 23:38
我要处理面板数据呢?这么弄太麻烦了吧,我要是append100支股票,这么筛选太麻烦呢,您觉得呢?
没错,如果是面板数据,的确如此!我昨天本来想跟你讲另一个指令 tin(d1,d2), 就如同"蓝色"所建议,但这又涉及到你必须将 date 变量转成 Stata 型态,然后才能对应 d1, d2!

9
mengdengliao 发表于 2018-2-12 14:26:47
黃河泉 发表于 2016-9-8 07:50
没错,如果是面板数据,的确如此!我昨天本来想跟你讲另一个指令 tin(d1,d2), 就如同"蓝色"所建议,但这又 ...
黄老师您好!
假如我想把时间在2005-06-06到2007-10-16的时间段定义为熊市,赋值bull=1,应该如何编程
我之前写了replace bull=1 if ymd<td(2007-10-16)&ymd>td(2005-06-06),发现不行,tin这个函数我也不太会用。。请指教这里怎么用tin函数?谢谢!
  1. * Example generated by -dataex-. To install: ssc install dataex
  2. clear
  3. input long symbol float(ymd bull)
  4. 163402 16891 0
  5. 163302 16891 0
  6. 320003 16891 0
  7.   2001 16891 0
  8. 375010 16891 0
  9. 20006 16891 0
  10. 161601 16891 0
  11. 184699 16891 0
  12. 184692 16891 0
  13. 200002 16891 0
  14. 500010 16891 0
  15. 310318 16891 0
  16. 184719 16891 0
  17. 110002 16891 0
  18. 184689 16891 0
  19. 20005 16891 0
  20. 519011 16891 0
  21. 580001 16891 0
  22. 20003 16891 0
  23. 40001 16891 0
  24. 161706 16891 0
  25. 210001 16891 0
  26. 184712 16891 0
  27. 161607 16891 0
  28. 184701 16891 0
  29. 184700 16891 0
  30. 257010 16891 0
  31. 202202 16891 0
  32. 217002 16891 0
  33. 270005 16891 0
  34. end
  35. format %tdCCYY-nn-dd ymd
复制代码

10
蓝色 发表于 2018-2-12 16:05:19
  1. replace bull=1 if ymd<date("2007-10-16","YMD") & ymd>date("2005-06-06","YMD")
复制代码

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

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