Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Strings that give missing values as SIF


From   Paul <[email protected]>
To   <[email protected]>
Subject   st: Strings that give missing values as SIF
Date   Tue, 22 Apr 2014 12:14:54 +1000

I am using Stata ic 13.1 for mac 64 bit Intel

I imported into Stata  a csv file with 4083 patient responses recorded at an import_date. The recorded format of that date in Excel is  DD/MM/YY h:mm, and is shown as a  str13 variable

My attempt to get an SIF date as DD/MM/YY in stata followed the sequence below

1. I first stripped off the h:mm in import_date

gen Time=substr(import_time,1,8)
list Time in 1/10
*     +----------+

*  1. | 31/05/13 |
*  2. | 28/05/13 |
*  3. | 21/03/13 |
*  4. | 30/04/13 |
*  5. | 13/05/13 |
*     |----------|
*  6. | 28/05/13 |
*  7. | 17/04/13 |
*  8. | 30/04/13 |
*  9. | 16/05/13 |
* 10. | 30/04/13 |
*     +----------+
2. This new format seems OK  but Time is shown as a str9 variable with format %9s. I tried

gen ImportTime = date(Time, "DMY")
format ImportTime %td

The  result was 
*(4083 missing values generated)

3. Noting that some days were 1-9, I tried adding an extra 0 in front of the day in import_date using 

*replace import_time = "0" + import_time if length(import_time) == 7

4. To no avail as the 4083 missing values message was repeated when I recalculated ImportTime

I am missing something in my reading of stata dates and times or in importing excel csv to stata.Any ideas?





© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index