按日期过滤变量

时间:2019-02-28 22:42:47

标签: string date stata

我在Stata的数据文件中有一个列,其日期如下:

//player.js
import Sprite from "Sprite.js";

export default class Player {
    constructor(img) {
        this.pos = {x: 0, y: 0}
        this.img = new Sprite(true, img); //this is in the classes folder, so we must take the root of it so we can access the public folder and then the image.
    }
}

按日期过滤的语法是什么?

例如,要查找日期为//sprite.js export default class Sprite { constructor(isRoot, path) { let temp = new Image(); if(isRoot === true) { temp.src = `../Public/${path}`; } else { temp.src = `Public/${path}`; } this.sprite = temp; return this.sprite; } } 的所有观测值?

类似1/29/2018 16:28:02

日期为红色,我认为这是字符串。

1 个答案:

答案 0 :(得分:4)

考虑以下玩具示例:

clear

input str20 string_date
"1/14/2018 18:28:02"
"1/19/2018 16:12:13"
"1/26/2018 17:54:43"
"2/11/2018 20:34:25"
"3/29/2018 22:21:01"
end

您首先需要将字符串变量转换为数字:

generate double numeric_date = clock(string_date, "MDY hms")
format numeric_date %tc

list

     +-----------------------------------------+
     |        string_date         numeric_date |
     |-----------------------------------------|
  1. | 1/14/2018 18:28:02   14jan2018 18:28:02 |
  2. | 1/19/2018 16:12:13   19jan2018 16:12:13 |
  3. | 1/26/2018 17:54:43   26jan2018 17:54:43 |
  4. | 2/11/2018 20:34:25   11feb2018 20:34:25 |
  5. | 3/29/2018 22:21:01   29mar2018 22:21:01 |
     +-----------------------------------------+

然后,您必须找到感兴趣的未格式化值:

display %15.0g numeric_date[4]
1834000465000

list if numeric_date == 1834000465000

     +-----------------------------------------+
     |        string_date         numeric_date |
     |-----------------------------------------|
  4. | 2/11/2018 20:34:25   11feb2018 20:34:25 |
     +-----------------------------------------+

或:

keep if numeric_date == 1834000465000

键入help formathelp datetime_display_formats以获得有关使用日期时间的更多详细信息。