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

Problem with exporting dates(timeseries) with day, month, year, hour, minute and seconds to stata from excel

$
0
0
I am using stata 13.0 on Windows 7. I'm quite new to stata and there is a lot of information, so I apologize if I'm not specific enough. I am trying to export dates and times for time series analysis to stata(I'm back testing closing prices for various stocks for stationarity). In excel, the date is recorded in the format:

Date
02/29/2016 11:30:00
02/29/2016 11:20:00
02/29/2016 11:10:00

This continues totaling 661 entries.

In stata, I proceed to import my data from excel. I select File-->Import-->Excel Spreadsheet(*.xls, *.xlsx). I check the box that says "Import first row as variable names" and "Import all variables as strings." (At first, I didn't import all variables as strings until I researched and realized the date has to be in string to use the date() function).

on the results page I see
. import excel "C:\Users\Marcques\Documents\Excel Data Thesis trial.xlsx", sheet("Sheet1") firstrow allstring clear

When I open the data editor the date is in the format:
29feb2016 11:29:59
29feb2016 11:19:59
29feb2016 11:10:00

When I look at the variables manager it has the "Type" as str18.
Next, I want to use the date() to convert it to a stata script. So I selected Data-->Create or change data-->Create new variable
The new variable name was Date2. Below in the box "specify a value or an expression" I typed:
date(Date,"DMYhms")

on the results page

. generate Date2 = date(Date,"DMYhms")

on the data editor screen, the dates are all the same for the new variable Date2:
20513
20513
20513

the "Type" is float. When I went to format
. format %tc Date2

It just displays the default date for stata or time 0
01jan1960 00:00:20

Thanks for any input or suggestions.

Viewing all articles
Browse latest Browse all 65601

Trending Articles



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