Reputation: 165
I have dates in my stata dataset in the form of 1/1/2008 12:00
in %tcnn/dd
format. I want to remove the timestamp from the datetime and only display 1/1/2008
while still retaining its type (double). I tried gen double newdate=date(olddate, "MDY")
, but keep getting the error type mismatch
.
Upvotes: 0
Views: 5457
Reputation: 2694
I understand your question to mean that you want to change the way the variable is displayed, but retain the actual content. In Stata you would call this changing the format. There is a lot you can do in terms of customizing the way dates are displayed. To find what you can do type in Stata help datetime_display_formats
. Below is a basic example of how to hide the time from a date when displaying the data.
. // create some example data
. clear
. input str14 date
date
1. "1/1/2008 12:00"
2. end
. gen double stata_date = clock(date, "DMYhm")
.
. // default display format
. format stata_date %tc
. list
+-------------------------------------+
| date stata_date |
|-------------------------------------|
1. | 1/1/2008 12:00 01jan2008 12:00:00 |
+-------------------------------------+
.
. // don't display the time
. format stata_date %tcDDmonCCYY
. list
+----------------------------+
| date stata_d~e |
|----------------------------|
1. | 1/1/2008 12:00 01jan2008 |
+----------------------------+
Upvotes: 2