Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 65555

Date time variable- keep based on year; month, date, only

$
0
0
I have a "date and time" variable (clock variable is the right terminology?)

Code:
. list  OCCURED_DT in 1/1

     +--------------------+
     |         OCCURED_DT |
     |--------------------|
  1. | 28jun2016 21:20:00 |
     +--------------------+

. des OCCURED_DT

              storage   display    value
variable name   type    format     label      variable label
-----------------------------------------------------------------------------------------------------------------------------------------------------
OCCURED_DT      double  %tc
1. I would like to keep only observations for 2016. Do I have to created a year variable first and then keep 2016 or can I keep 2016 observations using this clock date variable? I tried the code below but it didn't work.
Code:
keep if yofd(OCCURED_DT) == 2016
2. By the same token, can I keep only observations after a specific date (regardless of time) using this variable or I have to create a date variable first? For example, I created a date variable and then:
Code:
keep if OCCURED_DT_DATEONLY >= td(28may2016)
Finally, can I use this variable to keep a specific month- or again- I have to create a month variable first.

Thank you,
Marvin

Viewing all articles
Browse latest Browse all 65555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>